Find the php implementation code and click the url to record a specified parameter. I am not familiar with php and need a function:
How can a string of a url be recorded in the database by clicking a url? Used to cancel a subscription
Example: http://mydomain.com/abc.php? Username = myname
Click this url. The php program records the myname and inserts it into the unsubscribe table of mysql database mydatabase,
The mysql User name is root and the password is 123456
Php implementation code
Reply to discussion (solution)
$ Username = $ _ GET ['username'];
After obtaining the value, you will know how to do it.
$ Username = $ _ GET ['username'];
After obtaining the value, you will know how to do it.
I don't know. it's totally php,
Paste your table structure.
Paste your table structure.
Table unsubscribe has only one field username, string type
CREATE TABLE `unsubscribe` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(100) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Assume that the unsubscribe data table is of the above structure.
Abc. php can be written in this way.
// Connect to the database $ conn = @ mysql_connect ("localhost", "root", "123456") or die (mysql_error (); // localhost is the host that adds your database, if it is not local, modify @ mysql_select_db ('mydatabase', $ conn) or die (mysql_error (); $ username = isset ($ _ GET ['username'])? Mysql_escape_string ($ _ GET ['username']): ''; if ($ username) {$ sqlstr =" insert into unsubscribe (username) values ('". $ username. "')"; mysql_query ($ sqlstr) or die (mysql_error (); echo 'Insert success ';}
Visit: http://mydomain.com/abc.php? Username = myname
$ Username = $ _ GET ['username']; $ con = mysqli_connect ('localhost', 'root', '123', 'mydatabase '); $ SQL = "insert into unsubscribe (username) values ('$ username')"; if (mysqli_query ($ con, $ SQL) {echo 'information inserted successfully ';} else {echo 'insertion information failed ';}
CREATE TABLE `unsubscribe` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(100) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Assume that the unsubscribe data table is of the above structure.
Abc. php can be written in this way.
// Connect to the database $ conn = @ mysql_connect ("localhost", "root", "123456") or die (mysql_error (); // localhost is the host that adds your database, if it is not local, modify @ mysql_select_db ('mydatabase', $ conn) or die (mysql_error (); $ username = isset ($ _ GET ['username'])? Mysql_escape_string ($ _ GET ['username']): ''; if ($ username) {$ sqlstr =" insert into unsubscribe (username) values ('". $ username. "')"; mysql_query ($ sqlstr) or die (mysql_error (); echo 'Insert success ';}
Visit: http://mydomain.com/abc.php? Username = myname
Thanks. you can run it. do you need to close the database connection? Or will php automatically close the connection?
$ Username = $ _ GET ['username']; $ con = mysqli_connect ('localhost', 'root', '123', 'mydatabase '); $ SQL = "insert into unsubscribe (username) values ('$ username')"; if (mysqli_query ($ con, $ SQL) {echo 'information inserted successfully ';} else {echo 'insertion information failed ';}
Thanks. you can run it. do you need to close the database connection? Or will php automatically close the connection?
Php will automatically close the connection after the script is run. However, we recommend that you manually close the connection.
?????
Mysql_close () or die ('MySQL close error ');