casino1234 Posted December 30, 2010 Share Posted December 30, 2010 <?php $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("contact", $con); $sql="INSERT INTO contact_info (FirstName, LastName, Phone, Email, ContactMethod, City, State, zip, TimeFrame, Agent, AgentInfo) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[phone]','$_POST[email]','$_POST[contactmethod]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[timeframe]','$_POST[agent]','$_POST[agentinfo]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> That's my code everything seem's to be working fine script runs and says 1 record added however when I go to view the entry phpMyAdmin the entry show's up without the data? Quote Link to comment Share on other sites More sharing options...
.josh Posted December 30, 2010 Share Posted December 30, 2010 do you see a new rows but no data for the cells? Or no rows at all? If it is empty rows, then check to make sure $_POST[...] has data... echo $sql out see what it shows the generated query string to be Quote Link to comment Share on other sites More sharing options...
casino1234 Posted December 30, 2010 Author Share Posted December 30, 2010 i see rows but no data Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2010 Share Posted December 30, 2010 Your POST values likely don't have values or were not even sent. Add the following to the bottom of that script to see what, if anything, was sent in the POST data echo "<pre>"; print_r($_POST); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
casino1234 Posted December 30, 2010 Author Share Posted December 30, 2010 Array ( [ctlSell$txtFirstName] => name [ctlSell$txtLastName] => name [ctlSell$txtPhone] => 1234567890 [ctlSell$txtEmail] => email@email.com [ctlSell$cboPreferredMethod] => Phone [ctlSell$txtCity] => City [ctlSell$txtState] => NY [ZipCode] => 12345 [ctlSell$cboTimeFrame] => 15 [ctlSell$rdoWorkingWithAgent] => 0 [ctlSell$txtAgentInformation] => [ctlSell$btnSubmit] => Submit ) thats the output so it say's data's going into the table but when I look at it... still nothing Quote Link to comment Share on other sites More sharing options...
.josh Posted December 30, 2010 Share Posted December 30, 2010 okay soo...compare those posted array elements with with you have in your $sql query string...does it look like they match up to you? Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted December 30, 2010 Share Posted December 30, 2010 maybe put ' ' around the $_POST elements $_POST['phone'] instead of $_POST[phone] et cetera Quote Link to comment Share on other sites More sharing options...
.josh Posted December 30, 2010 Share Posted December 30, 2010 maybe put ' ' around the $_POST elements $_POST['phone'] instead of $_POST[phone] et cetera That doesn't matter. Putting '' around them would help PHP parse the code faster, and it also ensures that you aren't accidentally using a constant instead of array element (php would try to parse it as a constant first, then an array element...if there happens to be a constant by the same name, it would attempt to find the array element of the constant's value). IOW it's good practice, but not strictly necessary. His problem that his form is not using the same element names as his array elements he's using in his db query. If you compare the $_POST dump to his variables in his db query, you can see that they aren't the same. Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted December 31, 2010 Share Posted December 31, 2010 I see, thanks for that extra bit of info on the parsing, never knew that, but glad i accidentally had a good practise Quote Link to comment Share on other sites More sharing options...
casino1234 Posted December 31, 2010 Author Share Posted December 31, 2010 Got it guys thanks can't believe I overlooked having different element names, I'm a beginner coder but should have payed more attention. Thank you again! Quote Link to comment 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.