Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP/MYSQL mismatch grrrrrr

  • 10-10-2007 04: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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 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