problems inserting to mysql

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
bobo12
Forum Newbie
Posts: 18
Joined: Sun Mar 04, 2007 3:48 pm

problems inserting to mysql

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
bobo12
Forum Newbie
Posts: 18
Joined: Sun Mar 04, 2007 3:48 pm

Post 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.
Post Reply