Jump to content

Archived

This topic is now archived and is closed to further replies.

benjamin_boothe

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

Recommended Posts

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:

[img]http://localhost/policy_records.gif[/img]

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

If so, what can I do about that?

Share this post


Link to post
Share on other sites
[quote]If so, what can I do about that?[/quote]

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

Share this post


Link to post
Share on other sites
[code]
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')";
[/code]

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

[quote]
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, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
[/quote]

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

Share this post


Link to post
Share on other sites
Please post the code where you set your form variables, and your form code... ;)

Share this post


Link to post
Share on other sites
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'

Share this post


Link to post
Share on other sites
Could we inquire as to what was causing your issue, in case another forum member comes across a similar problem?

;)

Share this post


Link to post
Share on other sites
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:

[code]
$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'] : '';
[/code]

Beforehand I was declaring the variable like this:

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


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


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:

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

That was the issue all along!!

Share this post


Link to post
Share on other sites

×

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.