Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将html表单连接到sql数据库_Php - Fatal编程技术网

Php 如何将html表单连接到sql数据库

Php 如何将html表单连接到sql数据库,php,Php,我想把一个表单连接到数据库,但是php给出了一些建议来帮助我编写脚本 <?php $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("hot_data", $connection); if(isset($_POST['submit'])) {

我想把一个表单连接到数据库,但是php给出了一些建议来帮助我编写脚本

                 <?php
              $connection = mysql_connect("localhost", "root", "");
               $db = mysql_select_db("hot_data", $connection);


            if(isset($_POST['submit']))
            {


                   $userid=_$POST['userid'];
                    $first_name=$_POST['fname'];
               $last_name=$_POST['lname'];
               $livingadress=$_POST['ldress'];
                 $telephone=$_POST['phone'];

                  if($userid !=''||$telephone !=''){

//Insert Query of SQL
                    $query = mysql_query("INSERT INTO personal_data(userid,first_name,last_name,living_address,telephone)


                   VALUES('$userid','$first_name','$last_name','$livingaddress','$telephone')");

              echo "<br/><br/><span>Data Inserted successfully...!!</span>";
              }
            else{
                 echo "<p>Insertion Failed <br/> Some Fields are Blank....!! </p>";
                        }
                     }
                           mysql_close($connection);
                  ?>

您在这行有一个错误-

$userid=_$POST['userid'];
如果是这样的话—

$userid=$_POST['userid']; // $_POST variable was improperly written

问题到底是什么?问题是这个解析错误:语法错误,在第10行的C:\wamp\www\morework.php中出现意外的T_变量,但随后重写了它并将其保存在那里……它有这个$userid=$POST['userid']$first_name=$_POST['fname'];请澄清错误是什么,是哪段代码引发了错误。天哪,莫莉小姐!我不是!鹰眼,是的。不是坏人。好像有人不喜欢你的答案。Meh,让他们吃蛋糕,但留给我们结冰。你应该考虑增加解释。
<?php
try{
    $servername = "localhost";
    $username = "username";
    $password = "password";
    // Create connection
    $conn = new mysqli($servername, $username, $password);
    // Check connection
    if ($conn->connect_error) {
        throw new Exception("Connection failed: " . $conn->connect_error);
    }
    if (mysql_select_db("hot_data")){
    if(isset($_POST['submit']))
                {
                     $userid=$_POST['userid'];
                        $first_name=$_POST['fname'];
                   $last_name=$_POST['lname'];
                   $livingadress=$_POST['ldress'];
                     $telephone=$_POST['phone'];

                      if($userid !=''||$telephone !=''){

    //Insert Query of SQL
                        $query = mysql_query("INSERT INTO personal_data(userid,first_name,last_name,living_address,telephone)
     VALUES('{$userid}','{$first_name}','{$last_name}','{$livingaddress}','{$telephone}')");
                    throw new Exception("Data Inserted successfully...!!");
                  }
                else{
                    throw new Exception("Insertion Failed...!!Some Fields are Blank....!!");
                            }
                         }
    }else {throw new Exception("Could not find database....!! ");}
}catch(exception $ex)
{   echo $ex;
    }
?>