php insert

dianax8

New Member
Messages
4
Reaction score
0
Points
1
I really hope you can help. I'm VERY new to php and I'm having trouble getting info to "insert" into my database. I have database created and I can insert manually in phpmyadmin, but not using php. I'm using:

$con = mysql_connect("localhost","xxxxxxxxx","xxxxxxx")
or die ("didn't work");// this works ok, cuz I run by itself and get check message at end

mysql_select_db("fitforli_database",$con);//this also works ok

//below is what won't work, I've tried with and without the MySQL_query command. do I need to use quotation marks throughout?
mysql_query (INSERT INTO `fitforli_database`.`gym` (`id`, `fname`, `lname`, `address`, `city`, `state`, `phone`, `email`,
`gender`, `contact`, `contact#`, `relation`, `plan`)
VALUES (null, "test","test","test","test","test","test","test","test","test","test","test","test");
echo ("ok");
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
367
Points
83
Hi dianax8,

Your MySQL query needs to be wrapped in quotation marks, like this:
Code:
mysql_query('INSERT INTO `fitforli_database`.`gym` (`id`, `fname`, `lname`, `address`, `city`, `state`, `phone`, `email`, `gender`, `contact`, `contact`, `relation`, `plan`) VALUES(NULL, "test","test","test","test","test","test","test","test","test","test","test","test")');

I've moved this thread to the Programming forum. :)
 

ChatIndia

Community Advocate
Community Support
Messages
1,408
Reaction score
30
Points
48
first of all, don't use mysql_connect() because it's deprecated. Instead use Mysqli or PDO.
second of all, mysql_query takes a String as it's first parameter. so you need to wrap your query in quotation marks.
 
Top