Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/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 无法保存到数据库中_Php_Html_Css_Database_Post - Fatal编程技术网

Php 无法保存到数据库中

Php 无法保存到数据库中,php,html,css,database,post,Php,Html,Css,Database,Post,为什么当我提交表格时,数据没有保存在数据库中 下面的代码是我的insert.php php是数据库中的一个连接 <?php include 'Config.php'; $position = $_POST['position']; $tel = $_POST['tel']; $menu1 = $_POST['menu1']; $name = $_POST['name']; $Add2 = $_POST['Add2']; $birth = $_POST['birth']; $civ

为什么当我提交表格时,数据没有保存在数据库中

下面的代码是我的
insert.php

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>";

}
?>

从insert查询中删除表名的单引号,或尝试以下操作

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')");
试着换成

INSERT INTO `tblonline`
因为mysql可能正在考虑这个问题,并认为它是一个字符串。反勾号用于数据库和表名。(在“-只是试图绕过SO的格式设置”周围没有空格。)如果失败,只需从表名中删除“”,并指定为Just
tblonline
,以确保可以保存数据


另一方面,所有mysql_*函数都已被弃用。您可能想看看如何使用mysqli_*函数,以防万一。

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


另外,请告诉我您遇到了什么错误。?

检查是否有任何由
mysql\u error()
显示您的表结构INSERT-INTO'tblonline'->尝试更改为INSERT-INTO'tblonline'-因为mysql可能正在查看并认为这是一个字符串。反勾号用于数据库和表名。(在“-”周围没有空格,只是想绕过SO的格式设置。)如果失败,只需从表名中删除“”,并指定为Just tblonline。您不应该使用
mysql\u query
,因为它已经贬值了。在这里阅读有关使用准备好的语句的内容
INSERT INTO `tblonline`