[PHP-DB] Undefined Index error when trying to insert data from a form into a db
Hello to all: I am getting the following error message when trying to insert data from an html form into a MYSQL database that I recently created. Can someone take a look at the errors and corresponding code and suggest some alternatives? Thank you very much in advance for your assistance. Regards, Chris McCourt Error Message: Notice: Undefined index: Store_ID in c:\program files\apache group\apache\htdocs\insertdata.php on line 9 Notice: Undefined index: Postal_Code in c:\program files\apache group\apache\htdocs\insertdata.php on line 14 Notice: Undefined index: Cert_Org in c:\program files\apache group\apache\htdocs\insertdata.php on line 17 Notice: Undefined index: Cert_Level_ID in c:\program files\apache group\apache\htdocs\insertdata.php on line 18 Notice: Undefined index: Cert_Date in c:\program files\apache group\apache\htdocs\insertdata.php on line 19 Notice: Undefined index: Emerg_Contact_Name in c:\program files\apache group\apache\htdocs\insertdata.php on line 20 Notice: Undefined index: Emerg_Contact_Phone in c:\program files\apache group\apache\htdocs\insertdata.php on line 21 Error: Unable to execute insertion query. +++ Original PHP Code: HTML HEAD TITLE Inserting Data Into a Database/TITLE BODY ?php /* This page receives and handles the data generated by the form Insert_Table_Form.html*/ $Store = ($_POST['Store_ID']); $Users = ($_POST['User_Name']); $Pass = ($_POST['Password']); $Addr = ($_POST['Address']); $State = ($_POST['State']); $Post = ($_POST['Postal_Code']); $Phone = ($_POST['Phone']); $Email = ($_POST['EMail']); $Certor = ($_POST['Cert_Org']); $Certl = ($_POST['Cert_Level_ID']); $Certd = ($_POST['Cert_Date']); $Emergn = ($_POST['Emerg_Contact_Name']); $Emergp = ($_POST['Emerg_Contact_Phone']); //Set the variables for the database access: $Host = localhost; $User = root; $Password = ; $Link = mysql_connect($Host, $User, $Password) or die(Could not connect: . mysql_error()); mysql_select_db('dive_store') or die(could not select database); $sql = mysql_query(INSERT INTO test_scores VALUES (NULL, '$Store', '$Users', '$Pass', '$Addr', '$State', '$Post', '$Phone', '$Email', '$Certor', '$Certd', '$Certl', '$Emergn', '$Emergp')) or die('Error: Unable to execute insertion query.'); $Result = mysql_query($sql)or die(mysql_error()); if ($Result){ echo(Table Created successfully); }else{ echo(error when creating table); } mysql_close($Link); ? /BODY /HEAD /HTML
[PHP-DB] Having trouble with this SQL query
Hi to all: First of all, I'm a newbie to PHP and MYSQL and started working on a create table query in PHP to execute on MYSQL. Can someone take a quick look at the following code to see if there are any problems? Can you also advise some tips on debugging? Thank you in advance for your assistance. Take care, Chris McCourt PHP code: HTML HEAD TITLECreating a Database/TITLE BODY ?php //Set the variables for the database access: $Host = localhost; $User = root; $Password = ; $Link = mysql_connect($Host, $User, $Password) or die(Could not connect: . mysql_error()); mysql_select_db(dive_store) or die(could not select database); //Execute query to create User table $sql =CREATE TABLE User( ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, Store_ID Smallint(3), User_Name VARCHAR(15), Password VARCHAR(15), Address VARCHAR(50), State_ID Smallint (3), Postal_Code VARCHAR(10), Phone VARCHAR(20), E_mail VARCHAR(30), Cert_Org VARCHAR(25), Cert_DATE DATE, Cert_Level_ID Smallint(3) UNSIGNED NOT NULL, Emergency_Contact_Name VARCHAR(30), Emergency_Contact_Phone VARCHAR(30)); //Run the above query $Result = mysql_query($sql); if ($Result){ echo(Table Created successfully); }else{ echo(error when creating table); } mysql_close($Link); ? /BODY /HEAD /HTML
RE: [PHP-DB] Having trouble with this SQL query
Thank you John. -Original Message- From: CPT John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Monday, June 23, 2003 12:10 PM To: Christopher McCourt; PHP Lists Subject: Re: [PHP-DB] Having trouble with this SQL query First of all, I'm a newbie to PHP and MYSQL and started working on a create table query in PHP to execute on MYSQL. Can someone take a quick look at the following code to see if there are any problems? Can you also advise some tips on debugging? Print out your SQL queries when debugging. Make sure they look correct. (Not an issue in your case, though, since you're not inserting any variables into the SQL.) Also, use mysql_error() in conjunction with mysql_query(). $rs = msyql_query($sql) or die(mysql_error()); or example. Wrapping your sql queries in a simple abstraction layer will make debugging easier, too. You could use a simple db_query($sql) function call and have error checking built into the function and handle all queries the same. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php