我想覆蓋MySQL中的當前數據以便能夠更新所有內容。 我是新來這個我沒有看到下面的代碼的任何錯誤:用PHP更新MySQL查詢
PHP代碼:
<?php
// see if the form has been completed
if (isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
if($firstname && $surname){
// connect to the server
include_once("php_includes/db_conx.php");
// check if that user exist
$exists = mysql_query ("SELECT * FROM users WHERE firstname='$firstname'") or die ("the query could not be connected");
if (mysql_num_rows ($exists) != 0) {
// update the description in the database
mysql_query("UPDATE firstname SET surname='$surname' WHERE firstname='$firstname'") or die ("update could not be applied");
echo "successful";
} else echo "the name does not edist";
} else echo "you need to enter both of the fields try again:";
}
?>
我得到的錯誤是
查詢無法連接
但我試過查詢,它很好。
HTML:
<html>
<head>
<title>update MySql form</title>
</head>
<body>
<div id="pageMiddle">
<form action="user1.php" method="POST">
<div>
<p>First Name: <input type="text" name="firstname" id="firstname" ></p>
<p>Surname: <input type="text" name="surname" id="surname"></p>
<p><input type="submit" name="submit" id="submit" value="Update Description"></p>
</div>
</form>
</body>
</html>
你應該真的讀這個http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 – Fabio
更新查詢錯誤我討厭人們只是看看對我說我是新手 – user3311898
而不是'死(「查詢無法連接」)'嘗試'死(mysql_error())' –