Jump to content

[SOLVED] Query seems to work, but data does not make it into the table


mellis95

Recommended Posts

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.

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?

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.