我做了一个html表单,更新mySQL DB中的表中的一些字段成功更新后,应该指示我成功的页面,否则给错误消息。指示错误mysql表更新没有结果
我使用形式验证,但到目前为止,什么也没有发生在我的表中的字段只指示我到一个空白页
这里是表单代码:
<html>
<body>
<form action="http://localhost/wordpress/orgupdate.php" method="post" name="myForm">
Name <input id="name" type="text" name="name" />
Telephone <input id="telephone" type="text" name="telephone" />
Fax <input id="fax" type="text" name="fax" />
Web address <input id="webaddress" type="text" name="webaddress" />
State <input id="state" type="text" name="state" />
Address <input id="address" type="text" name="address" />
<input type="submit" name= "submit" value="update" />
</form>
</body>
</html>
<script type="text/javascript">// <![CDATA[
/* JS validation code here */
function validateForm()
{
/* Validating name field */
var x=document.forms["myForm"]["name"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
/* Validating email field */
var x=document.forms["myForm"]["telephone"].value;
if (x==null || x=="")
{
alert("telephone must be filled out");
return false;
}
}
// ]]>
</script>
,这是我的php文件:
<?php
//establish connection
$con = mysqli_connect("localhost","xx","xxxx","android_app");
//on connection failure, throw an error
if(!$con) {
die('Could not connect: '.mysql_error());
}
//get the form elements and store them in variables
$name=$_POST['name'];
$telephone=$_POST['telephone'];
$fax=$_POST['fax'];
$webaddress=$_POST['webaddress'];
$state=$_POST['state'];
$address=$_POST['address'];
$query= update islamic_organisation SET (Telephone ='$telephone', Fax ='$fax', WebAddress ='$webaddress', state ='$state', Address ='$address' WHERE Name ='$name');
//Redirects to the specified page
header("Location: http://localhost/wordpress/?page_id=857");
?>
有什么想法吗?
你的更新查询是错误的,而函数名是可疑的 – samayo 2013-05-04 08:27:11
首先,你如何不在'$ query = update ...'上得到解析错误,它需要正确引用。其次,你永远不会执行你的查询,只将它分配给一个变量。 – Jon 2013-05-04 08:27:13
我恳求你,在将此代码推向生产之前,请阅读有关SQL注入的内容。 :) – spacediver 2013-05-04 09:39:33