Php 更新mysql无法正常工作
您好,我创建了一个维护个人电脑的网站,如果有人访问我的网站并尝试回答他,答案将转到所有访问者,而不仅仅是指定的人,请帮助,下面的代码将帮助我,请参阅下面的代码:Php 更新mysql无法正常工作,php,Php,您好,我创建了一个维护个人电脑的网站,如果有人访问我的网站并尝试回答他,答案将转到所有访问者,而不仅仅是指定的人,请帮助,下面的代码将帮助我,请参阅下面的代码: <html> <head> <meta charset='utf-8'> </head> <body > </body> </html> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass
<html>
<head>
<meta charset='utf-8'>
</head>
<body >
</body>
</html>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$con=mysql_connect("localhost","root","root");
// Check connection
if (!$con)
{
die("can not connect" . mysql_error());
}
mysql_select_db('newone') or die("can not find db");
if(isset($_GET['edit']))
{
$user_id=$_GET['edit'];
echo "$user_id";
$res=mysql_query("SELECT * FROM newone WHERE user_id='$user_id' ");
}
if(isset($_POST['save']))
{
$sql=mysql_query("UPDATE newone set user_notes ='$user_notes' , user_answer='$user_answer' where user_id='$user_id' ");
$res=mysql_query($sql) or die("count update".mysql_error());
echo "<meta http-equiv=\"REFRESH\"content=\"0;url=justtry2.php\">";
}
echo "<table border='2' heigh='1740' width='1340' bgcolor='C8B478'>
<tr>
<th>الملاحظات</th>
<th>الجواب</th>
<th>المشكله</th>
<th>نوع اخر للعطل</th>
<th>نوع العطل</th>
<th>البريد الاكتروني</th>
<th>موقع اخر</th>
<th>الموقع</th>
<th>الاسم</th>
<th>التاريخ والوقت</th>
<th>الرقم</th>
</tr>";
while($row=mysql_fetch_array($res))
{
echo "<form method='post' action='justtry2.php'>";
echo "<tr>";
echo "<td> <input type=text name='user_notes' ></td>";
echo "<td><input type=text name='user_answer' > </td>";
echo "<td>" . $row['user_problem'] . "</td>";
echo "<td>" . $row['user_ectt'] . "</td>";
echo "<td>" . $row['user_type'] . "</td>";
echo "<td>" . $row['user_email'] . "</td>";
echo "<td>" . $row['user_ect'] . "</td>";
echo "<td>" . $row['user_location'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $row['join_date'] . "</td>";
echo "<td>" . $row['user_id'] . "</td>";
echo "<td><input type='submit' name='save' value='save'></td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
?>
您的PHP代码已从根本上被破坏:
$sql=mysql_query("UPDATE newone set user_notes ='$user_notes' , user_answer='$user_answer' where user_id='$user_id' ");
$res=mysql_query($sql)
由于您在第一行调用mysql_query(),$sql
是一个查询结果,而不是实际的查询字符串。不能使用查询结果句柄执行其他查询
也许你应该这么做
$sql = "UPDATE blah blah blah";
$result = mysql_query($sql) or die(mysql_error());
相反
您还可以访问您还需要将php变量与Post请求链接起来。
例如:
请发布您可能遇到的任何错误。这一行没有中断:$sql=mysql\u query(“更新newone set user\u notes='$user\u notes',user\u answer='$user\u answer'其中user\u id='$user\u id')代码>否,但由于OP在下一行中执行了$result=mysql\u query($sql)
,因此它可能会被破坏。您能帮我一下吗,代码没有按照我的要求工作
$user_answer=$_POST["user_answer"];