Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Totally confused

    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...

    Code:
    //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?

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Try getting an mysql_error();

    with

    PHP Code:
    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(); 
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •