0

我有以下消息框错误,说Failed。这些是我的代码:

<?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,我的代码是否缺少某些内容?

4

4 回答 4

0

您可能在 $query 中遗漏了表插入所必需的某些内容。

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

然后在 phpmyadmin 中运行查询,您将得到它没有插入表中的原因。看到那里的错误。

于 2013-12-12T13:15:42.327 回答
0

更改此行并尝试:

$qresult = mysql_query($query) or die(mysql_error());
于 2013-08-02T12:57:42.120 回答
0

检查这个:

$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());
于 2013-08-02T12:59:29.600 回答
0

检查数据库中的字段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')";
于 2013-08-02T13:00:14.547 回答