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'; ?> Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/ 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. Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789264 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"; Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789266 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.. :-\ Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789269 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789273 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. Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789280 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789286 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? Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789287 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789288 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']; Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789289 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'; ?> Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789291 Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 $_GET['id'] is set ? Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789294 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. Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789295 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789298 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' Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789301 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. Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789303 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789305 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) Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789308 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 Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789314 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>"; } Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789323 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. Link to comment https://forums.phpfreaks.com/topic/150291-solved-php-code-updates-to-0-instead-of-yes/#findComment-789668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.