php插入数据库失败


php inserting to database fail

我有以下消息框错误,显示失败。这些是我的代码:

<?php   
require('admin/connectdb.php');
    if (isset($_POST['Sub'])) 
    {   
        //get data from reservation form 
        $cutomername=$_POST['aname'];
        $gender=$_POST['sex'];
        $phoneno=$_POST['tel'];
        $email=$_POST['email'];
        $age=$_POST['age'];
        $computerpart=$_POST['partcomp'];
        $option1=$_POST['option1'];
        $notes=$_POST['Notes'];
        $query="INSERT INTO `assignmentwebprog`.`reservation` (`cumstomername`, `gender`, `phoneno`, `email`, `age`, `typeofcomputerpart`, `option`, `notes`) 
                    VALUES ('$cutomername', '$gender', '$phoneno', '$email', '$age', '$computerpart', '$option1', '$notes')";
        $qresult = mysql_query($query);
        if ($qresult){
            echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
        }
        else
        {
            echo "<script type='text/javascript'>alert('failed!')</script>";
        }
    }
?>

上面是向phpmyadmin&每次我加载/输入,然后单击输入,页面就会显示消息框"失败"

这些是我的数据库:

<?php
$host="localhost"; // Host name
$username="root"; // username
$username="root"; // username
$db_name="assignmentwebprog"; //database name
$tbl_name="reservation";
// Replace database connect functions depending on database you are using.
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");
?>

目前我的数据库是phpmyadmin,我的代码是否缺少什么?

检查数据库cumstomername中的字段拼写是否正确。可能是customername

通过参数

$cutomername=$_POST['aname'];

SQL

$query="INSERT INTO `assignmentwebprog`.`reservation` (`cumstomername`, `gender`, `phoneno`, `email`, `age`, `typeofcomputerpart`, `option`, `notes`) 
                    VALUES ('$cutomername', '$gender', '$phoneno', '$email', '$age', '$computerpart', '$option1', '$notes')";

更改此行并尝试:

$qresult = mysql_query($query) or die(mysql_error());

检查此项:

$query="INSERT INTO reservation (cumstomername, gender, phoneno, email, age, typeofcomputerpart, option, notes) 
                    VALUES ('$cutomername', '$gender', '$phoneno', '$email', '$age', '$computerpart', '$option1', '$notes')";
        $qresult = mysql_query($query) or die(mysql_error());

您可能在$查询中缺少一些内容,这对于表插入是必需的。

首先在页面上回显查询。//echo$query;

然后在phpmyadmin中运行查询,您将得到它没有插入表中的原因。请参阅此处的错误。