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

?>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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