更新到sql失败
updating to sql failed
我收到一个错误,说失败,每当我检查这个代码时,我都觉得我的代码没有问题。请帮帮我,因为我只是个初学者。有表单、javascript和php。
<?php
$species=""; //declare variable to assign table record data
$age= "";
$sex="";
$location="";
$comment="";
require('connectdb.php');
$record=$_REQUEST['id' ];
$query="SELECT * FROM usersform WHERE id = $record "; // listing reservation record
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$species= $row['species']; //retrieve table record and assign to variable
$age= $row['age'];
$location= $row['location'];
$comment= $row['comment'];
if (isset($_POST['submit']))
{
//get data from reservation form
$spec=$_POST['species'];
$eage=$_POST['age'];
$gender=$_POST['gender'];
$elocation=$_POST['location'];
$ecomment=$_POST['comment'];
//update data to table
$query=" UPDATE `usersform` SET
`species` ='$spec',
`age`='$eage',
`location`='$elocation',
`comment`='$ecomment',
WHERE usersform= $record
";
$qresult = mysql_query($query);
if ($qresult){
/*echo '<script type="text/javascript">
window.location = "http://www.example.com/";
</script>';*/
echo '<script type="text/javascript"> window.location="gallery.php";</script>';
#header("location:gallery.php"); // redirect to list
}
else
{
echo "<script type='text/javascript'>alert('failed!')</script>";
}
}
?>
这是我的表单代码:
<h2>Edit/Update Reservation Record </h2>
<form name="Form" method="Post" onsubmit="return(validateForm());" onreset="cancel();">
<table cellspacing="2" cellpadding="2">
<tr>
<td>species: </td>
<td><input type="text" name="species" size="35" value="<?php echo $species; ?>"/></td>
</tr>
<tr>
<td>age:</td>
<td><input type="text" name="age" maxlength="15" size="15" value="<?php echo $age; ?>"/></td>
</tr>
<tr>
<td>sex:</td>
<td><input type="radio" name="gender" value="male" value="<?php echo $sex; ?>"/>Male <input type="radio" name="gender" value="female" value="<?php echo $sex; ?>"/>Female</td>
</tr>
<tr>
<td>location:</td>
<td><input type="text" name="location" size="35" value="<?php echo $location; ?>"/></td>
</tr>
<tr>
<td>comment:</td>
<td><input type="text" name="comment" size="50" value="<?php echo $comment; ?>"/></td>
</tr>
<tr>
<td><input type="submit" value="Update" name="submit" /></td>
<td><input type="reset" value="Cancel" name="reset" /></td>
</tr>
</table>
</form>
这是我的javascript:
function validateForm() {
if( document.Form.species.value == "" )
{
alert( "Please insert species." );
document.Form.Name.focus() ;
return false;
}
if( document.Form.age.value == "" ||isNaN( document.Form.age.value ) )
{
alert( "Please insert age." );
document.Form.age.focus() ;
return false;
}
if( document.Form.location.value == "" )
{
alert( "Please insert location." );
document.Form.Name.focus() ;
return false;
}
if( document.Form.comment.value == "" )
{
alert( "Please insert comment." );
document.Form.Name.focus() ;
return false;
}
}
function cancel()
{
window.location.href="gallery.php";
}
更新语法不正确。。这是正确的sql语法
$query=" UPDATE `usersform` SET
`species` ='$spec',
`age`='$eage',
`location`='$elocation',
`comment`='$ecomment'
WHERE usersform= $record
";
将update
查询更改为此
$query=" UPDATE `usersform` SET
`species` ='$spec',
`age`='$eage',
`location`='$elocation',
`comment`='$ecomment'
WHERE id= $record
";
$qresult = mysql_query($query) or die(mysql_error());
注意:学习mysqli_
或p.D.O,因为mysql
是去极化
相关文章:
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 当json解析空响应时,Whatwg-Fetch失败,我该如何防止它
- JsFiddle在分叉后描述失败
- 捕获初始RedQueryBuilder查询中的SQL问题
- 从Chrome扩展访问Google Cloud SQL数据库
- 在php和mysql中选择选项.一旦选择了选项,就列出我的sql数据库数据
- 为什么不'当单元测试出现解析错误时,我的因果报应测试会失败
- 当一些承诺失败时,如何继续使用$q.all()
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 在Jquery中单击传播失败
- 当通过ajax发送到php/sql时,无法存储HTML
- MongoDB + SQL Select equivalent
- 网页上失败的javascript会导致所有其他脚本失败
- 带有对象解析的响应javascript ajax失败
- 通过PHP和JQuery在SQL中保存表单数据始终失败
- 当返回的查询不为空时,来自 php 的 MS SQL Server 过程失败并显示 500
- 更新到sql失败
- 使用sequelize连接SQL server失败
- PHP循环中的SQL查询在第n次迭代后失败
- 在sql中插入语句失败