2011-08-04 40 views

回答

1

如果通過to make entries表示將數據添加到數據庫。

您以與您select數據相同的方式執行此操作。
而是發出select聲明一樣的:

SELECT x,y,z FROM table1 

你這樣做:

INSERT INTO table1 (x,y,z) VALUES ('a', 1, 'test') 

或者:

UPDATE table1 SET x = 'b' WHERE x = 'a' 

如何傳遞參數取決於您使用的API。
使用PDO傳遞參數是最好的(最安全的)。

如何獲得的參數進行URL的
爲了得到這些參數從URL(例如:example.com/test.php?username=xyz &密碼= @#$%)做:

$username = mysql_real_escape_string($_GET['username']); 
$password = mysql_real_escape_string($_GET['password']); 
$query = "SELECT * FROM users WHERE username = '$username' 
      AND passhash = sha2(CONCAT(salt,'$password'),512)"; 

請注意,這是至關重要的周圍放上注入的變量名的單引號使用mysql_real_escape_string()或逃逸將是無用的時候。像這樣使用的代碼是從SQL注入100%安全。

如果您正在使用PDO,則可以刪除mysql_real_escape_string(),如果不需要它,可以防止SQL注入。

鏈接
http://dev.mysql.com/doc/refman/5.5/en/update.html
http://dev.mysql.com/doc/refman/5.5/en/insert.html
http://php.net/manual/en/ref.pdo-mysql.php
https://stackoverflow.com/search?q=%5Bphp%5D+%5Bmysql%5D+pdo
http://php.net/manual/en/reserved.variables.get.php
http://php.net/manual/en/function.mysql-real-escape-string.php

+0

感謝您的答覆這個我知道了如何使用INSERT n更新插入表中的數據,但我想做的事通過點擊一個URL example.com/test.php?username=xyz&[email protected]#$% – IphoneBites

+0

我知道這可能是要問的基本問題,但我不知道要製作Web服務。所以在點擊該URL後,用戶名和密碼應該在數據庫中更新。 – IphoneBites

+0

thnx鏈接工作:) thnx很多人 – IphoneBites

相關問題