无法保存到数据库中

时间:2014-02-20 07:09:05

标签: php html css database post

为什么当我提交表单时,数据不会保存在数据库中。

以下代码是我insert.php

中的代码

config.php是数据库中的连接

<?php     
include 'Config.php';
$position = $_POST['position'];
$tel = $_POST['tel'];
$menu1 = $_POST['menu1'];
$name = $_POST['name'];
$Add2 = $_POST['Add2'];
$birth = $_POST['birth'];
$civil = $_POST['civil'];
$sex = $_POST['sex'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$emailadd = $_POST['emailadd'];
$religion = $_POST['religion'];
$spouse = $_POST['spouse'];
$soccupation = $_POST['soccupation'];
$father = $_POST['father'];
$foccupation = $_POST['foccupation'];
$mother = $_POST['mother'];
$moccupation = $_POST['moccupation'];
$address = $_POST['address'];
$elem = $_POST['elem'];
$date = $_POST['date'];
$high = $_POST['high'];
$hdate = $_POST['hdate'];
$college = $_POST['college'];
$course = $_POST['course'];
$skills = $_POST['skills'];
$frm = $_POST['frm'];
$to2 = $_POST['to2'];
$eposition = $_POST['eposition'];
$company = $_POST['company'];

$result = mysql_num_rows(mysql_query("SELECT * FROM tblonline WHERE name = '$name'"));

if($result == 1) {
    echo "The Name already exists!";
}
else {

mysql_query("INSERT INTO 'tblonline' VALUES('$position','$tel','$menu1','$name','$Add2','$birth','$civil','$sex','$height','$weight','$emailadd','$religion','$spouse','$soccupation','$father','$foccupation','$mother','$moccupation','$address','$elem','$date','$high','$hdate','$college','$course','$skills','$frm','$to2','$eposition','$company')");
    echo "<p>Thank You! </p> 
    <p>Click <a href = \"online.php\">here</a> to login.</p>";

}
?>

3 个答案:

答案 0 :(得分:2)

从插入查询中删除表名的单引号或尝试此

mysql_query("INSERT INTO tblonline VALUES('$position','$tel','$menu1','$name','$Add2','$birth','$civil','$sex','$height','$weight','$emailadd','$religion','$spouse','$soccupation','$father','$foccupation','$mother','$moccupation','$address','$elem','$date','$high','$hdate','$college','$course','$skills','$frm','$to2','$eposition','$company')");

答案 1 :(得分:0)

INSERT INTO 'tblonline'

尝试更改为

INSERT INTO `tblonline`

因为mysql可能正在研究它并认为它是一个字符串。后退标记用于数据库和表名。 (没有`周围的空格 - 只是试图绕过SO的格式化。)如果不这样做,只需从表名中删除''并指定为tblonline - 只是为了确保您可以保存数据。

另外,所有mysql_ *函数都已被弃用。您可能希望查看使用mysqli_ *函数,以便将来证明。

答案 2 :(得分:0)

尝试将插入查询的代码更改为: 将'$ position'设为''。$ position。'' 对要插入DB的每个变量进行此编辑。 您还可以在所有$变量前面写一个echo,看看是否正确显示了值。 如果是,则查询中出现问题,否则问题出在HTML提取

另请告诉我,你有什么错误。?

相关问题