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
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");

?>

Link to comment
Share on other sites

thanks pocobueno1388 that solved it. However I do have another question when I am attempting to call the same album in a SELECT statement I do not require the quotes

i.e.

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

 

why would that be?

Link to comment
Share on other sites

I am looking for a number but identical code does not work in the two separate situations. I even tried copying a pasting the code from the one area to the other. It is even in the same page but will only recognize it in the one case.

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.