Jump to content

[SOLVED] No Double entry? Please help.


kendallkamikaze

Recommended Posts

I've been working on trying to fix this code for the last 2 hours, I want it to make it so that it will not let you enter two times. this is what i have so far:

 

<?php  
  
include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];


$sql="INSERT INTO winterfest (horseid, userid, classname, classtype)
VALUES
('$_POST[horseid]','$id','$_POST[classname]','$_POST[classtype]')";
if (!mysql_query($sql))
  {
  die('You cannot enter that show because you have already that horse in one of its type.');
}

echo "Success! You have entered Winterfest!"; 
  
?>

Link to comment
Share on other sites

<?php  
  
include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];


$sql="INSERT INTO winterfest (horseid, userid, classname, classtype)
VALUES
('$_POST[horseid]','$id','$_POST[classname]','$_POST[classtype]')";
if (!mysql_query($sql))
  {
  die('You cannot enter that show because you have already that horse in one of its type.');
}

echo "Success! You have entered Winterfest!"; 
  
?>

 

I've been working on trying to fix this code for the last 2 hours, I want it to make it so that it will not let you enter two times.

Link to comment
Share on other sites

<?php  
  
include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];


$sql="REPLACE INTO winterfest (horseid, userid, classname, classtype)
VALUES
('$_POST[horseid]','$id','$_POST[classname]','$_POST[classtype]')";
if (!mysql_query($sql))
  {
  die('You cannot enter that show because you have already that horse in one of its type.');
}

echo "Success! You have entered Winterfest!"; 
  
?>

didnt work :(

Link to comment
Share on other sites

Not tested but should work.  If the user has 2 or more records than it won't let them insert, are there any other restrictions?

 

include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];

$check_query = "SELECT * FROM winterfest WHERE id = $userid";
$num_rows = mysql_num_rows($check_query) or die(mysql_error());
if($num_rows > 1)
{
echo "You have enter 2 or more times.";
}
else {
$sql="INSERT INTO winterfest (horseid, userid, classname, classtype) VALUES ('$horseid','$userid','$classname','$classtype')";
mysql_query($sql) or die(mysql_query());
echo "Success! You have entered Winterfest!"; 
}
?>

Link to comment
Share on other sites

yes, sorry i had posted it in the wrong thread. I didnt even realize people were posting on it O.O

 

With the code MAQ provided, seems like it would work but I'm getting:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/collegh9/public_html/one-stride/winterfest_enter.php on line 10

 

<?php  
include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];

$check_query = "SELECT * FROM winterfest WHERE id = $userid";
$num_rows = mysql_num_rows($check_query) or die(mysql_error());
if($num_rows => 1)
{
echo "You have enter 2 or more times.";
}
else {
$sql="INSERT INTO winterfest (horseid, userid, classname, classtype) VALUES ('$horseid','$userid','$classname','$classtype')";
mysql_query($sql) or die(mysql_query());
echo "Success! You have entered Winterfest!"; 
}
?>

Link to comment
Share on other sites

Actually, greater than or equal is >=

 

=> has special significance and is not a comparison operator.

 

Upon further review, the posted code has a few other problems. There is no mysql_query() in it to execute the SELECT query and the or die() statement would need to be part of that mysql_query().

 

Replace this line -

 

$num_rows = mysql_num_rows($check_query) or die(mysql_error());

 

With these -

$result = mysql_query($check_query) or die(mysql_error());
$num_rows = mysql_num_rows($result));

Link to comment
Share on other sites

Sorry thank you for the corrections guys, I don't have an environment to test this in right now ;/

 

@PFMaBiSmAd

You have an extra ')' in the second line you corrected.

 

My revised code (that should work  :P ):

 

include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];

$check_query = "SELECT * FROM winterfest WHERE id = $userid";
$result = mysql_query($check_query) or die(mysql_error())
$num_rows = mysql_num_rows($check_query);
if($num_rows >= 1)
{
   echo "You have enter 2 or more times.";
}
else {
   $sql="INSERT INTO winterfest (horseid, userid, classname, classtype) VALUES ('$horseid','$userid','$classname','$classtype')";
   mysql_query($sql) or die(mysql_query());
   echo "Success! You have entered Winterfest!"; 
}
?>

Link to comment
Share on other sites

Oops here you go (supposed to be $num_rows = mysql_num_rows($result); )  ;)

 

include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];

$check_query = "SELECT * FROM winterfest WHERE id = $userid";
$result = mysql_query($check_query) or die(mysql_error())
$num_rows = mysql_num_rows($result);
if($num_rows >= 1)
{
   echo "You have enter 2 or more times.";
}
else {
   $sql="INSERT INTO winterfest (horseid, userid, classname, classtype) VALUES ('$horseid','$userid','$classname','$classtype')";
   mysql_query($sql) or die(mysql_query());
   echo "Success! You have entered Winterfest!"; 
}
?>

Link to comment
Share on other sites

the code is fully functional now, but its still allowing double entries...AHAH!

 

I've got it. I realized that user id is not actually posted onto the winterfest table, so by switching user id to horseid its now functional!

 

<?php
include 'header.php'; 
  
$horseid = $_POST['horseid'];
$userid = $_POST['userid']; 
$classtype = $_POST['classtype'];
$classname = $_POST['classname'];

$check_query = "SELECT * FROM winterfest WHERE horseid = $horseid";
$result = mysql_query($check_query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows >= 1)
{
   echo "You have enter 2 or more times.";
}
else {
   $sql="INSERT INTO winterfest (horseid, userid, classname, classtype) VALUES ('$horseid','$userid','$classname','$classtype')";
   mysql_query($sql) or die(mysql_query());
   echo "Success! You have entered Winterfest!"; 
}
?>

 

This website has been amazing. You guys are GREAT help to my lack of PHP knowledge!

I wish I could pay you guys for all your help. If you ever need any work or have time for any work I'm willing to pay to get things fixed/made for my game!

 

<3

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.