kendallkamikaze Posted March 20, 2009 Share Posted March 20, 2009 for some reason the portion that says: $query="UPDATE horsedata SET retired='yes' AND dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; is updating to 0 instead of yes...how do I fix this? <?php include 'header.php'; ?> <?php $sql = "SELECT id from horsedata WHERE id = '$horseid' AND Owner = '$id' AND DOB > 24"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($result) > 0){ $sql1 = "SELECT id from horsedata WHERE (Sire = ".$horseid." OR Dam = ".$horseid.")"; echo "<!-- ".$sql1." -->"; $result1= mysql_query($sql1) or die ( mysql_error() ); if(mysql_num_rows($result1) == 0) { $sql = "DELETE FROM horsedata WHERE id = $horseid"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql)or die ( mysql_error() );; echo "You have Euthanized this horse."; } else { $query="UPDATE horsedata SET retired='yes' AND dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; echo "<!-- ".$query." -->"; $checkresult = mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()>0) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font>"; else echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse or the horse is not old enough to be retired.</b></font>"; } } else { } ?> <?php include 'footer.php'; ?> Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 20, 2009 Share Posted March 20, 2009 Where are $horseid and $id set? And you have a double semi-colon there in the middle. Not that I think it would matter though. Quote Link to comment Share on other sites More sharing options...
suma237 Posted March 20, 2009 Share Posted March 20, 2009 replace with this code $query="UPDATE horsedata SET retired='yes' , dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 Where are $horseid and $id set? And you have a double semi-colon there in the middle. Not that I think it would matter though. im not sure what you mean...do you mean what table are they on? or if they are set on a pervious page? im a total php beginner...yet i own a php based site.. :-\ Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 replace with this code $query="UPDATE horsedata SET retired='yes' , dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; that got it functional! but now its not posting : 'You do not own this horse or the horse is not old enough to be retired.' if it doesnt meet the owner = $id and DOB > 24 Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 20, 2009 Share Posted March 20, 2009 I mean where are they defined? I.e. <?php $horseid = 'some ID'; $id = 'owner'; ?> And suma237 is right about using a comma instead of AND. Quote Link to comment Share on other sites More sharing options...
suma237 Posted March 20, 2009 Share Posted March 20, 2009 check the type(var char,enum..) of the field you defined Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 I mean where are they defined? I.e. <?php $horseid = 'some ID'; $id = 'owner'; ?> And suma237 is right about using a comma instead of AND. horse id is from the link, owner id appears to not be defined...but it still works apparently? Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 check the type(var char,enum..) of the field you defined dead and retired are both varchar Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 i don't see $horseid anywhere in your script.. if it's from the link, you should add something like this maybe $horseid = $_GET['horseid']; Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 i don't see $horseid anywhere in your script.. if it's from the link, you should add something like this maybe $horseid = $_GET['horseid']; it is there <?php include 'header.php'; ?> <?php $horseid=$_GET['id']; $sql = "SELECT id from horsedata WHERE id = '$horseid' AND Owner = '$id' AND DOB > 24"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($result) > 0){ $sql1 = "SELECT id from horsedata WHERE (Sire = ".$horseid." OR Dam = ".$horseid.")"; echo "<!-- ".$sql1." -->"; $result1= mysql_query($sql1) or die ( mysql_error() ); if(mysql_num_rows($result1) == 0) { $sql = "DELETE FROM horsedata WHERE id = $horseid"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql)or die ( mysql_error() );; echo "You have Euthanized this horse."; } else { $query="UPDATE horsedata SET retired='yes' , dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; echo "<!-- ".$query." -->"; $checkresult = mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()>0) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font>"; else echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse or the horse is not old enough to be retired.</b></font>"; } } else { } ?> <?php include 'footer.php'; ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 $_GET['id'] is set ? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 20, 2009 Share Posted March 20, 2009 So the $horseid is set from the URL, like page.php?horseid=123? Then the proper way to retrieve the data in the script is via $_GET (like the rest told you - yeah I'm a bit late ): <?php $horseid = $_GET['horseid']; ?> Else it depends on the register_globals setting (which is enabled on your server), and that's a bad thing, if not specifically kept in mind when coding. If the horseid is unique, you can simply remove the ownerid from the query. Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 So the $horseid is set from the URL, like page.php?horseid=123? Then the proper way to retrieve the data in the script is via $_GET (like the rest told you - yeah I'm a bit late ): <?php $horseid = $_GET['horseid']; ?> Else it depends on the register_globals setting (which is enabled on your server), and that's a bad thing, if not specifically kept in mind when coding. If the horseid is unique, you can simply remove the ownerid from the query. the 'owner' id is there so that other players cant 'steal' other peoples horses...because sad to say but it happens on my game haha Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 right now, everything functions BUT the part where if the horse does not meet the owner and DOB requirements, its not posting the 'you dont own this horse or it is not old enough' Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 add error_reporting(E_ALL); to the top of the file and see if any problems come up. Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 add error_reporting(E_ALL); to the top of the file and see if any problems come up. nothing showed up but the header and footer Quote Link to comment Share on other sites More sharing options...
suma237 Posted March 20, 2009 Share Posted March 20, 2009 use bracket when you apply conditions UPDATE horsedata SET retired='yes' , dead='yes' WHERE (id='$horseid' AND Owner='$id' AND DOB > 24) Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 use bracket when you apply conditions UPDATE horsedata SET retired='yes' , dead='yes' WHERE (id='$horseid' AND Owner='$id' AND DOB > 24) nope, still hasnt made it say what its supose to when horse doesnt meet requirements Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 why dont you just use if ($checkresult){ echo "<br /><br /><font size='5pt' face='comic sans ms'><b>Your horse has been retired.</b></font>"; } else { echo "<BR><BR><font size='5pt' face='comic sans ms'><B>You do not own this horse or the horse is not old enough to be retired.</b></font>"; } Quote Link to comment Share on other sites More sharing options...
kendallkamikaze Posted March 20, 2009 Author Share Posted March 20, 2009 <?php include 'header.php'; ?> <?php $horseid=$_GET['id']; $sql = "SELECT id from horsedata WHERE id = '$horseid' AND Owner = '$id' AND DOB > 24"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql) or die ( mysql_error ); if(mysql_num_rows($result) > 0){ $sql1 = "SELECT id from horsedata WHERE (Sire = ".$horseid." OR Dam = ".$horseid.")"; echo "<!-- ".$sql1." -->"; $result1= mysql_query($sql1) or die ( mysql_error() ); if(mysql_num_rows($result1) == 0) { $sql = "DELETE FROM horsedata WHERE id = $horseid"; echo "<!-- ".$sql." -->"; $result=mysql_query($sql)or die ( mysql_error() );; echo "You have Euthanized this horse."; } else { $query="UPDATE horsedata SET retired='yes' , dead='yes' WHERE id='$horseid' AND Owner='$id' AND DOB > 24"; echo "<!-- ".$query." -->"; $checkresult = mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()>0) echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Your horse has been retired.</b></font><BR><BR>"; } } else echo "<BR><BR><font size='4pt' face='comic sans ms'><B>This horse is not old enough to be euthanized, or you do not own it.</b></font><BR><BR>"; ?> <?php include 'footer.php'; ?> functioning code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.