Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP/MYSQL mismatch grrrrrr

Options
  • 10-10-2007 5:08pm
    #1
    Closed Accounts Posts: 46


    Hi, PLEASE help me before i scream :D

    I am using a javascript pop up date calender that allows my user to select their a date in a form. The date is then put in dd/mm/yyy format. When I try to insert this into my mysql table - it doesnt like it - obviously cos the format needs to be yyyy/mm/dd... so I tried to use the following to convert the field before the sql insert is ran but I just keep getting errors.

    Can anyone please help me.

    //here is where i am converting the date of birth field from my form
    $DOB = explode($_POST,"/");
    $DOB[0] =dd
    $DOB[1] =mm
    $DOB[2] =yyyy
    $new_dob = sprintf("%s/%s/%s",$DOB[2],$DOB[1],$DOB[0]);

    //here is where i am inserting it into my table using the $new_dob which i thought would work :(
    $query="REPLACE INTO Employee VALUES ('$Name', '$Address', '$new_dob', '$Phone', '$EName', '$Ephone', '$PPS', '$SPass', '$SPassEx', '$StartDate', '$EndDate', '$Rate', '$BankAcc', '$Notes')";

    Thanks in advance for any help


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    What's the specific error that MySQL is spitting back?

    If you echo the contents of the query, does it appear as it should?

    I always thought that DATE values went in as YYYY-MM-DD, but maybe that's just me.


  • Closed Accounts Posts: 46 kat9182


    Hi, Thanks for your reply.

    I am just getting a Parse error now so I cant even echo the query to see what it is :o(

    here is the content of the entire php file if that helps:
    <?php
    include( "db.inc");
    ?>

    <?
    if($_POST) //If submit is hit
    {

    $Name = $_POST;
    $Address = $_POST;
    # $DOB = $_POST;
    $Phone = $_POST;
    $EName = $_POST;
    $Ephone = $_POST;
    $PPS = $_POST;
    $SPass = $_POST;
    $SPassEx= $_POST;
    $StartDate = $_POST;
    $EndDate = $_POST;
    $Rate= $_POST;
    $BankAcc= $_POST;
    $Notes= $_POST;


    $DOB = explode($_POST,"/");
    $DOB[0] =dd
    $DOB[1] =mm
    $DOB[2] =yyyy
    $new_dob = sprintf("%s/%s/%s",$DOB[2],$DOB[1],$DOB[0]);


    $query="REPLACE INTO Employee VALUES ('$Name', '$Address', '$new_dob', '$Phone', '$EName', '$Ephone', '$PPS', '$SPass', '$SPassEx', '$StartDate', '$EndDate', '$Rate', '$BankAcc', '$Notes')";


    //Connect to the DB
    $connection = @ mysql_connect($hostName,
    $username,
    $password)
    or die("Cannot connect");
    //Select the DB
    mysql_select_db("primaryip_schedule", $connection);

    // Execute the query
    $result = mysql_query ($query, $connection);

    echo "New employee added $Name";

    echo "<meta http-equiv='refresh' content='1;url="viewemployee.php'>";

    }
    ?>



    AND THIS IS THE TABLE IM TRYING TO INSERT INTO

    CREATE TABLE `Employee` (\n `Name` varchar(65) NOT NULL default '',\n `Address` varchar(100) NOT NULL default '',\n `DOB` date NOT NULL default '0000-00-00',\n `phone` varchar(25) NOT NULL default '0',\n `EName` varchar(100) NOT NULL default '',\n `Ephone` varchar(25) NOT NULL default '0',\n `PPS` varchar(20) NOT NULL default '0',\n `SPass` char(3) NOT NULL default '',\n `SPassEx` date NOT NULL default '0000-00-00',\n `StartDate` date NOT NULL default '0000-00-00',\n `EndDate` date NOT NULL default '0000-00-00',\n `Rate` decimal(10,2) NOT NULL default '0.00',\n `BankAcc` tinytext NOT NULL,\n `Notes` varchar(250) NOT NULL default '',\n PRIMARY KEY (`Name`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Have a look at the parse error that you're getting, it's usually pretty good at telling you where you went wrong. The first error I got pointed to these three lines:
    $DOB[0] =dd
    $DOB[1] =mm
    $DOB[2] =yyyy
    
    What are they supposed to be doing? :)


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    Should be "-" rather than "/" as the other poster suggested.


  • Closed Accounts Posts: 583 ✭✭✭monkey tennis


    Bluefrog wrote: »
    Should be "-" rather than "/" as the other poster suggested.

    That's just part of the problem, Seamus is on the money with the assignment operations...


  • Advertisement
Advertisement