www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Can't find my stupid mistake!

  1. #1
    Join Date
    Oct 2012
    Posts
    24

    Can't find my stupid mistake!

    Hi all,
    I'm trying to create a form that will insert into a mysql database.
    The code for the php file is below:

    PHP Code:
    <?

    //set database connection parameters
    $hostname "127.0.0.1:3307"// database server name
    $db_user "testuser"// change to your database password 
    $db_password "testpass"// change to your database password 
    $database "testdb"// provide your database name 
    $db_table "form1"// leave this as is 


    //database connection
    $db mysql_connect($hostname$db_user$db_password); 
    mysql_select_db($database,$db);

    //Prepare prerequisites
            
    $created time();
            
    $ip $_SERVER['REMOTE_ADDR'];
            
    $_POST array_map('mysql_real_escape_string',$_POST);

    if(isset(
    $_REQUEST['submit']))
    {
    //inserting data order
    $sql "INSERT INTO $db_table(EmployeeName,EmployeeRef,WeeksPerYear,MonTownFrom,MonPostcodeFrom,MonTownTo,MonPostcodeTo,MonMiles,TueTownFrom,TuePostcodeFrom,TueTownTo,TuePostcodeTo,TueMiles,WedTownFrom,WedPostcodeFrom,WedTownTo,WedPostcodeTo,WedMiles,ThuTownFrom,ThuPostcodeFrom,ThuTownTo,ThuPostcodeTo,ThuMiles,FriTownFrom,FriPostcodeFrom,FriTownTo,FriPostcodeTo,FriMiles,SatTownFrom,SatPostcodeFrom,SatTownTo,SatPostcodeTo,SatMiles,SunTownFrom,SunPostcodeFrom,SunTownTo,SunPostcodeTo,SunMiles,SumMiles,MonCheck,TueCheck,WedCheck,ThuCheck,FriCheck,SatCheck,SunCheck,MonHours,TueHours,WedHours,ThuHours,FriHours,SatHours,SunHours,SumHours,MonTravel,TueTravel,WedTravel,ThuTravel,FriTravel,SatTravel,SunTravel,MonMealCheck,TueMealCheck,WedMealCheck,ThuMealCheck,FriMealCheck,SatMealCheck,SunMealCheck,MonEveningMealCheck,TueEveningMealCheck,WedEveningMealCheck,ThuEveningMealCheck,FriEveningMealCheck,SatEveningMealCheck,SunEveningMealCheck,MonOvernightCheck,TueOvernightCheck,WedOvernightCheck,ThuOvernightCheck,FriOvernightCheck,SatOvernightCheck,SunOvernightCheck,DeclarationCheck,ip,created) 
                VALUES ('
    $_POST['EmployeeName']','$_POST['EmployeeRef']','$_POST['WeeksPerYear']','$_POST['MonTownFrom']','$_POST['MonPostcodeFrom']','$_POST['MonTownTo']','$_POST['MonPostcodeTo']','$_POST['MonMiles']','$_POST['TueTownFrom']','$_POST['TuePostcodeFrom']','$_POST['TueTownTo']','$_POST['TuePostcodeTo']','$_POST['TueMiles']','$_POST['WedTownFrom']','$_POST['WedPostcodeFrom']','$_POST['WedTownTo']','$_POST['WedPostcodeTo']','$_POST['WedMiles']','$_POST['ThuTownFrom']','$_POST['ThuPostcodeFrom']','$_POST['ThuTownTo']','$_POST['ThuPostcodeTo']','$_POST['ThuMiles']','$_POST['FriTownFrom']','$_POST['FriPostcodeFrom']','$_POST['FriTownTo']','$_POST['FriPostcodeTo']','$_POST['FriMiles']','$_POST['SatTownFrom']','$_POST['SatPostcodeFrom']','$_POST['SatTownTo']','$_POST['SatPostcodeTo']','$_POST['SatMiles']','$_POST['SunTownFrom']','$_POST['SunPostcodeFrom']','$_POST['SunTownTo']','$_POST['SunPostcodeTo']','$_POST['SunMiles']','$_POST['SumMiles']','$_POST['MonCheck']','$_POST['TueCheck']','$_POST['WedCheck']','$_POST['ThuCheck']','$_POST['FriCheck']','$_POST['SatCheck']','$_POST['SunCheck']','$_POST['MonHours']','$_POST['TueHours']','$_POST['WedHours']','$_POST['ThuHours']','$_POST['FriHours']','$_POST['SatHours']','$_POST['SunHours']','$_POST['SumHours']','$_POST['MonTravel']','$_POST['TueTravel']','$_POST['WedTravel']','$_POST['ThuTravel']','$_POST['FriTravel']','$_POST['SatTravel']','$_POST['SunTravel']','$_POST['MonMealCheck']','$_POST['TueMealCheck']','$_POST['WedMealCheck']','$_POST['ThuMealCheck']','$_POST['FriMealCheck']','$_POST['SatMealCheck']','$_POST['SunMealCheck']','$_POST['MonEveningMealCheck']','$_POST['TueEveningMealCheck']','$_POST['WedEveningMealCheck']','$_POST['ThuEveningMealCheck']','$_POST['FriEveningMealCheck']','$_POST['SatEveningMealCheck']','$_POST['SunEveningMealCheck']','$_POST['MonOvernightCheck']','$_POST['TueOvernightCheck']','$_POST['WedOvernightCheck']','$_POST['ThuOvernightCheck']','$_POST['FriOvernightCheck']','$_POST['SatOvernightCheck']','$_POST['SunOvernightCheck']','$_POST['DeclarationCheck']','$_POST['ip']','$_POST['created']')";


    //declare in the order variable
    if($result mysql_query($sql ,$db))
    {
        echo = 
    "<br>Your Mileage form has been submitted successfully";

    else{
        echo = 
    "<br>Your Mileage form has not been submitted successfully. Please correct any errors and try again."
        "ERROR: "
    .mysql_error();
    }
    }
    ?>
    My problem is:
    When I click submit on the form, the only thing I get is:

    Your Mileage form has been submitted successfully"; } else{ echo = "
    Your Mileage form has not been submitted successfully. Please correct any errors and try again." "ERROR: ".mysql_error(); } } ?>
    Obviously my syntax is wrong somewhere, but I simply can't find where!
    I've tried everything and pulling my hair out is next.

    I'd appreciate someone giving me a hand with this!

    Thanks

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    You're trying to embed variables (namely post) into a string, but when you do this quotes around the array index are NOT correct.

    Note you should NEVER place external data directly into a SQL query like that, else you will be open to SQL Injection

    Also note, the entire mysql_* library is out of date and to be deprecated. You shjould instead use PDO or mysqli. See API choosing for more information.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    For my personal tastes, I'll leave the quotes in there around the array indexes just to be consistent throughout the app. To do that, however, you either have to use "complex" variable notation (wrapping the entire array variable in curly braces) or use concatenation -- or use sprintf() and add the variables as the additional arguments.

    PHP Code:
    // both (ugh!) complex notation and concatenation:
    $sql "test {$_GET['foo']} test " $_GET['bar'] . " test";

    // or use sprintf with place-holders:
    $sql sprintf(
        
    "test %s test %s test",
        
    mysql_real_escape_string($_GET['foo']),
        
    mysql_real_escape_string($_GET['bar'])
    ); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Oct 2012
    Posts
    24
    Thanks guys.
    I've taken your advice and used mysqli instead of the (previously unbeknownst to me) depreciated mysql_connect() method.

    Below is my new code.
    Is this any good?
    (splitting it into two posts because the forum doesn't like the length)

    PHP Code:
    <?

    //set database connection parameters
    $hostname "127.0.0.1:3307"// usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost 
    $db_user "testuser"// change to your database username
    $db_password "testpw"// change to your database password 
    $database "testdb"// provide your database name 
    $db_table "form1"// leave this as is 


    //database connection
    $db = new mysqli($hostname$db_user$db_password$database);
    if(
    $db->connect_errno 0)
         {
        die(
    'Unable to connect to database [' $db->connect_error ']');
          }
        
    mysqli_report(MYSQLI_REPORT_ERROR);

    //Prepare prerequisites
            
    $created time();
            
    $ip $_SERVER['REMOTE_ADDR'];
            
    $_POST array_map('mysql_real_escape_string',$_POST);

    if(isset(
    $_POST['submit']))
        {

    //get the form data
       
    $EmployeeName        htmlentities($_POST['EmployeeName'],        ENT_QUOTES);
       
    $EmployeeRef         htmlentities($_POST['EmployeeRef'],         ENT_QUOTES);
       
    $WeeksPerYear        htmlentities($_POST['WeeksPerYear'],        ENT_QUOTES);
       
    $MonTownFrom         htmlentities($_POST['MonTownFrom'],         ENT_QUOTES);
       
    $MonPostcodeFrom     htmlentities($_POST['MonPostcodeFrom'],     ENT_QUOTES);
       
    $MonTownTo           htmlentities($_POST['MonTownTo'],           ENT_QUOTES);
       
    $MonPostcodeTo       htmlentities($_POST['MonPostcodeTo'],       ENT_QUOTES);
       
    $MonMiles            htmlentities($_POST['MonMiles'],            ENT_QUOTES);
       
    $TueTownFrom         htmlentities($_POST['TueTownFrom'],         ENT_QUOTES);
       
    $TuePostcodeFrom     htmlentities($_POST['TuePostcodeFrom'],     ENT_QUOTES);
       
    $TueTownTo           htmlentities($_POST['TueTownTo'],           ENT_QUOTES);
       
    $TuePostcodeTo       htmlentities($_POST['TuePostcodeTo'],       ENT_QUOTES);
       
    $TueMiles            htmlentities($_POST['TueMiles'],            ENT_QUOTES);
       
    $WedTownFrom         htmlentities($_POST['WedTownFrom'],         ENT_QUOTES);
       
    $WedPostcodeFrom     htmlentities($_POST['WedPostcodeFrom'],     ENT_QUOTES);
       
    $WedTownTo           htmlentities($_POST['WedTownTo'],           ENT_QUOTES);
       
    $WedPostcodeTo       htmlentities($_POST['WedPostcodeTo'],       ENT_QUOTES);
       
    $WedMiles            htmlentities($_POST['WedMiles'],            ENT_QUOTES);
       
    $ThuTownFrom         htmlentities($_POST['ThuTownFrom'],         ENT_QUOTES);
       
    $ThuPostcodeFrom     htmlentities($_POST['ThuPostcodeFrom'],     ENT_QUOTES);
       
    $ThuTownTo           htmlentities($_POST['ThuTownTo'],           ENT_QUOTES);
       
    $ThuPostcodeTo       htmlentities($_POST['ThuPostcodeTo'],       ENT_QUOTES);
       
    $ThuMiles            htmlentities($_POST['ThuMiles'],            ENT_QUOTES);
       
    $FriTownFrom         htmlentities($_POST['FriTownFrom'],         ENT_QUOTES);
       
    $FriPostcodeFrom     htmlentities($_POST['FriPostcodeFrom'],     ENT_QUOTES);
       
    $FriTownTo           htmlentities($_POST['FriTownTo'],           ENT_QUOTES);
       
    $FriPostcodeTo       htmlentities($_POST['FriPostcodeTo'],       ENT_QUOTES);
       
    $FriMiles            htmlentities($_POST['FriMiles'],            ENT_QUOTES);
       
    $SatTownFrom         htmlentities($_POST['SatTownFrom'],         ENT_QUOTES);
       
    $SatPostcodeFrom     htmlentities($_POST['SatPostcodeFrom'],     ENT_QUOTES);
       
    $SatTownTo           htmlentities($_POST['SatTownTo'],           ENT_QUOTES);
       
    $SatPostcodeTo       htmlentities($_POST['SatPostcodeTo'],       ENT_QUOTES);
       
    $SatMiles            htmlentities($_POST['SatMiles'],            ENT_QUOTES);
       
    $SunTownFrom         htmlentities($_POST['SunTownFrom'],         ENT_QUOTES);
       
    $SunPostcodeFrom     htmlentities($_POST['SunPostcodeFrom'],     ENT_QUOTES);
       
    $SunTownTo           htmlentities($_POST['SunTownTo'],           ENT_QUOTES);
       
    $SunPostcodeTo       htmlentities($_POST['SunPostcodeTo'],       ENT_QUOTES);
       
    $SunMiles            htmlentities($_POST['SunMiles'],            ENT_QUOTES);
       
    $SumMiles            htmlentities($_POST['SumMiles'],            ENT_QUOTES);
       
    $MonCheck            htmlentities($_POST['MonCheck'],            ENT_QUOTES);
       
    $TueCheck            htmlentities($_POST['TueCheck'],            ENT_QUOTES);
       
    $WedCheck            htmlentities($_POST['WedCheck'],            ENT_QUOTES);
       
    $ThuCheck            htmlentities($_POST['ThuCheck'],            ENT_QUOTES);
       
    $FriCheck            htmlentities($_POST['FriCheck'],            ENT_QUOTES);
       
    $SatCheck            htmlentities($_POST['SatCheck'],            ENT_QUOTES);
       
    $SunCheck            htmlentities($_POST['SunCheck'],            ENT_QUOTES);
       
    $MonHours            htmlentities($_POST['MonHours'],            ENT_QUOTES);
       
    $TueHours            htmlentities($_POST['TueHours'],            ENT_QUOTES);
       
    $WedHours            htmlentities($_POST['WedHours'],            ENT_QUOTES);
       
    $ThuHours            htmlentities($_POST['ThuHours'],            ENT_QUOTES);
       
    $FriHours            htmlentities($_POST['FriHours'],            ENT_QUOTES);
       
    $SatHours            htmlentities($_POST['SatHours'],            ENT_QUOTES);
       
    $SunHours            htmlentities($_POST['SunHours'],            ENT_QUOTES);
       
    $SumHours            htmlentities($_POST['SumHours'],            ENT_QUOTES);
       
    $MonTravel           htmlentities($_POST['MonTravel'],           ENT_QUOTES);
       
    $TueTravel           htmlentities($_POST['TueTravel'],           ENT_QUOTES);
       
    $WedTravel           htmlentities($_POST['WedTravel'],           ENT_QUOTES);
       
    $ThuTravel           htmlentities($_POST['ThuTravel'],           ENT_QUOTES);
       
    $FriTravel           htmlentities($_POST['FriTravel'],           ENT_QUOTES);
       
    $SatTravel           htmlentities($_POST['SatTravel'],           ENT_QUOTES);
       
    $SunTravel           htmlentities($_POST['SunTravel'],           ENT_QUOTES);
       
    $MonMealCheck        htmlentities($_POST['MonMealCheck'],        ENT_QUOTES);
       
    $TueMealCheck        htmlentities($_POST['TueMealCheck'],        ENT_QUOTES);
       
    $WedMealCheck        htmlentities($_POST['WedMealCheck'],        ENT_QUOTES);
       
    $ThuMealCheck        htmlentities($_POST['ThuMealCheck'],        ENT_QUOTES);
       
    $FriMealCheck        htmlentities($_POST['FriMealCheck'],        ENT_QUOTES);
       
    $SatMealCheck        htmlentities($_POST['SatMealCheck'],        ENT_QUOTES);
       
    $SunMealCheck        htmlentities($_POST['SunMealCheck'],        ENT_QUOTES);
       
    $MonEveningMealCheck htmlentities($_POST['MonEveningMealCheck'], ENT_QUOTES);
       
    $TueEveningMealCheck htmlentities($_POST['TueEveningMealCheck'], ENT_QUOTES);
       
    $WedEveningMealCheck htmlentities($_POST['WedEveningMealCheck'], ENT_QUOTES);
       
    $ThuEveningMealCheck htmlentities($_POST['ThuEveningMealCheck'], ENT_QUOTES);
       
    $FriEveningMealCheck htmlentities($_POST['FriEveningMealCheck'], ENT_QUOTES);
       
    $SatEveningMealCheck htmlentities($_POST['SatEveningMealCheck'], ENT_QUOTES);
       
    $SunEveningMealCheck htmlentities($_POST['SunEveningMealCheck'], ENT_QUOTES);
       
    $MonOvernightCheck   htmlentities($_POST['MonOvernightCheck'],   ENT_QUOTES);
       
    $TueOvernightCheck   htmlentities($_POST['TueOvernightCheck'],   ENT_QUOTES);
       
    $WedOvernightCheck   htmlentities($_POST['WedOvernightCheck'],   ENT_QUOTES);
       
    $ThuOvernightCheck   htmlentities($_POST['ThuOvernightCheck'],   ENT_QUOTES);
       
    $FriOvernightCheck   htmlentities($_POST['FriOvernightCheck'],   ENT_QUOTES);
       
    $SatOvernightCheck   htmlentities($_POST['SatOvernightCheck'],   ENT_QUOTES);
       
    $SunOvernightCheck   htmlentities($_POST['SunOvernightCheck'],   ENT_QUOTES);
       
    $DeclarationCheck    htmlentities($_POST['DeclarationCheck'],    ENT_QUOTES);
       
    $ip                  htmlentities($_POST['ip'],                  ENT_QUOTES);
       
    $created             htmlentities($_POST['created'],             ENT_QUOTES);
    Last edited by Lazarix; 11-26-2012 at 07:18 PM.

  5. #5
    Join Date
    Oct 2012
    Posts
    24
    part 2:

    PHP Code:
    //check that the required fields are not empty
    if ($EmployeeName == '' || $EmployeeRef == '' || $DeclarationCheck == '')
            {
    $error 'ERROR: Please fill in all required fields!';
    renderForm($EmployeeName$EmployeeRef$DeclarationCheck$error);
            }
    else
            {
        
    //Insert the new record
        
    if ($stmt $mysqli->prepare("INSERT mileageform (EmployeeName,EmployeeRef,WeeksPerYear,MonTownFrom,MonPostcodeFrom,MonTownTo,MonPostcodeTo,MonMiles,TueTownFrom,TuePostcodeFrom,TueTownTo,TuePostcodeTo,TueMiles,WedTownFrom,WedPostcodeFrom,WedTownTo,WedPostcodeTo,WedMiles,ThuTownFrom,ThuPostcodeFrom,ThuTownTo,ThuPostcodeTo,ThuMiles,FriTownFrom,FriPostcodeFrom,FriTownTo,FriPostcodeTo,FriMiles,SatTownFrom,SatPostcodeFrom,SatTownTo,SatPostcodeTo,SatMiles,SunTownFrom,SunPostcodeFrom,SunTownTo,SunPostcodeTo,SunMiles,SumMiles,MonCheck,TueCheck,WedCheck,ThuCheck,FriCheck,SatCheck,SunCheck,MonHours,TueHours,WedHours,ThuHours,FriHours,SatHours,SunHours,SumHours,MonTravel,TueTravel,WedTravel,ThuTravel,FriTravel,SatTravel,SunTravel,MonMealCheck,TueMealCheck,WedMealCheck,ThuMealCheck,FriMealCheck,SatMealCheck,SunMealCheck,MonEveningMealCheck,TueEveningMealCheck,WedEveningMealCheck,ThuEveningMealCheck,FriEveningMealCheck,SatEveningMealCheck,SunEveningMealCheck,MonOvernightCheck,TueOvernightCheck,WedOvernightCheck,ThuOvernightCheck,FriOvernightCheck,SatOvernightCheck,SunOvernightCheck,DeclarationCheck,ip,created)
         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    ))
                {
                
    $stmt->bind_param("ss"$EmployeeName$EmployeeRef$WeeksPerYear$MonTownFrom$MonPostcodeFrom$MonTownTo$MonPostcodeTo$MonMiles$TueTownFrom$TuePostcodeFrom$TueTownTo$TuePostcodeTo$TueMiles$WedTownFrom$WedPostcodeFrom$WedTownTo$WedPostcodeTo$WedMiles$ThuTownFrom$ThuPostcodeFrom$ThuTownTo$ThuPostcodeTo$ThuMiles$FriTownFrom$FriPostcodeFrom$FriTownTo$FriPostcodeTo$FriMiles$SatTownFrom$SatPostcodeFrom$SatTownTo$SatPostcodeTo$SatMiles$SunTownFrom$SunPostcodeFrom$SunTownTo$SunPostcodeTo$SunMiles$SumMiles$MonCheck$TueCheck$WedCheck$ThuCheck$FriCheck$SatCheck$SunCheck$MonHours$TueHours$WedHours$ThuHours$FriHours$SatHours$SunHours$SumHours$MonTravel$TueTravel$WedTravel$ThuTravel$FriTravel$SatTravel$SunTravel$MonMealCheck$TueMealCheck$WedMealCheck$ThuMealCheck$FriMealCheck$SatMealCheck$SunMealCheck$MonEveningMealCheck$TueEveningMealCheck$WedEveningMealCheck$ThuEveningMealCheck$FriEveningMealCheck$SatEveningMealCheck$SunEveningMealCheck$MonOvernightCheck$TueOvernightCheck$WedOvernightCheck$ThuOvernightCheck$FriOvernightCheck$SatOvernightCheck$SunOvernightCheck$DeclarationCheck$ip$created);
                
    $stmt->execute();
                
    $stmt->close();
                }
            
    // show an error if the query has an error
            
    else
                {
                echo 
    "ERROR: Could not prepare SQL statement. Your Mileage form has not been submitted successfully.";
                }
            }
        }
        else
        {
            
    renderForm();
        }

    //declare in the order variable
    $mysqli->close();

    ?> 

  6. #6
    Join Date
    Oct 2012
    Posts
    24
    Well,
    clearly i'm doing something wrong because when I press submit, i get the following as the result:

    connect_errno > 0) { die('Unable to connect to database [' . $db->connect_error . ']'); } mysqli_report(MYSQLI_REPORT_ERROR); //Prepare prerequisites $created = time(); $ip = $_SERVER['REMOTE_ADDR']; $_POST = array_map('mysql_real_escape_string',$_POST); if(isset($_POST['submit'])) { //get the form data $EmployeeName = htmlentities($_POST['EmployeeName'], ENT_QUOTES); $EmployeeRef = htmlentities($_POST['EmployeeRef'], ENT_QUOTES); $WeeksPerYear = htmlentities($_POST['WeeksPerYear'], ENT_QUOTES); $MonTownFrom = htmlentities($_POST['MonTownFrom'], ENT_QUOTES); $MonPostcodeFrom = htmlentities($_POST['MonPostcodeFrom'], ENT_QUOTES); $MonTownTo = htmlentities($_POST['MonTownTo'], ENT_QUOTES); $MonPostcodeTo = htmlentities($_POST['MonPostcodeTo'], ENT_QUOTES); $MonMiles = htmlentities($_POST['MonMiles'], ENT_QUOTES); $TueTownFrom = htmlentities($_POST['TueTownFrom'], ENT_QUOTES); $TuePostcodeFrom = htmlentities($_POST['TuePostcodeFrom'], ENT_QUOTES); $TueTownTo = htmlentities($_POST['TueTownTo'], ENT_QUOTES); $TuePostcodeTo = htmlentities($_POST['TuePostcodeTo'], ENT_QUOTES); $TueMiles = htmlentities($_POST['TueMiles'], ENT_QUOTES); $WedTownFrom = htmlentities($_POST['WedTownFrom'], ENT_QUOTES); $WedPostcodeFrom = htmlentities($_POST['WedPostcodeFrom'], ENT_QUOTES); $WedTownTo = htmlentities($_POST['WedTownTo'], ENT_QUOTES); $WedPostcodeTo = htmlentities($_POST['WedPostcodeTo'], ENT_QUOTES); $WedMiles = htmlentities($_POST['WedMiles'], ENT_QUOTES); $ThuTownFrom = htmlentities($_POST['ThuTownFrom'], ENT_QUOTES); $ThuPostcodeFrom = htmlentities($_POST['ThuPostcodeFrom'], ENT_QUOTES); $ThuTownTo = htmlentities($_POST['ThuTownTo'], ENT_QUOTES); $ThuPostcodeTo = htmlentities($_POST['ThuPostcodeTo'], ENT_QUOTES); $ThuMiles = htmlentities($_POST['ThuMiles'], ENT_QUOTES); $FriTownFrom = htmlentities($_POST['FriTownFrom'], ENT_QUOTES); $FriPostcodeFrom = htmlentities($_POST['FriPostcodeFrom'], ENT_QUOTES); $FriTownTo = htmlentities($_POST['FriTownTo'], ENT_QUOTES); $FriPostcodeTo = htmlentities($_POST['FriPostcodeTo'], ENT_QUOTES); $FriMiles = htmlentities($_POST['FriMiles'], ENT_QUOTES); $SatTownFrom = htmlentities($_POST['SatTownFrom'], ENT_QUOTES); $SatPostcodeFrom = htmlentities($_POST['SatPostcodeFrom'], ENT_QUOTES); $SatTownTo = htmlentities($_POST['SatTownTo'], ENT_QUOTES); $SatPostcodeTo = htmlentities($_POST['SatPostcodeTo'], ENT_QUOTES); $SatMiles = htmlentities($_POST['SatMiles'], ENT_QUOTES); $SunTownFrom = htmlentities($_POST['SunTownFrom'], ENT_QUOTES); $SunPostcodeFrom = htmlentities($_POST['SunPostcodeFrom'], ENT_QUOTES); $SunTownTo = htmlentities($_POST['SunTownTo'], ENT_QUOTES); $SunPostcodeTo = htmlentities($_POST['SunPostcodeTo'], ENT_QUOTES); $SunMiles = htmlentities($_POST['SunMiles'], ENT_QUOTES); $SumMiles = htmlentities($_POST['SumMiles'], ENT_QUOTES); $MonCheck = htmlentities($_POST['MonCheck'], ENT_QUOTES); $TueCheck = htmlentities($_POST['TueCheck'], ENT_QUOTES); $WedCheck = htmlentities($_POST['WedCheck'], ENT_QUOTES); $ThuCheck = htmlentities($_POST['ThuCheck'], ENT_QUOTES); $FriCheck = htmlentities($_POST['FriCheck'], ENT_QUOTES); $SatCheck = htmlentities($_POST['SatCheck'], ENT_QUOTES); $SunCheck = htmlentities($_POST['SunCheck'], ENT_QUOTES); $MonHours = htmlentities($_POST['MonHours'], ENT_QUOTES); $TueHours = htmlentities($_POST['TueHours'], ENT_QUOTES); $WedHours = htmlentities($_POST['WedHours'], ENT_QUOTES); $ThuHours = htmlentities($_POST['ThuHours'], ENT_QUOTES); $FriHours = htmlentities($_POST['FriHours'], ENT_QUOTES); $SatHours = htmlentities($_POST['SatHours'], ENT_QUOTES); $SunHours = htmlentities($_POST['SunHours'], ENT_QUOTES); $SumHours = htmlentities($_POST['SumHours'], ENT_QUOTES); $MonTravel = htmlentities($_POST['MonTravel'], ENT_QUOTES); $TueTravel = htmlentities($_POST['TueTravel'], ENT_QUOTES); $WedTravel = htmlentities($_POST['WedTravel'], ENT_QUOTES); $ThuTravel = htmlentities($_POST['ThuTravel'], ENT_QUOTES); $FriTravel = htmlentities($_POST['FriTravel'], ENT_QUOTES); $SatTravel = htmlentities($_POST['SatTravel'], ENT_QUOTES); $SunTravel = htmlentities($_POST['SunTravel'], ENT_QUOTES); $MonMealCheck = htmlentities($_POST['MonMealCheck'], ENT_QUOTES); $TueMealCheck = htmlentities($_POST['TueMealCheck'], ENT_QUOTES); $WedMealCheck = htmlentities($_POST['WedMealCheck'], ENT_QUOTES); $ThuMealCheck = htmlentities($_POST['ThuMealCheck'], ENT_QUOTES); $FriMealCheck = htmlentities($_POST['FriMealCheck'], ENT_QUOTES); $SatMealCheck = htmlentities($_POST['SatMealCheck'], ENT_QUOTES); $SunMealCheck = htmlentities($_POST['SunMealCheck'], ENT_QUOTES); $MonEveningMealCheck = htmlentities($_POST['MonEveningMealCheck'], ENT_QUOTES); $TueEveningMealCheck = htmlentities($_POST['TueEveningMealCheck'], ENT_QUOTES); $WedEveningMealCheck = htmlentities($_POST['WedEveningMealCheck'], ENT_QUOTES); $ThuEveningMealCheck = htmlentities($_POST['ThuEveningMealCheck'], ENT_QUOTES); $FriEveningMealCheck = htmlentities($_POST['FriEveningMealCheck'], ENT_QUOTES); $SatEveningMealCheck = htmlentities($_POST['SatEveningMealCheck'], ENT_QUOTES); $SunEveningMealCheck = htmlentities($_POST['SunEveningMealCheck'], ENT_QUOTES); $MonOvernightCheck = htmlentities($_POST['MonOvernightCheck'], ENT_QUOTES); $TueOvernightCheck = htmlentities($_POST['TueOvernightCheck'], ENT_QUOTES); $WedOvernightCheck = htmlentities($_POST['WedOvernightCheck'], ENT_QUOTES); $ThuOvernightCheck = htmlentities($_POST['ThuOvernightCheck'], ENT_QUOTES); $FriOvernightCheck = htmlentities($_POST['FriOvernightCheck'], ENT_QUOTES); $SatOvernightCheck = htmlentities($_POST['SatOvernightCheck'], ENT_QUOTES); $SunOvernightCheck = htmlentities($_POST['SunOvernightCheck'], ENT_QUOTES); $DeclarationCheck = htmlentities($_POST['DeclarationCheck'], ENT_QUOTES); $ip = htmlentities($_POST['ip'], ENT_QUOTES); $created = htmlentities($_POST['created'], ENT_QUOTES); //check that the required fields are not empty if ($EmployeeName == '' || $EmployeeRef == '' || $DeclarationCheck == '') { $error = 'ERROR: Please fill in all required fields!'; renderForm($EmployeeName, $EmployeeRef, $DeclarationCheck, $error); } else { //Insert the new record if ($stmt = $mysqli->prepare("INSERT mileageform (EmployeeName,EmployeeRef,WeeksPerYear,MonTownFrom,MonPostcodeFrom,MonTownTo,MonPostcodeTo,MonMiles, TueTownFrom,TuePostcodeFrom,TueTownTo,TuePostcodeTo,TueMiles,WedTownFrom,WedPostcodeFrom,WedTownTo,W edPostcodeTo,WedMiles,ThuTownFrom,ThuPostcodeFrom,ThuTownTo,ThuPostcodeTo,ThuMiles,FriTownFrom,FriPo stcodeFrom,FriTownTo,FriPostcodeTo,FriMiles,SatTownFrom,SatPostcodeFrom,SatTownTo,SatPostcodeTo,SatM iles,SunTownFrom,SunPostcodeFrom,SunTownTo,SunPostcodeTo,SunMiles,SumMiles,MonCheck,TueCheck,WedChec k,ThuCheck,FriCheck,SatCheck,SunCheck,MonHours,TueHours,WedHours,ThuHours,FriHours,SatHours,SunHours ,SumHours,MonTravel,TueTravel,WedTravel,ThuTravel,FriTravel,SatTravel,SunTravel,MonMealCheck,TueMeal Check,WedMealCheck,ThuMealCheck,FriMealCheck,SatMealCheck,SunMealCheck,MonEveningMealCheck,TueEvenin gMealCheck,WedEveningMealCheck,ThuEveningMealCheck,FriEveningMealCheck,SatEveningMealCheck,SunEvenin gMealCheck,MonOvernightCheck,TueOvernightCheck,WedOvernightCheck,ThuOvernightCheck,FriOvernightCheck ,SatOvernightCheck,SunOvernightCheck,DeclarationCheck,ip,created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $stmt->bind_param("ss", $EmployeeName, $EmployeeRef, $WeeksPerYear, $MonTownFrom, $MonPostcodeFrom, $MonTownTo, $MonPostcodeTo, $MonMiles, $TueTownFrom, $TuePostcodeFrom, $TueTownTo, $TuePostcodeTo, $TueMiles, $WedTownFrom, $WedPostcodeFrom, $WedTownTo, $WedPostcodeTo, $WedMiles, $ThuTownFrom, $ThuPostcodeFrom, $ThuTownTo, $ThuPostcodeTo, $ThuMiles, $FriTownFrom, $FriPostcodeFrom, $FriTownTo, $FriPostcodeTo, $FriMiles, $SatTownFrom, $SatPostcodeFrom, $SatTownTo, $SatPostcodeTo, $SatMiles, $SunTownFrom, $SunPostcodeFrom, $SunTownTo, $SunPostcodeTo, $SunMiles, $SumMiles, $MonCheck, $TueCheck, $WedCheck, $ThuCheck, $FriCheck, $SatCheck, $SunCheck, $MonHours, $TueHours, $WedHours, $ThuHours, $FriHours, $SatHours, $SunHours, $SumHours, $MonTravel, $TueTravel, $WedTravel, $ThuTravel, $FriTravel, $SatTravel, $SunTravel, $MonMealCheck, $TueMealCheck, $WedMealCheck, $ThuMealCheck, $FriMealCheck, $SatMealCheck, $SunMealCheck, $MonEveningMealCheck, $TueEveningMealCheck, $WedEveningMealCheck, $ThuEveningMealCheck, $FriEveningMealCheck, $SatEveningMealCheck, $SunEveningMealCheck, $MonOvernightCheck, $TueOvernightCheck, $WedOvernightCheck, $ThuOvernightCheck, $FriOvernightCheck, $SatOvernightCheck, $SunOvernightCheck, $DeclarationCheck, $ip, $created); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement. Your Mileage form has not been submitted successfully."; } } } else { renderForm(); } //declare in the order variable $mysqli->close(); ?>

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    Try using <?php (instead of <?). (Looks like it's not being parsed as PHP, just outputting (malformed) HTML.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  8. #8
    Join Date
    Oct 2012
    Posts
    24
    Yep, you're dead right

    So, now it's complaining about:
    Code:
    		$_POST = array_map('mysql_real_escape_string',$_POST);
    on line 22
    the error is shown as:
    Warning: mysql_real_escape_string() [<a href='function.mysql-real-escape-string'>function.mysql-real-escape-string</a>]: Access denied for user ''@'localhost' (using password: NO)
    despite the fact that i'm specifying the database as 127.0.0.1:3307, i'm not sure why it's throwing localhost in there.

    Does it have something to do with how i'm applying the real escape string, versus how i'm trying to use "$stmt ->execute();" ?

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    If you're using the MySQLi extension, then the mysql_*() function won't know anything about that DB connection, and so won't work. In any case, if you are using bound parameters for all the inputs, then you do not want to escape them separately anyway, since the bind_param() method automatically takes care of that, as doing so would result in double escaping. (However, it looks like you'll need a lot more place-holders in its first parameter: one for each place-holder to be bound).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Oct 2012
    Posts
    24
    Thanks very much NogDog, I think i'm starting to get somewhere now!
    I've commented out the mysql_real_escape_string piece and now it's progressing past that error.

    The only thing that I don't seem to be handling correctly now are the checkboxes in my form.

    I've got all the inputs looking for whether they are set or not by the master:
    PHP Code:
    if(isset($_POST['submit'])) 
    However, this isn't handling the checkboxes.
    I get:
    Notice: Undefined index: MonCheck
    and so on, for all checkbox values.

    by looking online, I believe i'd like to handle the checkbox insertion by either using a 1 or a 0 if they are checked or unchecked respectively.
    I can see that this can be typically done by:

    PHP Code:
    $MonCheck = (isset($_POST['MonCheck'])) ? 0
    If this is the way to do it, I can't see how to handle that within my existing code due to the fact that i'm running an isset for all inputs as opposed to doing it for each input individually :

    PHP Code:
       $MonCheck            htmlentities($_POST['MonCheck'],            ENT_QUOTES);
       
    $TueCheck            htmlentities($_POST['TueCheck'],            ENT_QUOTES); 
    Unless I do something like:

    PHP Code:
       $MonCheck            htmlentities($_POST['MonCheck'],            ENT_QUOTES) ? 0;
       
    $TueCheck            htmlentities($_POST['TueCheck'],            ENT_QUOTES) ? 0
    but i'm not sure if this is the right way to go about it.

  11. #11
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Checkboxes are only POST when they are checked. So even though you check if the form was submitted, which you should do differently btw (see: here), the $_POST['CheckBox'] will not be set unless it was checked, that's why the suggested way to check for it is with isset on the field itself.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  12. #12
    Join Date
    Oct 2012
    Posts
    24
    So, the only way to do it is to have 85 different isset statements?

  13. #13
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    If you have 85 checkboxes, in a way yes. You could however name those checkboxes something like name="Options[]" Value="unique values" and then just check the $_POST['Options'] is set and loop through looking for values, you could then have a predefined array of possible values, and then loop through them to determine which ones were checked and which ones weren't. I'm not going to do an 85 point but here's an example of what I mean:

    PHP Code:
    <?php

    $PossibleOptions 
    = array('Ashley','Jack','John');
    $Picks = array();
    if( isset(
    $_POST['Options']) && is_array($_POST['Options']) ) {
       foreach( 
    $PossibleOptions as $opt ) {
          if( 
    in_array($opt$_POST['Options']) ) {
             
    $Picks[$opt] = 1;
          } else {
             
    $Picks[$opt] = 0;
          }
       }
    } else {
       
    $Picks array_combine($PossibleOptionsarray_fill(0count($PossibleOptions), 0));
    }

    $query "Insert into Picks (Jack, John, Ashley) values ("implode(','$Picks) .")";
    echo 
    $query;

    ?>
    <form method="post" action="">
       <input type="checkbox" value="Jack"> Jack<br>
       <input type="checkbox" value="Ashley"> Ashley<br>
       <input type="checkbox" value="John"> John<br>
       <input type="submit" value="Submit">
    </form>
    *Note: Not producing valid html, pseudo/example code.
    Last edited by Derokorian; 11-27-2012 at 03:46 PM.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  14. #14
    Join Date
    Oct 2012
    Posts
    24
    Thanks very much for the input Derokorian.

    I've refined (or is it bloated?) the code now to the below and fixed other errors that I spotted along the way.

    The only issue i'm facing at the moment is that the insert doesn't seem to insert the date/time that I have set by a variable.
    The error is:

    Warning: mysqli_stmt::execute() [<a href='mysqli-stmt.execute'>mysqli-stmt.execute</a>]: (23000/1048): Column 'created' cannot be null
    Obviously this is the target mysql server notifying me that the destination column is not nullable (which is fine) and the underlying issue is that it's not being given the date/time correctly.

    My code is now as below:

    PHP Code:
    <?php

    //set database connection parameters
    $hostname 'localhost:3307'// usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost 
    $db_user 'testuser'// change to your database username
    $db_password 'testpass'// change to your database password 
    $database 'test'// provide your database name 
    //$db_table = 'testform'; // leave this as is 


    //database connection
    $db = new mysqli($hostname$db_user$db_password$database);
    if(
    $db->connect_errno 0)
        {
        die(
    'Unable to connect to database [' $db->connect_error ']');
        }
        
    mysqli_report(MYSQLI_REPORT_ERROR);

    //Prepare prerequisites
            
    $created date("d-m-Y H:i:s");
            
    $ip $_SERVER['REMOTE_ADDR'];

        {

    //get the form data
       
    $EmployeeName        htmlentities(isset($_POST['EmployeeName']),        ENT_QUOTES);
       
    $EmployeeRef         htmlentities(isset($_POST['EmployeeRef']),         ENT_QUOTES);
       
    $WeeksPerYear        htmlentities(isset($_POST['WeeksPerYear']),        ENT_QUOTES);
       
    $MonTownFrom         htmlentities(isset($_POST['MonTownFrom']),         ENT_QUOTES);
       
    $MonPostcodeFrom     htmlentities(isset($_POST['MonPostcodeFrom']),     ENT_QUOTES);
       
    $MonTownTo           htmlentities(isset($_POST['MonTownTo']),           ENT_QUOTES);
       
    $MonPostcodeTo       htmlentities(isset($_POST['MonPostcodeTo']),       ENT_QUOTES);
       
    $MonMiles            htmlentities(isset($_POST['MonMiles']),            ENT_QUOTES);
       
    $TueTownFrom         htmlentities(isset($_POST['TueTownFrom']),         ENT_QUOTES);
       
    $TuePostcodeFrom     htmlentities(isset($_POST['TuePostcodeFrom']),     ENT_QUOTES);
       
    $TueTownTo           htmlentities(isset($_POST['TueTownTo']),           ENT_QUOTES);
       
    $TuePostcodeTo       htmlentities(isset($_POST['TuePostcodeTo']),       ENT_QUOTES);
       
    $TueMiles            htmlentities(isset($_POST['TueMiles']),            ENT_QUOTES);
       
    $WedTownFrom         htmlentities(isset($_POST['WedTownFrom']),         ENT_QUOTES);
       
    $WedPostcodeFrom     htmlentities(isset($_POST['WedPostcodeFrom']),     ENT_QUOTES);
       
    $WedTownTo           htmlentities(isset($_POST['WedTownTo']),           ENT_QUOTES);
       
    $WedPostcodeTo       htmlentities(isset($_POST['WedPostcodeTo']),       ENT_QUOTES);
       
    $WedMiles            htmlentities(isset($_POST['WedMiles']),            ENT_QUOTES);
       
    $ThuTownFrom         htmlentities(isset($_POST['ThuTownFrom']),         ENT_QUOTES);
       
    $ThuPostcodeFrom     htmlentities(isset($_POST['ThuPostcodeFrom']),     ENT_QUOTES);
       
    $ThuTownTo           htmlentities(isset($_POST['ThuTownTo']),           ENT_QUOTES);
       
    $ThuPostcodeTo       htmlentities(isset($_POST['ThuPostcodeTo']),       ENT_QUOTES);
       
    $ThuMiles            htmlentities(isset($_POST['ThuMiles']),            ENT_QUOTES);
       
    $FriTownFrom         htmlentities(isset($_POST['FriTownFrom']),         ENT_QUOTES);
       
    $FriPostcodeFrom     htmlentities(isset($_POST['FriPostcodeFrom']),     ENT_QUOTES);
       
    $FriTownTo           htmlentities(isset($_POST['FriTownTo']),           ENT_QUOTES);
       
    $FriPostcodeTo       htmlentities(isset($_POST['FriPostcodeTo']),       ENT_QUOTES);
       
    $FriMiles            htmlentities(isset($_POST['FriMiles']),            ENT_QUOTES);
       
    $SatTownFrom         htmlentities(isset($_POST['SatTownFrom']),         ENT_QUOTES);
       
    $SatPostcodeFrom     htmlentities(isset($_POST['SatPostcodeFrom']),     ENT_QUOTES);
       
    $SatTownTo           htmlentities(isset($_POST['SatTownTo']),           ENT_QUOTES);
       
    $SatPostcodeTo       htmlentities(isset($_POST['SatPostcodeTo']),       ENT_QUOTES);
       
    $SatMiles            htmlentities(isset($_POST['SatMiles']),            ENT_QUOTES);
       
    $SunTownFrom         htmlentities(isset($_POST['SunTownFrom']),         ENT_QUOTES);
       
    $SunPostcodeFrom     htmlentities(isset($_POST['SunPostcodeFrom']),     ENT_QUOTES);
       
    $SunTownTo           htmlentities(isset($_POST['SunTownTo']),           ENT_QUOTES);
       
    $SunPostcodeTo       htmlentities(isset($_POST['SunPostcodeTo']),       ENT_QUOTES);
       
    $SunMiles            htmlentities(isset($_POST['SunMiles']),            ENT_QUOTES);
       
    $SumMiles            htmlentities(isset($_POST['SunMiles']),            ENT_QUOTES);
       
    $MonCheck            htmlentities(isset($_POST['MonCheck']),            ENT_QUOTES) ? 0;
       
    $TueCheck            htmlentities(isset($_POST['TueCheck']),            ENT_QUOTES) ? 0;
       
    $WedCheck            htmlentities(isset($_POST['WedCheck']),            ENT_QUOTES) ? 0;
       
    $ThuCheck            htmlentities(isset($_POST['ThuCheck']),            ENT_QUOTES) ? 0;
       
    $FriCheck            htmlentities(isset($_POST['FriCheck']),            ENT_QUOTES) ? 0;
       
    $SatCheck            htmlentities(isset($_POST['SatCheck']),            ENT_QUOTES) ? 0;
       
    $SunCheck            htmlentities(isset($_POST['SunCheck']),            ENT_QUOTES) ? 0;
       
    $MonHours            htmlentities(isset($_POST['MonHours']),            ENT_QUOTES);
       
    $TueHours            htmlentities(isset($_POST['TueHours']),            ENT_QUOTES);
       
    $WedHours            htmlentities(isset($_POST['WedHours']),            ENT_QUOTES);
       
    $ThuHours            htmlentities(isset($_POST['ThuHours']),            ENT_QUOTES);
       
    $FriHours            htmlentities(isset($_POST['FriHours']),            ENT_QUOTES);
       
    $SatHours            htmlentities(isset($_POST['SatHours']),            ENT_QUOTES);
       
    $SunHours            htmlentities(isset($_POST['SunHours']),            ENT_QUOTES);
       
    $SumHours            htmlentities(isset($_POST['SumHours']),            ENT_QUOTES);
       
    $MonTravel           htmlentities(isset($_POST['MonTravel']),           ENT_QUOTES);
       
    $TueTravel           htmlentities(isset($_POST['TueTravel']),           ENT_QUOTES);
       
    $WedTravel           htmlentities(isset($_POST['WedTravel']),           ENT_QUOTES);
       
    $ThuTravel           htmlentities(isset($_POST['ThuTravel']),           ENT_QUOTES);
       
    $FriTravel           htmlentities(isset($_POST['FriTravel']),           ENT_QUOTES);
       
    $SatTravel           htmlentities(isset($_POST['SatTravel']),           ENT_QUOTES);
       
    $SunTravel           htmlentities(isset($_POST['SunTravel']),           ENT_QUOTES);
       
    $MonMealCheck        htmlentities(isset($_POST['MonMealCheck']),        ENT_QUOTES) ? 0;
       
    $TueMealCheck        htmlentities(isset($_POST['TueMealCheck']),        ENT_QUOTES) ? 0;
       
    $WedMealCheck        htmlentities(isset($_POST['WedMealCheck']),        ENT_QUOTES) ? 0;
       
    $ThuMealCheck        htmlentities(isset($_POST['ThuMealCheck']),        ENT_QUOTES) ? 0;
       
    $FriMealCheck        htmlentities(isset($_POST['FriMealCheck']),        ENT_QUOTES) ? 0;
       
    $SatMealCheck        htmlentities(isset($_POST['SatMealCheck']),        ENT_QUOTES) ? 0;
       
    $SunMealCheck        htmlentities(isset($_POST['SunMealCheck']),        ENT_QUOTES) ? 0;
       
    $MonEveningMealCheck htmlentities(isset($_POST['MonEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $TueEveningMealCheck htmlentities(isset($_POST['TueEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $WedEveningMealCheck htmlentities(isset($_POST['WedEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $ThuEveningMealCheck htmlentities(isset($_POST['ThuEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $FriEveningMealCheck htmlentities(isset($_POST['FriEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $SatEveningMealCheck htmlentities(isset($_POST['SatEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $SunEveningMealCheck htmlentities(isset($_POST['SunEveningMealCheck']), ENT_QUOTES) ? 0;
       
    $MonOvernightCheck   htmlentities(isset($_POST['MonOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $TueOvernightCheck   htmlentities(isset($_POST['TueOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $WedOvernightCheck   htmlentities(isset($_POST['WedOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $ThuOvernightCheck   htmlentities(isset($_POST['ThuOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $FriOvernightCheck   htmlentities(isset($_POST['FriOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $SatOvernightCheck   htmlentities(isset($_POST['SatOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $SunOvernightCheck   htmlentities(isset($_POST['SunOvernightCheck']),   ENT_QUOTES) ? 0;
       
    $DeclarationCheck    htmlentities(isset($_POST['DeclarationCheck']),    ENT_QUOTES) ? 0;

  15. #15
    Join Date
    Oct 2012
    Posts
    24
    Part 2:
    PHP Code:
    //check that the required fields are not empty
    if ($EmployeeName == '' || $EmployeeRef == '' || $DeclarationCheck == '')
            {
                
    $error 'ERROR: Please fill in all required fields!';
                
    //renderForm($EmployeeName, $EmployeeRef, $DeclarationCheck, $error);
            
    }
    else
            {
        
    //Insert the new record
        
    if ($stmt $db->prepare("INSERT mileageform (EmployeeName,EmployeeRef,WeeksPerYear,MonTownFrom,MonPostcodeFrom,MonTownTo,MonPostcodeTo,MonMiles,TueTownFrom,TuePostcodeFrom,TueTownTo,TuePostcodeTo,TueMiles,WedTownFrom,WedPostcodeFrom,WedTownTo,WedPostcodeTo,WedMiles,ThuTownFrom,ThuPostcodeFrom,ThuTownTo,ThuPostcodeTo,ThuMiles,FriTownFrom,FriPostcodeFrom,FriTownTo,FriPostcodeTo,FriMiles,SatTownFrom,SatPostcodeFrom,SatTownTo,SatPostcodeTo,SatMiles,SunTownFrom,SunPostcodeFrom,SunTownTo,SunPostcodeTo,SunMiles,SumMiles,MonCheck,TueCheck,WedCheck,ThuCheck,FriCheck,SatCheck,SunCheck,MonHours,TueHours,WedHours,ThuHours,FriHours,SatHours,SunHours,SumHours,MonTravel,TueTravel,WedTravel,ThuTravel,FriTravel,SatTravel,SunTravel,MonMealCheck,TueMealCheck,WedMealCheck,ThuMealCheck,FriMealCheck,SatMealCheck,SunMealCheck,MonEveningMealCheck,TueEveningMealCheck,WedEveningMealCheck,ThuEveningMealCheck,FriEveningMealCheck,SatEveningMealCheck,SunEveningMealCheck,MonOvernightCheck,TueOvernightCheck,WedOvernightCheck,ThuOvernightCheck,FriOvernightCheck,SatOvernightCheck,SunOvernightCheck,DeclarationCheck,ip,created)
         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, INET_ATON(?))"
    ))
                {
                
    $stmt->bind_param("sssssssssssssssssssssssssssssssssssssssiiiiiiisssssssssssssssiiiiiiiiiiiiiiiiiiiiiiss"$EmployeeName$EmployeeRef$WeeksPerYear$MonTownFrom$MonPostcodeFrom$MonTownTo$MonPostcodeTo$MonMiles$TueTownFrom$TuePostcodeFrom$TueTownTo$TuePostcodeTo$TueMiles$WedTownFrom$WedPostcodeFrom$WedTownTo$WedPostcodeTo$WedMiles$ThuTownFrom$ThuPostcodeFrom$ThuTownTo$ThuPostcodeTo$ThuMiles$FriTownFrom$FriPostcodeFrom$FriTownTo$FriPostcodeTo$FriMiles$SatTownFrom$SatPostcodeFrom$SatTownTo$SatPostcodeTo$SatMiles$SunTownFrom$SunPostcodeFrom$SunTownTo$SunPostcodeTo$SunMiles$SumMiles$MonCheck$TueCheck$WedCheck$ThuCheck$FriCheck$SatCheck$SunCheck$MonHours$TueHours$WedHours$ThuHours$FriHours$SatHours$SunHours$SumHours$MonTravel$TueTravel$WedTravel$ThuTravel$FriTravel$SatTravel$SunTravel$MonMealCheck$TueMealCheck$WedMealCheck$ThuMealCheck$FriMealCheck$SatMealCheck$SunMealCheck$MonEveningMealCheck$TueEveningMealCheck$WedEveningMealCheck$ThuEveningMealCheck$FriEveningMealCheck$SatEveningMealCheck$SunEveningMealCheck$MonOvernightCheck$TueOvernightCheck$WedOvernightCheck$ThuOvernightCheck$FriOvernightCheck$SatOvernightCheck$SunOvernightCheck$DeclarationCheck$ip$created);
                
    $stmt->execute();
                
    $stmt->close();
                }
            
    // show an error if the query has an error
            
    else
                {
                echo 
    "ERROR: Could not prepare SQL statement. Your Mileage form has not been submitted successfully.";
                }
            }
        }
        

    //declare in the order variable
    $db->close();

    ?> 
    So, i've declared: $created = date("d-m-Y H:i:s");
    but it doesn't seem to be inserting.
    Is it because the declaration is in the wrong location?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles