连接PHP源代码并提交表单到MySQL数据库 [英] Connecting PHP source code and submit form to MySQL Database

查看:691
本文介绍了连接PHP源代码并提交表单到MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习PHP,我试图用我的PHP代码连接一个MySQL数据库来创建一个允许我将数据输入到数据库的提交表单。我的问题是,源代码正在连接,但HTML不会将变量发布到PHP文件。

这是我的HTML源代码

 < HTML> 

< head>
< title>表格输入资料< / title>
< / head>

< body>

< table border =1>
< tr>
< td align =center>表单输入员工数据< / td>
< / tr>
< tr>
< td>
< table>
< form action =input.phpmethod =POST>
< tr>
< td>名称< / td>
< td>< input type =textname =namesize =20>
< / td>
< / tr>
< tr>
< td>地址< / td>
< td>< input type =textname =addresssize =40>
< / td>
< / tr>
< tr>
< td>< / td>
< td align =right>< input type =submit
name =submitvalue =Sent>< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>




是我的PHP源代码

 <?php 

$ user_name =fees0_14446440;
$ password =********;
$ database =fees0_14446440_addressbook;
$ server =sql107.0fees.net;

mysql_connect($ server,$ user_name,$ password);

mysql_select_db($ database); b













$ '$ name',

'$ address');


$ result = mysql_query($ order);

if($ result){

echo(< br>输入数据成功);
$ b} else {

echo(< br>输入数据失败);

}
?>


解决方案

您可以在PHP的 $ _POST 变量。它应该包含所有通过POST方法传递的值。

$ name = $ _POST [name];


I'm trying to learn PHP and I'm trying to connect a MySQL database with my PHP code to make a submit form that lets me input data into the database. My problem is that the source code is connecting but the HTML isn't posting the variables to the PHP file. I could really use some help.

This is my HTML source code

<html>

<head>
<title>Form Input Data</title>
</head>

<body>

<table border="1">
  <tr>
    <td align="center">Form Input Employees Data</td>
  </tr>
  <tr>
  <td>
  <table>
    <form action="input.php" method="POST">
    <tr>
      <td>Name</td>
      <td><input type="text" name="name" size="20">
      </td>
    </tr>
    <tr>
      <td>Address</td>
      <td><input type="text" name="address" size="40">
      </td>
    </tr>
    <tr>
      <td></td>
      <td align="right"><input type="submit" 
      name="submit" value="Sent"></td>
    </tr>
    </table>
  </td>
</tr>
</table>

And this is my PHP source code

<?php

$user_name = "fees0_14446440";
$password = "********";
$database = "fees0_14446440_addressbook";
$server = "sql107.0fees.net";

mysql_connect("$server","$user_name","$password");

mysql_select_db("$database");


$order = "INSERT INTO Trial

        (name, address)

        VALUES

        ('$name',

        '$address')";


$result = mysql_query($order);

if($result){

    echo("<br>Input data is succeed");

} else{

    echo("<br>Input data is fail");

}
?>

解决方案

You can find the POST data in PHP's $_POST variable. It should hold all the values that were passed via the POST method.

$name = $_POST["name"];

这篇关于连接PHP源代码并提交表单到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆