Blank/duplicate Entries - a little help please.

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Blank/duplicate Entries - a little help please.

wappy
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.
Notice from jlhaslip:
chenged code tags to codebox

 

 

 


Reply

galexcd
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";

Reply

wappy
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.

 

 

 


Reply

squeetox
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.

Reply

wappy
Thanks, this has been a great help ;-)

Reply

galexcd
QUOTE(squeetox @ Jul 27 2007, 07:04 AM) *
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : blank duplicate entries

  1. Making Sure They Did Not Leave Any Required Fields Blank - (3)
    how to make sure they did not leave any required fields blank? CODE <?php
        include("config/config.inc.php");
        include("config/dbcon.php");     include("checksession.php");
                 if(isset($_POST['action'])){         $gname =
    $_POST['gname'];         $gemail = $_POST['mail'];
            $gmsg = $_POST['gmsg'];         $date =
    date("m.d.y"); $sql = "insert into tblg...
  2. Blank Cookies... - Need some help with Cookies... (4)
  3. Showing Numbers Of Mysql Entries In A Database Table - It should be easy, but I don't know how... (7)
    I have a database, and need to know how to show the numbers of entries. So, if there are 10 entries
    in the selected database table, it will show the number 10 . I'm pretty sure this should be
    easy, but I don't know how to do it. Can someone tell me? /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />...
  4. Php Shows Blank Page - (1)
    Hey there everyone, I'm trying to create a website using some PHP. I created an order form for
    my school company to let people order products this way. Only orders are made - no payments or
    anything. Now I have create the whole website. It is very simple. Every different product has a
    different combobox to select the number of items from. Then on the end of the page the client's
    details are asked. Now I created this PHP file that would handle everything, that is collecting all
    information and creating a well-formatted e-mail to send to the company's e-mail a...



Looking for blank, duplicate, entries,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for blank, duplicate, entries,

*MORE FROM TRAP17.COM*
advertisement



Blank/duplicate Entries - a little help please.



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE