1

The Update customer query in this code setting phno to a constant 2147483647 always instead of setting to the value submitted... i tried echoeing $phone its correct.. but its not working when im executing query....

<?php
    include 'database.php' ;
    $id=$_POST["customer"];
    $name = $_POST["name"];
    $address = $_POST["address"];
    $phone = $_POST["phno"];
    $sql = "UPDATE `customer`  SET `phno`=$phone, `name`='$name',`address`='$address' WHERE actno=$id";
    if (!mysqli_query($con,$sql))
      {
      die('Error: ' . mysqli_error($con));
      }
    echo "successful";
    mysqli_close($con);
?>
falsetru
  • 357,413
  • 63
  • 732
  • 636
Krishna Kittu
  • 106
  • 1
  • 12

2 Answers2

1

You set phno as INTEGER, didn't you? The maximum value of INTEGER is 2,147,483,647, so any number larger than 2,147,483,647 is out-of-range, and will be inserted as 2,147,483,647.

Change the datatype of phno to BIGINT or VARCHAR.

Also, your query is vulnerable to SQL injections, see the link below for more details.

See also:

Community
  • 1
  • 1
Petr R.
  • 1,247
  • 2
  • 22
  • 30
0

I think you are trying to substitute $phone in the string, but it wont work that way, either you split the string or use {}.

thegeek
  • 232
  • 2
  • 8
  • 1
    You're only halfway right, though I don't think you realize how. You are allowed to use a double-quoted string with a variable inside, and PHP will interpret that variable (like `"$myVar"`. However, for single-quoted strings, you need to use concatenation (like `'Hi ' . $myVar`). For the part you're right about, if `$phone` is a string, then it should be in quotes for MySQL to know it's a string *if there is a space in it*. – BLaZuRE Aug 03 '13 at 13:33