Jump to content

[SOLVED] Newbie PHP/mySQL syntax problem


ssweb

Recommended Posts

I got this code to insert values into a database and can't seem to find the problem in the following code:

 

//php code

 

$sql = "UPDATE chrislistings SET

listing_address = '" . addslashes($_POST['listing_address']) . "',

listing_overview = '" . addslashes($_POST['listing_overview']) . "',

listing_price = '" . addslashes($_POST['listing_price']) . "',

listing_location = '" . addslashes($_POST['listing_location']) . "',

listing_style = '" . addslashes($_POST['listing_style']) . "',

listing_sqrft = '" . addslashes($_POST['listing_sqrft']) . "',

listing_lotwidth = '" . addslashes($_POST['listing_lotwidth']) . "',

listing_lotlength = '" . addslashes($_POST['listing_lotlength']) . "',

listing_year = '" . addslashes($_POST['listing_year']) . "',

listing_taxes = '" . addslashes($_POST['listing_taxes']) . "',

listing_parking = '" . addslashes($_POST['listing_parking']) . "',

listing_exterior = '" . addslashes($_POST['listing_exterior']) . "',

listing_roof = '" . addslashes($_POST['listing_roof']) . "',

listing_heating = '" . addslashes($_POST['listing_heating']) . "',

listing_ac = '" . addslashes($_POST['listing_ac']) . "',

listing_fireplace = '" . addslashes($_POST['listing_fireplace']) . "',

listing_school = '" . addslashes($_POST['listing_school']) . "',

listing_transit = '" . addslashes($_POST['listing_transit']) . "',

listing_bathrooms = '" . addslashes($_POST['listing_bathrooms']) . "',

listing_bedrooms = '" . addslashes($_POST['listing_bedrooms']) . "'

WHERE listing_id = " . addslashes($_GET['listing_id']);

 

//end PHP

 

I actually copied the code from another one of my pages where it worked fine. The only difference is I am entering more values this time. 

 

I get the following error message.

 

Error inserting record: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 22

Link to comment
https://forums.phpfreaks.com/topic/88315-solved-newbie-phpmysql-syntax-problem/
Share on other sites

You don't have quotes around your $_GET['listing_id'] var, that could be the problem.

 

<?php

$sql = "UPDATE chrislistings SET
   listing_address = '" . addslashes($_POST['listing_address']) . "',
   listing_overview = '" . addslashes($_POST['listing_overview']) . "',
   listing_price = '" . addslashes($_POST['listing_price']) . "',
   listing_location = '" . addslashes($_POST['listing_location']) . "',
   listing_style = '" . addslashes($_POST['listing_style']) . "',
   listing_sqrft = '" . addslashes($_POST['listing_sqrft']) . "',
   listing_lotwidth = '" . addslashes($_POST['listing_lotwidth']) . "',
   listing_lotlength = '" . addslashes($_POST['listing_lotlength']) . "',
   listing_year = '" . addslashes($_POST['listing_year']) . "',
   listing_taxes = '" . addslashes($_POST['listing_taxes']) . "',
   listing_parking = '" . addslashes($_POST['listing_parking']) . "',
   listing_exterior = '" . addslashes($_POST['listing_exterior']) . "',
   listing_roof = '" . addslashes($_POST['listing_roof']) . "',
   listing_heating = '" . addslashes($_POST['listing_heating']) . "',
   listing_ac = '" . addslashes($_POST['listing_ac']) . "',
   listing_fireplace = '" . addslashes($_POST['listing_fireplace']) . "',
   listing_school = '" . addslashes($_POST['listing_school']) . "',
   listing_transit = '" . addslashes($_POST['listing_transit']) . "',
   listing_bathrooms = '" . addslashes($_POST['listing_bathrooms']) . "',
   listing_bedrooms = '" . addslashes($_POST['listing_bedrooms']) . "'
   WHERE listing_id = '" . addslashes($_GET['listing_id']) . "'";

?>

 

Also, you should try echoing the query out in the die error, like so

 

<?php

$query = mysql_query($sql)or die(mysql_error() . "<p>With Query:<br>$sql");

?>

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.