Jump to content
xisto Community
Sign in to follow this  
wappy

Blank/duplicate Entries a little help please.

Recommended Posts

Hi, I have been working with a download/link exchange script: http://forums.xisto.com/no_longer_exists/

However it has some problems when adding download links..

Users can submit downloads with no title, and also entries with duplicate titles.

Can anyone show me how to fix this?? Here is the submit page:

     $rank=1;
while ($row = mysql_fetch_row($result)) //read fields from record set
{
$title=$row[0];
$url=$row[1];
$points=$row[2];
$id=$row[4];
if($rank <= $toptop) //only display first X number of banners
{
$banner=$row[3];
}
if ($banner!="")
{
echo "<a href='$url' target='_blank'><img border=0 src=$banner></A> - $points<BR>";
}
else { ?> linenums:0'><?php include("dbconnect.php"); ?> <html> <head> <title><? echo $sitename ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META NAME="Keywords" CONTENT="<? echo $keywords; ?>"> <META NAME="Description" CONTENT="<? echo $description; ?>"> <META NAME="Author" CONTENT="<? echo $yourmail; ?>"> <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW"> <META NAME="REVISIT-AFTER" CONTENT="1 DAYS"> <META NAME="RATING" CONTENT="GENERAL"> <link rel="stylesheet" type="text/css" href="images/evilddl.css" /> </head> <div align="center"> <body bgcolor="#FFFFFF" text="#000000" link="#333333" vlink="#333333" alink="#333333"> <table width="928" border="0" cellspacing="1" cellpadding="0" class="main"> <tr> <td colspan="2"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td background="images/sitetitleback.gif"><img src="images/banner.gif" width="339" height="70"></td> </tr> </table> </td> </tr> <tr> <td valign="top"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Menu</td> </tr> <tr> <td class="bottom"> <?php include("menu.txt"); ?> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Affiliates</td> </tr> <tr> <td class="bottom"> <?php include("aff.txt"); ?> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Top Sites</td> </tr> <tr> <td class="bottom"> <?php $result=mysql_query("select titel, url, points, banner, id from toplist WHERE points > 0 ORDER BY points DESC LIMIT 0,$topsites;"); //fetch all fields from table which's points are > 0 order them by most points, and limit number of records by global defined amount of topsites to be displayed $rank=1; while ($row = mysql_fetch_row($result)) //read fields from record set { $title=$row[0]; $url=$row[1]; $points=$row[2]; $id=$row[4]; if($rank <= $toptop) //only display first X number of banners { $banner=$row[3]; } if ($banner!="") { echo "<a href='$url' target='_blank'><img border=0 src=$banner></A> - $points<BR>"; } else { ?>:: <a href="site.php?id=<? echo $id ?>"><? echo $title ?></a><br> <? } $banner=""; $rank += 1; } ?> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Search</td> </tr> <tr> <td class="bottom"> <?php include("search.htm"); ?> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Stats</td> </tr> <tr> <td class="bottom"> <?php $ip = $_SERVER['REMOTE_ADDR']; echo ":: IP: $ip"; ?> <br> :: Date: <?PHP echo date("D M d, Y"); ?> <br> :: Time: <?PHP echo date("H:i:s"); include_once ("online.php"); $visitors_online = new usersOnline(); if (count($visitors_online->error) == 0) { $online = $visitors_online->count_users(); echo "<br>:: Online: $online"; } ?> </td> </tr> </table> </td> </tr> </table> </td> <td width="735" valign="top"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr> <td background="images/tabletop.gif" height="21" class="top">Advert</td> </tr> <tr> <td class="bottom"> <?php include("ad.htm"); ?> </td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="2" class="box"> <tr background="images/tabletop.gif"> <td height="21" colspan="2" class="top"> <p>Add Downloads</p> </td> </tr> <tr> <td class="bottom" valign="top"><? if(isset($_POST['submit'])) { $ip = $_SERVER['REMOTE_ADDR']; $date = date("d/m/Y"); $title = addslashes($_POST['title']); $description = addslashes($_POST['description']); $link = addslashes($_POST['link']); $crack = addslashes($_POST['crack']); $query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')"; $result = mysql_query($query); if ($result) { echo "<b>Download Added</b><br/>You can add another in 2 seconds."; echo "<meta http-equiv=Refresh content=2;url=submit.php>"; } else { echo "Download could not be added.<br/>"; } } else { ?> <br> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Title: <br><input name="title" size="55" maxlength="255"> <br> <br> Description:<br><textarea name="description" rows="9" cols="50"></textarea> <br> <br> Link(s):<br> <textarea name="link" rows="6" cols="50">http://test.com/file0.rar<br> [url="https://www.test.com/; [url="https://www.test.com/; [url="https://www.test.com/; <br> <br> Crack/Password: <br> <input name="crack" size="55" maxlength="255"> <br> <br> <input type="submit" name="submit" value="Add Download"> </form> <?php } ?></td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <div align="center"><?php include("foot.txt"); ?> </div> </div> </td> </tr> </table></div> </body> </html>
Here is the bit that needs the work:

   {

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("d/m/Y");
$title = addslashes($_POST['title']);
$description = addslashes($_POST['description']);
$link = addslashes($_POST['link']);
$crack = addslashes($_POST['crack']);
$query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')";

$result = mysql_query($query);

if ($result) {
echo "<b>Download Added</b><br/>You can add another in 2 seconds.";
echo "<meta http-equiv=Refresh content=2;url=submit.php>";
} else {
echo "Download could not be added.<br/>";
}
}
else
{
?>
<br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Title linenums:0'><? if(isset($_POST['submit'])) { $ip = $_SERVER['REMOTE_ADDR']; $date = date("d/m/Y"); $title = addslashes($_POST['title']); $description = addslashes($_POST['description']); $link = addslashes($_POST['link']); $crack = addslashes($_POST['crack']); $query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')"; $result = mysql_query($query); if ($result) { echo "<b>Download Added</b><br/>You can add another in 2 seconds."; echo "<meta http-equiv=Refresh content=2;url=submit.php>"; } else { echo "Download could not be added.<br/>"; } } else { ?> <br> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Title: <br><input name="title" size="55" maxlength="255"> <br> <br> Description:<br><textarea name="description" rows="9" cols="50"></textarea> <br> <br> Link(s):<br> <textarea name="link" rows="6" cols="50">http://test.com/file0.rar<br> [url="https://www.test.com/; [url="https://www.test.com/; [url="https://www.test.com/; <br> <br> Crack/Password: <br> <input name="crack" size="55" maxlength="255"> <br> <br> <input type="submit" name="submit" value="Add Download"> </form> <?php } ?>
Thanks in advance for any help, im not very good at coding.
Notice from jlhaslip:
chenged code tags to codebox

Share this post


Link to post
Share on other sites

I'd suggest doing adding this if statement around your query:

if($title!="" && mysql_num_rows(mysql_query("SELECT * FROM `downloads` WHERE `title` = '".$title."'"))==0){//Your original code:$query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')";$result = mysql_query($query);}else echo"The title you entered was either invalid or already exists";

Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

Thanks i will try this out.

Edit: It works great but it was still showing Download Added text so i got round it like this:

if($title!="" && mysql_num_rows(mysql_query("SELECT * FROM `downloads` WHERE `title` = '".$title."'"))==0){  $add = 1;$query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')";$result = mysql_query($query);}else echo "<b>Download NOT Added</b><br/>The title you entered was either invalid or already exists.";if ($result) { if ($add==1){echo "<b>Download Added</b><br/>You can add another in 2 seconds.";}echo "<meta http-equiv=Refresh content=2;url=submit.php>";}

With the $add bit.
Edited by wappy (see edit history)

Share this post


Link to post
Share on other sites

I think you could even make it a little faster like this (if it's got a big database):

if($title!="" && mysql_num_rows(mysql_query("SELECT * FROM `downloads` WHERE `title` = '".$title."' LIMIT 1"))==0){$add = true;$query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')";$result = mysql_query($query);}else echo "<b>Download NOT Added</b><br/>The title you entered was either invalid or already exists.";if ($result) {if ($add){echo "<b>Download Added</b><br/>You can add another in 2 seconds.";}echo "<meta http-equiv=Refresh content=2;url=submit.php>";}
This way if it finds an entry it will stop querying, which is good for keeping MySQL queries as low as possible.
Edited by squeetox (see edit history)

Share this post


Link to post
Share on other sites

Thanks, this has been a great help ;-)

Share this post


Link to post
Share on other sites

I think you could even make it a little faster like this (if it's got a big database):

if($title!="" && mysql_num_rows(mysql_query("SELECT * FROM `downloads` WHERE `title` = '".$title."' LIMIT 1"))==0){$add = true;$query = "INSERT INTO `downloads` (title, date, description, link, crack, ip) VALUES ('$title','$date','$description', '$link', '$crack', '$ip')";$result = mysql_query($query);}else echo "<b>Download NOT Added</b><br/>The title you entered was either invalid or already exists.";if ($result) {if ($add){echo "<b>Download Added</b><br/>You can add another in 2 seconds.";}echo "<meta http-equiv=Refresh content=2;url=submit.php>";}
This way if it finds an entry it will stop querying, which is good for keeping MySQL queries as low as possible.

Oh yes good point. I wasn't thinking too hard about it when i wrote my fix and didn't even think about efficiency. Yes limiting the ammount of rows it checks would save precious loading time.
Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.