Richlather Posted October 18, 2009 Share Posted October 18, 2009 Hi- I am new with php and mysql and having a good bit of trouble setting up an email subscriber form on a website I maintain. The site is hosted with godaddy and, after 2 days on the phone with them I've come to the conclusion that while I'm not the brightest bulb on the tree, they really don't want to be of much help. I purchased a "website building for dummies" type book which contained the following code, meant by the author as a "works across the board" kind of document. Unfortunately, it doesn't work in this case. When I input information from the form I created it seems fine, but then when I check the database, a new record has been created but the fields are empty.The database is simple in that only three fields are required, the "ID", the subscriber's name, and the subscriber's email address. Can anyone tell he either a) what is wrong with the php document below or b) does anyone have a sample document that they know works with godaddy hosting that I might use? Thanks in advance. here's the code that doesn't properly: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php $Name=$_POST['Name']; $EMail=$_POST['EMail']; $connection=mysql_connect ("databaseaddress", "myusername", "mypassword") or die ('I cannot connect to the database.'); mysql_select_db ("mydatabase",$connection) or die( "Unable to select database"); $query = "INSERT INTO `mytable` (`ID`, `Name`, `EMail`) VALUES ('', '$Name', '$EMail')"; mysql_query($query); mysql_close(); ?> </body> </html> One last thing...when building the database I used the following field settings: ID: type-integer, legnth-4, collation-empty, attributes-unsigned, null-no, default-empty, extra-auto_increment, primary key Name: type-varchar, length-40, collation-UTF8_unicode_ci, attributes-empty, null-no, default-empty, extra-empty EMail: type-varchar, length-40, collation-UTF8_unicode_ci, attributes-empty, null-no, default-empty, extra-empty When I created the database I used the default setting for the database type (MyISAM). Thanks to anyone who can shed some light on this for me. Quote Link to comment https://forums.phpfreaks.com/topic/178124-php-and-mysql-fields-empty/ Share on other sites More sharing options...
mikesta707 Posted October 18, 2009 Share Posted October 18, 2009 it seems that your form fields are empty. verify that your HTML form has the correct names, and that its action is set to the right page. do you have the code for the html form? also put your code in code or php tags Quote Link to comment https://forums.phpfreaks.com/topic/178124-php-and-mysql-fields-empty/#findComment-939156 Share on other sites More sharing options...
cags Posted October 18, 2009 Share Posted October 18, 2009 Just as a side note to what mikesta707 said, the name of form fields are case sensitive. So if you have <!-- this on your form --> <input type="text" name="name" /> <?php // and this in your script $Name=$_POST['Name']; ?> .. $Name will be a blank variable because you are looking in the $_POST array for an item with the key of 'Name', when the value is stored with the key of 'name'. Quote Link to comment https://forums.phpfreaks.com/topic/178124-php-and-mysql-fields-empty/#findComment-939171 Share on other sites More sharing options...
Richlather Posted October 18, 2009 Author Share Posted October 18, 2009 Thanks very much. I did not know that it was case sensitive. I'll check that out and make sure that the action in the form is set to the correct page. Thanks so much for the input. It's GREATLY appreciated! Hopefully that will do the trick! Quote Link to comment https://forums.phpfreaks.com/topic/178124-php-and-mysql-fields-empty/#findComment-939175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.