Home > Backend Development > PHP Tutorial > 求php实现代码 实现点击url 就记要一个指定的参数

求php实现代码 实现点击url 就记要一个指定的参数

WBOY
Release: 2016-06-13 12:07:55
Original
1216 people have browsed it

求php实现代码 实现点击url 就记录一个指定的参数。
对 php 很不熟悉,需要一个功能:
点击url 就能把url 的一段字符串记录在数据库如何实现?用于取消订阅
例如: http://mydomain.com/abc.php?username=myname
点击这个url, php程序就记录 myname,并 插入 mysql数据库 mydatabase 的 unsubscribe 表中,
 mysql 的用户名 是 root  ,密码 123456

求php实现代码
------解决思路----------------------

<br />CREATE TABLE `unsubscribe` (<br />  `id` int(10) unsigned NOT NULL auto_increment,<br />  `username` varchar(100) NOT NULL,<br />  PRIMARY KEY  (`id`)<br />) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />
Copy after login

假设unsubscribe数据表是以上结构

abc.php可以这样写
<br />// 连接数据库  <br />[email&#160;protected]_connect("localhost","root","123456")  or die(mysql_error());   // localhost是添你db的host,如果不是本地的请修改这里<br />@mysql_select_db('mydatabase',$conn) or die(mysql_error()); <br /><br />$username = isset($_GET['username'])? mysql_escape_string($_GET['username']) : '';<br /><br />if($username){<br />	$sqlstr = "insert into unsubscribe(username) values('".$username."')";<br />    mysql_query($sqlstr) or die(mysql_error());<br />    echo 'insert success';<br />}<br />
Copy after login


访问:http://mydomain.com/abc.php?username=myname
------解决思路----------------------
<br />$username=$_GET['username'];<br />$con=mysqli_connect('localhost','root','123456','mydatabase');<br />$sql="insert into unsubscribe(username) values('$username')";<br />if(mysqli_query($con,$sql)){<br />    echo '插入信息成功';<br />}else{<br />    echo '插入信息失败';<br />}<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template