使用 PHP 更新 SQL
屏幕消息是:
object(mysqli)[1]
public 'affected_rows' => null
public 'client_info' => null
public 'client_version' => null
public 'connect_errno' => null
public 'connect_error' => null
public 'errno' => null
public 'error' => null
public 'field_count' => null
public 'host_info' => null
public 'info' => null
public 'insert_id' => null
public 'server_info' => null
public 'server_version' => null
public 'stat' => null
public 'sqlstate' => null
public 'protocol_version' => null
public 'thread_id' => null
public 'warning_count' => null
No rows updated
我的代码是:
$connection = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_error()) {
die(`Connect Error: ` . mysqli_connect_error());
} else {
echo `Successful connection to MySQL <br />`;
$employ = $_POST['employer'];
$address = $_POST['flat'];
$login_name = $_POST['login_name'] ;
var_dump($connection);
// Insert employer and address into database row for logged in user.
$query = "UPDATE members SET employer = `$employ`, flat = `$address` WHERE login=`$login_name`";
if (!$result = $connection->query($query)) {
echo "No rows updated <br />";
} else {
echo $result . " row(s) successfully updated<br />";
}
}
?>
我从中获取信息的表格是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<table width="100%" border="0" >
<tr>
<td colspan="2" style="background-color:#FFA500;">
</td>
</tr>
<td style="height:500px;width:400px; ">
<center>
<h2>Update</h2><br>
<form action="update.php" method="post">
<input type="hidden" name="login_name" value="$_SESSION['SESS_LOGIN']">
<p>employer <input type="text" name="employer"> </p>
<p>flat number <input type="text" name="flat"></p>
<p><input type="submit" value="Login" ></p>
</form>
</center>
</td>
</tr>
</table>
我一直试图让这个工作好几天。用户登录他们的个人资料,然后从 SQL 数据库中获取他们的所有信息,然后显示在屏幕上。上面的表格是使用特定信息更新他们的个人资料,以在他们下次登录时更新他们在数据库中的行。