开发者

How to add data to mysql by url

newbie at php here, basically I wish to know how to add data to my mysql table manually using the url.

For example, say I have a table called users which has 3 fields called 'ID', 'username' and 'password'. I wish to add data to the table like this:

http://localhost/register.php?id=1@usernam开发者_开发知识库e=bob@password=123@act=register (I'm not sure if this is entirely right) but yeah something like that.

Any help on how to do this would be much appreciated!


mysql_connect('localhost', 'mysql_user', 'mysql_password');

mysql_select_db('database');

mysql_query("INSERT INTO table (id, username, password) VALUES ('".mysql_real_escape_string($_GET['id'])."', '".mysql_real_escape_string($_GET['username'])."', '".mysql_real_escape_string($_GET['password'])."')");


$query = "insert into users (username, password) values ('".$_GET['username']."','".$_GET['password']."'";

That would be to insert a user based on the act parameter.

Also, usually parameters on a get are split up by "&", not "@".


First of all, if you're saving large data, better to use POST, rather than GET. But if you really need to send data to the server with URL, your URL should be change as below:

You should use '&' in place of '@'

http://localhost/register.php?id=1&username=bob&password=123&act=register

In Server side, you can retrieve the data by following:

$id = mysql_real_escape_string($_GET['id']);

$username = mysql_real_escape_string($_GET['username']); $password = mysql_real_escape_string($_GET['password']);

$sql = mysql_query('INSERT INTO table_name (id, username, password) VALUES ('.$id.', '.$username.', '.$password.'); if(!$sql){ echo "Error " . mysql_error(); }else{ echo "Success"; }


use

$id  = $_REQUEST['id'];
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$act   = $_REQUEST['act'];

to get values from url

Then usual MySQL

Insert Query

refer

http://dev.mysql.com/doc/refman/5.5/en/insert.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜