Find the php implementation code and click the url to record a specified parameter. -Php Tutorial

Source: Internet
Author: User
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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.