Jump to content


Photo

Database returning 'NULL' values when submitting data from form HELP!!


  • Please log in to reply
7 replies to this topic

#1 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 22 August 2006 - 11:01 PM

The form successfully adds a record to the database.

BUT.... it doesn't add what I put in the form, instead it adds 'NULL' to all of fields.

So it looks like this:

Posted Image

Is it beacuse the default value is NULL on all fields barring the id?

If so, what can I do about that?

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 August 2006 - 11:04 PM

If so, what can I do about that?


Fix your code.  Or post the offending part, and maybe we can help.

#3 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 22 August 2006 - 11:15 PM

if ($msg=="") {
    $insert = "INSERT INTO policy_holder
    ( id, title, first_name, surname, date_of_birth, uk_residency, marital_status,
    disability, employment_status, address_line_1, area, town, county, post_code,
    telephone_work, telephone_home, fax_number, email)
    VALUES ( NULL, '$t', '$fn', '$sn', '$dob', '$uk', '$ms', '$d', '$es', '$ad1', '$a',
    '$tn', '$c', '$pc', '$tw', '$th', '$fax', '$em')";

That is the query I am running.  I echoed it to see what it is doing:

INSERT INTO policy_holder ( id, title, first_name, surname, date_of_birth, uk_residency, marital_status, disability, employment_status, address_line_1, area, town, county, post_code, telephone_work, telephone_home, fax_number, email) VALUES ( NULL, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')


It's not returning the values in the db that I am putting into my form.

#4 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 22 August 2006 - 11:16 PM

Please post the code where you set your form variables, and your form code... ;)

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 August 2006 - 11:16 PM

If that is the insert query, then you aren't inserting anything into the database.....

#6 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 22 August 2006 - 11:51 PM

Thanks a lot HeyRay2.

I've been stressing like a muthafucka over dat shit!!

It was staring at me right in the face.  Lack of sleep!!!

Dis PHP shit has become an addiction man!!!

I can't thank you enough bro'

#7 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 22 August 2006 - 11:53 PM

Could we inquire as to what was causing your issue, in case another forum member comes across a similar problem?

;)

#8 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 23 August 2006 - 03:27 AM

Because the globals are off I had to use this piece of code.  This was because at first, I was getting 'Notice: Undefined' messages.  So I had to declare all of my variables like this:

$t = isSet($_POST['title']) ? $_POST['title'] : '';
$fn = isSet($_POST['first_name']) ? $_POST['first_name'] : '';
$sn = isSet($_POST['surname']) ? $_POST['surname'] : '';
$dob = isSet($_POST['date_of_birth']) ? $_POST['date_of_birth'] : '';
$uk = isSet($_POST['uk_residency']) ? $_POST['uk_residency'] : '';
$ms = isSet($_POST['marital_status']) ? $_POST['marital_status'] : '';
$d = isSet($_POST['disability']) ? $_POST['disability'] : '';
$es = isSet($_POST['employment_status']) ? $_POST['employment_status'] : '';
$ad1 = isSet($_POST['address_line_1']) ? $_POST['address_line_1'] : '';
$a = isSet($_POST['area']) ? $_POST['area'] : '';
$tn = isSet($_POST['town']) ? $_POST['town'] : '';
$c = isSet($_POST['county']) ? $_POST['county'] : '';
$pc = isSet($_POST['post_code']) ? $_POST['post_code'] : '';
$tw = isSet($_POST['telephone_work']) ? $_POST['telephone_work'] : '';
$th = isSet($_POST['telephone_home']) ? $_POST['telephone_home'] : '';
$fax = isSet($_POST['fax_number']) ? $_POST['fax_number'] : '';
$em = isSet($_POST['email']) ? $_POST['email'] : '';

Beforehand I was declaring the variable like this:

For example, if wanted to declare the 'fax_number' form variable, I was doing this:


$fax = isSet($_POST['fax']) ? $_POST['fax'] : '';


Which was why it was not reading the values that I was inputting, as I was not making the field names (form inputs) equal to the variables like this:

$fax = isSet($_POST['fax_number']) ? $_POST['fax_number'] : '';

That was the issue all along!!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users