Jump to content

xCiter

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Posts posted by xCiter

  1. Thanks for the reply, i did what you recommended but get this error:

     

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '',')' at line 1

     

    This is the updated version of my code:

     

    $dob = "{$_POST['year']}-{$_POST['month']}-{$_POST['day']}";
    $sql = "INSERT INTO account (Username, FirstName, LastName, DateofBirth, Email, HearAbout, Recommended, FriendUser) VALUES ('$_POST[username]','$_POST[fname]','$_POST[lname]','$dob','$_POST[email]','$_POST[hear]',$_POST[recom]',$_POST[fusername]')";
    

     

    Could you explain a bit more about sanitizing data? I've seen it posted before but still don't understand what it does

  2. I should have mentioned before that the above code is not all that i have.

     

    This is all of it:

     

    <?php
    // Create php connection 
    $connection = mysql_connect("*****","*****","****");
    
    // If no connection is established, error message.
    if (!$connection)
    {
    die("Error: Could not connect to host. Reason: " . mysql_error());
    }
    
    mysql_select_db("bliss510_social", $connection);
    
    $sql = "INSERT INTO account (Username, FirstName, LastName, DateofBirth, Email, HearAbout, Recommended, FriendUser) VALUES ('$_POST[username]','$_POST[fname]','$_POST[lname]','$_POST[day]' . - . '$_POST[month]' . - . '$_POST[year]','$_POST[email]','$_POST[hear]',$_POST[recom]',$_POST[fusername]')";
    
    if (!mysql_query($sql, $connection))
    {
    die('Error: ' .mysql_error());
    }
    echo "1 record added";
    mysql_close($connection)
    ?>

  3. Hi there,

     

    I'm new to PHP so sorry if this is a really basic question.

     

    How do i post date of birth collected from a form, into a database?

     

    I have the fields in the form set up as 'day' 'month' 'year' all of which are drop-down boxes.

     

    I tried doing it one way which i saw on a different website, but it didn't work. Here is what i tried:

    '$_POST[day] . - . $_POST[month]' . - . $_POST[year]',

     

    More info: In the database table this information is going to, the "date of birth" field is set to "DATE" type. Don't know if that makes any difference

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.