Jump to content

[SOLVED] debugging script - syntax confusion


kate_rose

Recommended Posts

Someone over in the mysql help section suggested that I have incorrect syntax in the snippet of code below.  I have always used the periods and double quotes to put a php variable into a mysql query but I am very new at this so maybe it does need to be changed.  Specifically I am refereding to the $savetodb variable syntax.  I am trying to send a serialized array to a mysql db.

 

<?php
$query = "INSERT INTO serialized_data(key, serialized) VALUES ('picstorage','". $savetodb ."')";
?>

 

Thanks,

 

Kate

Link to comment
Share on other sites

The syntax looks correct to me.  You could try adding a space after 'serialized_data'.  so..

 

<?php
$query = "INSERT INTO serialized_data (key, serialized) VALUES ('picstorage','". $savetodb ."')";
?>

 

Also make sure the field in the database if of a type capable of storing what you are trying to store.  And try to include any error messages you are getting.

Link to comment
Share on other sites

Here is the code at least the part I am having trouble with.

 

<?php
$savetodb = (serialize($picstorage));		//convert picstorage into a sqlinput string
echo $savetodb;
$query = "INSERT INTO serialized_data (key, serialized) VALUES ('picstorage','". $savetodb ."')";  
mysql_query($query);
?> 

 

As far as i know the "serialized_data" part of the query is the part of the INSERT command which tells mysql which table to use.

 

The database column is set to mediumtext but this is a rather big array.  I will try setting it to accept larger strings.

 

Anyway I am getting no error message at all.  It all looks fine but when I go look in the serialized_data table nothing has been added.

The echo $savetodb is returning the serialized array with no problem so it has to be in the query I think.

 

k- ???

 

The string I am saving does have backslashes & stuff in it.  Would that make a difference?

Link to comment
Share on other sites

Oh thats handy.  Sorry I didn't know about that before.

 

The error I get is

 

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 'key, serialized) VALUES ('picstorage','a:308:{i:0;s:36:"Acanthaceae\Asystasia_ga' at line 1

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.