mellis95 Posted January 27, 2009 Share Posted January 27, 2009 I am very new to PHP and MYSQL, and I am working on my first application. I did a quick forum search and couldn't find an answer for this... I have a form that uses the file insert.php to insert data into a table. Visually, the query seems to execute properly, but when I view the table, there are some 0's in some fields and others say NULL. Most are simply blank. So basically, it is creating empty new records. I have a different page in my app that updates a different table using the same query, where the only difference are the field names and it works fine. I can't figure out what is different. The non-working code: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("referrals", $con); $sql="INSERT INTO TBL_REFERRAL_INFO (physician, fname, lname, date, add1, add2, city, state, zip, phone, existingpatient, payor2, age_yr, age_mo, pt, ot, st,location, email, payor1) VALUES ('$_POST[physician]','$_POST[fname]','$_POST[lname]','$_POST[date]','$_POST[add1]','$_POST[add2]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[phone]','$_POST[existingpatient]','$_POST[payor2]','$_POST[age_yr]','$_POST[age_mo]','$_POST[pt]','$_POST[ot]','$_POST[st]','$_POST[location]','$_POST[email]','$_POST[payor1]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> <META HTTP-EQUIV="refresh" content="0;URL=http://pto/referrals/menu.php"> --------------------------------------------------------------------------------------------- The Working Code from the other page: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("referrals", $con); $sql="INSERT INTO TBL_PHYSICIAN (fname, lname, specialty, add1, add2, city, st, zip, phone, fax, email) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[specialty]','$_POST[add1]','$_POST[add2]','$_POST[city]','$_POST[st]','$_POST[zip]','$_POST[phone]','$_POST[fax]','$_POST[email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> <META HTTP-EQUIV="refresh" content="0;URL=http://pto/referrals/menu.php"> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/142574-solved-query-seems-to-work-but-data-does-not-make-it-into-the-table/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2009 Share Posted January 27, 2009 Your form fields probably don't have names that match the $_POST variable names the from processing code is using or your form is somehow not sending any post data and is only requesting the form processing page (there is no logic in the posted code that is even checking if a form's submit button has been clicked.) Have you checked your form? Quote Link to comment https://forums.phpfreaks.com/topic/142574-solved-query-seems-to-work-but-data-does-not-make-it-into-the-table/#findComment-747216 Share on other sites More sharing options...
mellis95 Posted January 27, 2009 Author Share Posted January 27, 2009 Well, don't I feel stupid..... For some reason I had the <form method="submit" ... instead of <form method="post" .... I knew it was going to be something simple. Thank you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/142574-solved-query-seems-to-work-but-data-does-not-make-it-into-the-table/#findComment-747534 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.