2011-08-04 61 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

相关问题