Jump to content

[SOLVED] php code updates to '0' instead of 'yes'


kendallkamikaze

Recommended Posts

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';

?>

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.. :-\

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

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?

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';

?>

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.

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.