0

I feel nothing is wrong with the query i have. i do not understand why i getting the error.

I already tried to remove the single quote on query but its still the same.

here's m code

ERROR

Couldn't enter data: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Hills, price='393787', sqmw='218', sqml='218', sqm='47524', income='3773773' at line 1

UPDATED thanks

PHP CODE MYSQL

require 'connection.php';
$conn    = Connect();
$id= $conn->real_escape_string($_POST['id']);
$descr= $conn->real_escape_string($_POST['descr']);
$price= $conn->real_escape_string($_POST['price']);
$sqmw= $conn->real_escape_string($_POST['sqmw']);
$sqml= $conn->real_escape_string($_POST['sqml']);
$sqm = $sqmw * $sqml;
$income= $conn->real_escape_string($_POST['income']);
$statuss= $conn->real_escape_string($_POST['statuss']);
$query   = " UPDATE wentwrong SET descr='$descr',
 price='$price',
 sqmw='$sqmw',
 sqml='$sqml',
 sqm='$sqm',
 income='$income',
 statuss='$statuss'
 WHERE id='$id' ";

$success = $conn->query($query); 

if (!$success) {
    die("Couldn't enter data: ".$conn->error);

}

echo '<script language="javascript">';
echo 'alert("Edit Successfully!")';
echo '</script>';

echo '<script language="javascript">';
echo 'window.location.href = "http://google.com"';
echo '</script>';


$conn->close();

?>
O. Jones
  • 103,626
  • 17
  • 118
  • 172
Randy Corpuz
  • 153
  • 1
  • 10

1 Answers1

2

You're missing quotes around a constant. Where you have

 $query   = " UPDATE wentwrong SET descr=$descr,    /*wrong*/

you should have

 $query   = " UPDATE wentwrong SET descr='$descr',  

The tricks to troubleshooting this kind of thing.

  1. read error messages carefully. Then read them again.
  2. believe the error messages. You're working with systems that have been around for a couple of decades. They aren't throwing random bogus errors any more.
  3. In the case of MySQL's syntax error message, it shows you the erroneous query, starting with the first character it could not understand.
O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • holy cow. i missed that. thanks buddy – Randy Corpuz Aug 13 '17 at 11:29
  • 1
    The OP should invest time into learning how to use prepared statements. In any case, typo questions should not be answered. – Tim Biegeleisen Aug 13 '17 at 11:31
  • @TimBiegeleisen, that's absolutely true. It's more secure from cybercreeps. It definitively gets rid of the quoted-string issues. But we have to meet beginniners where they are, not where we wish they were. I wish php just rejected that kind of thing, like taintPerl does. – O. Jones Aug 13 '17 at 11:34
  • Fair enough +1 ... given the shortage of good questions here over the weekend, anything answerable looks better than a filet mignon steak to a starving man. – Tim Biegeleisen Aug 13 '17 at 11:37