Find the php implementation code and click the url to record a specified parameter. I am not familiar with & nbsp; php & nbsp; and need a function: click url & nbsp; to record a string of url & nbsp; in the database. how can this problem be solved? Used to cancel a subscription, for example, & nbsp; mydomain. comabc. php? Usernamemyname: click this url. & nbsp; the php program Records & requests the php implementation code. 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
------ Solution ----------------------
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
[Email protected] _ connect ("localhost", "root", "123456") or die (mysql_error (); // localhost is the host that adds your database, if it is not local, modify it here.
@ 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
------ Solution ----------------------
$ 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 'failed to insert information ';
}