Form not saving to database

后端 未结 2 610
梦毁少年i
梦毁少年i 2021-01-22 08:23

I made a form for a 5K run where the user enters basic information about him/her (first name, last name, email, organization, whether they are attending the event, and checking

2条回答
  •  无人及你
    2021-01-22 08:53

    First, though I generally loathe these suggestions, have you considered using a google doc with a form front end? They're a super easy way for non-developers to get data from people, and have it arrive in a spreadsheet.

    Baring that, I'm assuming you're using an auto-increment primary key, might I suggest changing your query to:

    if(mysql_query("INSERT INTO basicInfo VALUES(null, '{$_POST['first]}', '{$_POST['last']}', '{$_POST['email']}', '{$_POST['attendant']}', '$org', $time, 0, '', 1)"))
        {
    

    I've changed your '' to a null, as you want the DB to insert what it wants there. I've also changed the way you're including associative arrays in the string to a way that generally makes PHP happier.

    For cleaning the $_POST array, something like

    $expected = array('first', 'last', 'expected', 'attendant');
    foreach($expected as $k)
    {
      $p[$k] = clean($_POST[$k]);
    }
    //then changing the query to use $p rather than $_POST, clearly. 
    

    past that, as others have suggested, I would strongly recommend you use mysql_real_escape_string() rather than some sort of addslashes() combo.

    Posting the results of SHOW CREATE TABLE basicInfo; or any errors will help with MySQL issues.

提交回复
热议问题