我制作了一个 html 表单,用于更新 mySQL DB 中我的表中的某些字段,成功更新后应该将我引导到成功页面,否则会给出错误消息。指示错误
我使用表单验证,但到目前为止,我的表格中的字段没有任何反应,它只会将我引导到一个空白页面
这是表单代码:
<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");
?>
任何想法 ?