0

Hey there,

I am trying to build a small survey for a homework assignment.
So, I have the following code:

$con = mysql_connect("localhost","user", "mypassword");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}
	
	
	mysql_select_db("mydatabase", $con);

	$slq = "INSERT INTO results VALUES('', '', '', '', '', '', '', '', '', '', '', '')";
	mysql_query($sql, $con);
	
	
	mysql_close($con);

What is even more weird is that I use this same sql statement through command line, as well as through phpMyAdmin, and it inserts a row in my results table in both cases, but it won't insert a row when I use it in a script.

Anyone knows what might I be doing wrong?

thank you.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by bibiki
0

Change line 12 with mysql_query($sql, $con) or die(mysql_error()); and see what it happens, bye.

0

cereal,
I tried that but nothing happened. no error reporting, no row insertion. However, after rewriting my sql statement to include column names as:

INSERT INTO results (column name) VALUES ('val', 'val', 'val'....);

everything went fine. I guess I will mark this thread solved now.

thank you very much.
perhaps I have error reporting turned to off in my server or something.

0

BTW you can use the SET syntax as well:

INSERT INTO table SET field1='val1',field2='val2',field3='val3'

However this will only allow you to insert a single record at a time, the VALUES syntax allows insertion of many records in one query. I find the SET syntax easier to keep an eye on. The VALUES syntax can be tricky, especially if you include the autoincrement field in the query. My 2p

0

yes ardav,
I use
UPDATE tableName SET columnName = 'someValue'
for questions number 2 and above, but I use an INSERT statement to insert a row with null values for all columns, except the first, auto incremental one.

thank you for your two cents :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.