Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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 - Fatal编程技术网

php中的插入问题

php中的插入问题,php,Php,你能告诉我我的代码怎么了吗? 它显示了错误 分析错误:语法错误,第12行的C:\xampp\htdocs\xampp\dhiraj\queryverify.php中出现意外的T_字符串 这是我的密码 <head> <style> #margin_left{margin-left:400px; height:400px;} #spanning{margin-left:70px;} #spanning_gender{margin-left:66px;} #spanning_m

你能告诉我我的代码怎么了吗? 它显示了错误

分析错误:语法错误,第12行的C:\xampp\htdocs\xampp\dhiraj\queryverify.php中出现意外的T_字符串

这是我的密码

<head>
<style>
#margin_left{margin-left:400px;
height:400px;}
#spanning{margin-left:70px;}
#spanning_gender{margin-left:66px;}
#spanning_marstatus{margin-left:27px;}
#spanning_city{margin-left:82px;}
#spanning_country{margin-left:62px;}
#spanning_religion{margin-left:63px;}
#spanning_crime{margin-left:74px;}
#spanning_crimetype{margin-left:39px;}
#table{border:thick;border-color:#09F;}
#insert{margin-left:140px;}
#foot{
background:none;}
</style>
</head>
<body>
<?php 
include('database.php');
include('commonheader.php');
?>
<form method="get" name="queries" action="queryverify.php">
<h3 align="center"><font face="Tahoma, Geneva, sans-serif" color="#6C6">Queries</font></h3>
<div id="margin_left"><table id="table" border="1"cellpadding="10">
<tr>
<td>
Name: <span id="spanning"><input type="text" name="name" size="30"></span><br/>
Gender:<span id="spanning_gender"><select id="gender" size="1"><option value="r">male</option><option value="m">female</option></select></span><br/>
Marital Status:<span id="spanning_marstatus"><select size="1" id="marstatus"><option value="f">Married</option><option value="g">Unmarried</option><option value="h">Unknown</option></select></span><br/>
City: <span id="spanning_city"><input type="text" name="city" size="30"></span><br/>
Country:<span id="spanning_country"><input type="text" name="country" size="30"></span><br/>
Religion:<span id="spanning_religion"><input type="text" name="religion" size="30"></span><br/>
Crime:<span id="spanning_crime"><select id="crime" size="1"><option value="a">Murder</option></select></span><br/>
Crime Type:<span id="spanning_crimetype"><select id="crimetype" size="1"><option value="b">Half Murder</option></select></span>
</td>
</tr>
</table>
<div id="insert"><input type="submit" name="Insert" value="Insert"></div>
</div>
</form>
<?php include('footer.php');?>
<br />
<br/>
</body>

#左边距{左边距:400px;
高度:400px;}
#跨越{左边距:70px;}
#跨越{左边距:66px;}
#跨越{左边距:27px;}
#跨越城市{左边距:82px;}
#跨越{左边距:62px;}
#跨越宗教{左边距:63px;}
#跨越犯罪{左边距:74px;}
#跨越_crimetype{margin left:39px;}
#表{边框:粗;边框颜色:#09F;}
#插入{左边距:140px;}
#脚{
背景:无;}
询问
名称:
性别:男性女性
婚姻状况:已婚或不知名
城市:
国家:
宗教:
犯罪:谋杀
犯罪类型:半谋杀

queryverify.php

<?php
   $name = $_GET['name'];
   $gender=$_GET['gender'];
   $marstatus=$_GET['marstatus'];
   $city=$_GET['city'];
   $country=$_GET['country'];
   $religion=$_GET['religion'];
   $crime=$_GET['crime'];
   $crimetype=$_GET['crimetype'];
   include('database.php');
    $query="insert into criminal(cid,name,gender,marital_status,religion,city,country,crime,crime_types) values(NULL,'".$name."','".$gender."','".marstatus."','".$religion."','".$city."','".$country."','".$crime."','".$crimetype."')";
 mysql_query($query)or die mysql_error();
  ?>

缺少$。如果您有PHP错误(每个开发人员都有最常见的错误),也许将来您应该检查以下内容:

  • 您键入的查询是否正确
  • 所有变量都有美元符号吗
  • 你有没有加上,;在队伍的尽头
  • 你正确地使用了“和”吗
另外,我看到您得到了不同的值,但没有对它们进行过滤,我建议您在将查询发送到数据库之前使用mysql\u real\u escape\u string()

$name = mysql_real_escape_string($_GET['name']);

(仅提出几点建议)

另一方面,此设置极易受到SQL注入攻击的攻击。(请参阅)您需要清理数据,或使用PDO()中的语句等准备好的语句。是否已修复?如果已修复,请标记正确答案!