Page 1 of 1

Duplicate Removal

Posted: Tue Sep 17, 2002 10:45 pm
by craka
ok, im writing a script that will log a persons AIM screen name in MySQL when they view a subprofile page i made... it works.. but if a person views the page the script the more than once it will show their name multiple times .. I want mySQL not to log it in its database again.... What would the code look like for that.. this is the script i have written:

<?
$dbconn = mysql_connect("localhost", "username", "pass");
$result = mysql_select_db("screenames", $dbconn);
$insert = "INSERT INTO sns (sn) VALUES ('$name')";
$query = mysql_query($insert)or die(mysql_error());
mysql_close();
$dbconn = mysql_connect("localhost", "username", "pass");
$result = mysql_select_db("screenames", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
$sql = "SELECT sn FROM sns";
$result = mysql_query( $sql );
if ( $result != false )
{
while ( $data = mysql_fetch_assoc( $result ) )
{
echo 'Name: '.
$data['name'].'<a href="aim:goim?sreeenname='.
$data['sn'].'&message=Hello+Are+you+there?">'.
$data['sn'].'</a> <br>';


}
} else {
echo mysql_error();
}
}

mysql_close();
?>


and mah link to this page for aim looks like this:

<a href="http://page/aimthingy.php?name=%n" target="_self> page </a>
anyone know how i can modify it so that it doesnt log the same name mulitple times?

Posted: Tue Sep 17, 2002 11:45 pm
by hob_goblin
try something like this:

Code: Select all

<? 
	$screenname = str_replace(" ", "", $_GET&#1111;'name']);
	$screenname = str_replace("+", "", $screenname);
	$screenname = str_replace("%20", "", $screenname);
	$screenname = htmlentities($screenname);

$dbconn = mysql_connect("localhost", "username", "pass"); 
mysql_select_db("screenames", $dbconn) or die('Db selection failed');

$qry = mysql_query("SELECT * FROM sns WHERE sn = '$screenname'");

	if(@mysql_num_rows($qry) == "0")&#123;
	mysql_query("INSERT INTO sns (sn) VALUES ('$screenname')");
	&#125;


	$sql = "SELECT sn FROM sns"; 
	$result = mysql_query( $sql ); 

	while ($data = mysql_fetch_assoc($result)) 
	&#123; 
	echo "<a href="aim:goim?sreeenname=". 
	$data&#1111;'sn']."&message=Hello+Are+you+there?">". 
	$data&#1111;'sn']."</a><br>\n"; 

	&#125;
?> 


and mah link to this page for aim looks like this: 

<a href="http://page/aimthingy.php?name=%n" target="_self> page </a>

Posted: Wed Sep 18, 2002 4:27 pm
by craka
that worked on my computer... the one i was testing on... however when i moved it to my webserver it seemd as though it wasnt writing... see... the one that is in there i put to make sure it was retreieveing it.....

http://www.craka.com/profile/aim.php?na ... screenname

any suggestions?

Posted: Wed Sep 18, 2002 4:30 pm
by jason
Or you could look into using MySQL's REPLACE instead of SELECT/INSERT, that is what it's there for.