我想提醒用戶如果數據庫的查詢或更新是成功還是失敗..如何在php中查詢成功時提醒用戶?
adduser.php
<?php
include('sqlconnection.php');
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$middlename = $_POST['mname'];
$password = $_POST['pword'];
$username = $_POST['uname'];
$gender = $_POST['gender'];
$utype = $_POST['utype'];
$query = "INSERT INTO user (firstname,lastname,middlename,gender) VALUES ('$firstname','$lastname','$middlename','$gender')";
mysql_query($query);
$result = mysql_query("SELECT id FROM user WHERE firstname = '$firstname'");
$row = mysql_fetch_assoc($result);
mysql_query("INSERT INTO accounts (u_id,username,password,utype) VALUES ('$row["id"]','$username',md5('$password'),$utype);")
?>
我怎麼會提醒用戶?或者我應該怎麼用給用戶彈出消息說它成功了?
只是一個旁註,你的代碼容易受到SQL注入的影響,並且不推薦使用'mysql_ *'函數。您可能希望閱讀[如何防止SQL注入PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)和[爲什麼shouldn'我在PHP中使用mysql_ *函數?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 – 2013-08-22 02:21:10
@ user2062950 thanks..is最好使用mysqli_? – jmjassy27
是的,但PDO也可以。有一個[MySQL PHP驅動程序概述](http://www.php.net/manual/en/mysql.php),它提供了有關它們的詳細信息。 – 2013-08-22 02:28:33