-2

I have this website where I define an age for a animal to become old. If I define that 6 years is the age of an animal to become old I want to update my table(that as the born date of the animal) and all the animals in that situation become old. I have the Data field in varchar because in Date is was giving me problems.

$variable = $_POST['age']; **Here I am receiving the date I define in previous page**
if($variable == null){
     ?>
    <script>
    alert("Please choose an age");
    self.location="Definitions.php";
</script>


    <?php

}

**I need also to retrieve the actual system date**

if(isset($_POST['submit_x'])) **This is the id from previous page**
{    
        $query="update animal set old = '1' where chipnumber = {$var} AND user_id = {$_SESSION['user_id']}...."; **I need to complete my query in order to update only in the animals with the age I defined**
        mysqli_query($con, $query) or die (mysql_error());
Jose
  • 73
  • 3
  • 12
  • note, `$variable` != `$var`. And `mysql_error()` doesn't work with `mysqli_query()` (should be `die (mysqli_error($con))` – Sean Dec 30 '16 at 02:51
  • If your `chipnumber` (Data field?) is varchar, then you would need to treat your value as a string and quote it, ie. `... where chipnumber = '{$variable}' ...`. Also, time to read up on [How can I prevent SQL injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) to make sure your `$variable` does not lead to sql injection – Sean Dec 30 '16 at 02:52
  • question's way too unclear. check for errors, you have some. – Funk Forty Niner Dec 30 '16 at 02:54

1 Answers1

0
  $query="update animal set old = '1' where chipnumber = '".$_POST['var']."' AND user_id = '".$_POST['id']."' ... ;  

Should be modified in this way . Or the better way is to create one table row as UI interface. You don't have to create one more field for old or not. As old flag is decided by the age. Column old becomes redundant .

Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141