Jump to content

Trying to add data to a MySQL table


mikhl

Recommended Posts

I have a script that is supposed to allow a user to add their details to a members table in the database.

 

It acts as if the user has been added to the database by stating the thank you message, but there is no entry into the database.

 

I can connect to the database and have another script running OK that allows me to view all of the information in the members table with a loop (this data was entered using php my admin's GUI).

 

Here is the script that is supposed to add the member.

 

Any help would be greatly appreciated.

 

<?php

error_reporting(-1);

$user_name = "root";
$password = "";
$database = "test";
$server = "localhost";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found)
{
	$SQL = "INSERT INTO members (fname, sname, email, password, gender) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[password]','$_POST[gender]')";
	$result = mysql_query($SQL);

	mysql_close($db_handle);

	print "Thanks for joining us ".$_POST['fname'].".";
}
else
{
	print "Database NOT Found";
	mysql_close($db_handle);
}

?>

Link to comment
https://forums.phpfreaks.com/topic/221387-trying-to-add-data-to-a-mysql-table/
Share on other sites

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.