Page 1 of 1

problems inserting to mysql

Posted: Mon Mar 05, 2007 1:58 pm
by bobo12
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Well, the problem I posted before is fixed and I am able to create and add tables to databases.  The problem occurs when I submit a form from an html file and try to insert data:

Code: Select all

<?php	
	$connection = mysql_connection("localhost","root","password");
	if ($connection)
	{
		mysql_select_db("gb_db",$connection);
		$query = "INSERT INTO gb_table (NAME,EMAIL,COMMENT)
			  VALUES('$_POST[user_name]','$_POST[user_email]', '$_POST[user_comment]')";
		if (mysql_query($query,$connection))
		{
			echo "Comment added succesfully";
		}
		else
		{
			echo "Error: " + mysql_error();
		}
	}
	else
	{
		die('Error: ' . mysql_error());
	}
	mysql_close($connection);
?>
Nothing gets posted... no error message or anything!!! When I query the database it's like nothing has happened, because no information exists. I am calling this from an html form:

Code: Select all

<form action="insert_comment.php" method="post">
Is this another problem of my not setting something up correctly? I've tried changing a little bit of the syntax but it's not working and nothing shows up under viewsource.

Using php5, apache 2.2, and latest version of mysql.

Thanks.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Mar 05, 2007 5:31 pm
by volka
If this is your development server open your php.ini in a text editor and search and set the following parameters
  • error_reporting = E_ALL
  • display_errors = On
  • display_startup_errors = On
  • mysql.trace_mode = On
All those parameters should already be in your php.ini, just set the values. Then save the file and restart the webserver. Call

Code: Select all

<?php phpinfo(); ?>
and check wether the output reflects the changes you've made.

Posted: Tue Mar 06, 2007 7:39 am
by bobo12
Thanks. I made another stupid mistake:

Code: Select all

mysql_connection("localhost","root","password");
It should be mysql_connect(). I wish I had caught the error earlier, because I uninstalled everything and went with xampp, which is pretty nice.