|
|
|
|
![]() ![]() |
Jul 26 2007, 09:40 PM
Post
#1
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
Hi, I have been working with a download/link exchange script: http://evilddl.info/download/EViLDDL_1.0.1.rar
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: CODE <?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> http://test.com/file1.rar<br> http://test.com/file2.rar<br> http://test.com/file3.rar</textarea> <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: CODE <? 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> http://test.com/file1.rar<br> http://test.com/file2.rar<br> http://test.com/file3.rar</textarea> <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. |
|
|
|
Jul 27 2007, 04:35 AM
Post
#2
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 25-September 05 From: The dungeon deep below the foundation of trap17 Member No.: 12,251 |
I'd suggest doing adding this if statement around your query:
CODE 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"; This post has been edited by alex7h3pr0gr4m3r: Jul 27 2007, 04:36 AM |
|
|
|
Jul 27 2007, 11:18 AM
Post
#3
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
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: CODE 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. This post has been edited by wappy: Jul 27 2007, 11:34 AM |
|
|
|
Jul 27 2007, 02:04 PM
Post
#4
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 31 Joined: 22-July 07 Member No.: 46,856 |
I think you could even make it a little faster like this (if it's got a big database):
CODE 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. This post has been edited by squeetox: Jul 27 2007, 02:05 PM |
|
|
|
Jul 27 2007, 10:21 PM
Post
#5
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
Thanks, this has been a great help ;-)
|
|
|
|
Jul 28 2007, 11:48 PM
Post
#6
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 25-September 05 From: The dungeon deep below the foundation of trap17 Member No.: 12,251 |
I think you could even make it a little faster like this (if it's got a big database): CODE 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. This post has been edited by alex7h3pr0gr4m3r: Jul 28 2007, 11:49 PM |
|
|
|
![]() ![]() |
Similar Topics