Jump to content

[SOLVED] Inserting a variable into a database.


Michdd

Recommended Posts

I'm trying to insert a variable into a database using this code:

 

mysql_query("INSERT INTO monsters 
(monster, loc) VALUES($ucTitleString, $loc ) ") 
or die(mysql_error());  

mysql_query("INSERT INTO monsters 
(spawn, drops) VALUES($spawn, $drops ) ") 
or die(mysql_error());  

mysql_query("INSERT INTO example 
(hp, exp) VALUES($hp, $exp ) ") 
or die(mysql_error());  

echo "Data Inserted!";

 

When doing this I get this error:

 

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 'name, Location )' at line 2

SQL values need to be warped in quotes.

mysql_query("INSERT INTO monsters 
(monster, loc) VALUES('$ucTitleString', '$loc' ) ") 
or die(mysql_error());  

mysql_query("INSERT INTO monsters 
(spawn, drops) VALUES('$spawn', '$drops' ) ") 
or die(mysql_error());  

mysql_query("INSERT INTO example 
(hp, exp) VALUES('$hp', '$exp' ) ") 
or die(mysql_error());  

echo "Data Inserted!";

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.