...

View Full Version : Totally confused



kdalts
04-25-2012, 02:20 PM
Hi Guys..

I have developed some scripts using php/mysql locally and they work fine. I can add, delete, view and edit records perfectly. There are 3 of these files and they all work the same. The add function looks like this...



//now perform the add routine
function add2SQL() {

//additional var to save not already posted from the form
$change_requestor=$_SESSION['fullname'];//default user
$change_status= "New Request";/default status
$today = date("d-m-y");//default entry date

include '../config.php'; //connect to the database

//8 fields and 8 values
mysql_query("INSERT INTO change_log (request_date, change_headline, change_description, change_reason, change_priority, change_requestor, change_type, change_status) " .
"VALUES ('$today', '$_POST[change_headline]', '$_POST[change_description]', ".
"'$_POST[change_reason]', '$_POST[change_priority]', '$change_requestor', ".
"'$_POST[change_type]', '$change_status')");

}



The 3 scripts are identical except for the database table name and, of course, the fields.

So I have publised this now to my server and for some reason 1 script works and 2 do not. The 2 that do not work give back no error message (error_reporting = E_ALL & ~E_NOTICE) - the data simply does not add to the DB. The list, update and delete works on all scripts so I know that the databases work fine. I've echo'd the values back and they are all correct too - session vars are present but the record simply won't add to my tables.

I've been on this now for 2 days and I simply can't figure out what's wrong. Any one spot anything obvious or know of a way I can trace what's happening please?

timgolding
04-25-2012, 02:46 PM
Try getting an mysql_error();

with



if(!mysql_query("INSERT INTO change_log (request_date, change_headline, change_description, change_reason, change_priority, change_requestor, change_type, change_status) " .
"VALUES ('$today', '$_POST[change_headline]', '$_POST[change_description]', ".
"'$_POST[change_reason]', '$_POST[change_priority]', '$change_requestor', ".
"'$_POST[change_type]', '$change_status')")
echo mysql_error();

kdalts
04-25-2012, 05:16 PM
Hmmm,,,,

Great advise, not sure why I didn't think of that - lol

Anyhow, looks like my table on the server will not accept empty feilds for a new record. Error message says
'Field 'change_date' doesn't have a default value'

Weird that it accepts empty feilds for UPDATE? Also, same table locally and that also accepts empty fields. I was under the impression that if specified the column names in the same order os the values you did not need to specify a value for feilds that can be left empty?

timgolding
04-26-2012, 09:17 AM
http://bugs.mysql.com/bug.php?id=14306



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum