Help with PHP code

Discussion in 'PHP' started by Cain Fleming, Dec 20, 2010.

  1. #1
    Hi, I'm new to PHP and have been learning rapidly over the past few weeks.

    I am attempting to add data to a mysql database through a form on my site.

    However when I submit my form, the mysql database does not update.

    How can this be?

    Have a look at my code, tell me what's wrong and how I can improve.

    Could it be a problem with the form? :confused:

    Thanks

    Cain
    
    <?php
    $month_3 = $_POST ['month_3'];
    $day_3 = $_POST['day_3'];
    $year_3 = $_POST['year_3'];
    $hour_3 = $_POST['hour_3'];
    $min_3 = $_POST['min_3'];
    $ampm_3 = $_POST['ampm_3'];
    $protest_type = $_POST['protest_type'];
    $protest_title = $_POST['protest_title'];
    $protest_description = $_POST['protest_description'];
    $protest_speaker = $_POST['protest_speaker'];
    $url_link = $_POST['url_link'];
    $facebook_link = $_POST['facebook_link'];
    $street_address = $_POST['street_address'];
    $street_address2 = $_POST['street_address2'];
    $address_city = $_POST['address_city'];
    $address_state = $_POST['address_state'];
    $address_postal = $_POST['address_postal'];
    $address_country = $_POST['address_country'];
    $protest_email = $_POST['protest_email'];
    
    
    mysql_connect ("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx") or die ('Error: ' . mysql_error());
    mysql_select_db ("eventform");
    
    $query="INSERT INTO event_form (protest_ID, month_3, day_3, year_3, hour_3, min_3, ampm_3, protest_type, protest_title, protest_description, protest_speaker, url_link, facebook_link, street_address, street_address2, address_city, address_state, address_postal, address_country, protest_email)VALUES ('NULL','".$month_3."','".$day_3."','".$year_3."','".$hour_3."','".$min_3."','".$ampm_3."','".$protest_type."','".$protest_title."','".$protest_description."','".$protest_speaker."','".$url_link."','".$facebook_link."','".$street_address."','".$street_address2."','".$address_city."','".$address_state."','".$address_postal."','".$address_country."','".$protest_email."')";
    
    echo "Database updated with: " .$month_3." ".$day_3." ".$year_3." ".$hour_3." ".$min_3." ".$ampm_3." ".$protest_type." ".$protest_title." ".$protest_description." ".$protest_speaker." ".$url_link." ".$facebook_link." ".$street_address." ".$street_address2." ".$address_city." ".$address_state." ".$address_postal." ".$address_country." ".$protest_email ;
    
    
    ?>
    
    PHP:

     
    Cain Fleming, Dec 20, 2010 IP
  2. Simple Management

    Simple Management Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Where is mysql_query ?
     
    Simple Management, Dec 20, 2010 IP
  3. Cain Fleming

    Cain Fleming Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cain Fleming, Dec 20, 2010 IP
  4. Simple Management

    Simple Management Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    $month_3 = $_POST ['month_3'];
    $day_3 = $_POST['day_3'];
    $year_3 = $_POST['year_3'];
    $hour_3 = $_POST['hour_3'];
    $min_3 = $_POST['min_3'];
    $ampm_3 = $_POST['ampm_3'];
    $protest_type = $_POST['protest_type'];
    $protest_title = $_POST['protest_title'];
    $protest_description = $_POST['protest_description'];
    $protest_speaker = $_POST['protest_speaker'];
    $url_link = $_POST['url_link'];
    $facebook_link = $_POST['facebook_link'];
    $street_address = $_POST['street_address'];
    $street_address2 = $_POST['street_address2'];
    $address_city = $_POST['address_city'];
    $address_state = $_POST['address_state'];
    $address_postal = $_POST['address_postal'];
    $address_country = $_POST['address_country'];
    $protest_email = $_POST['protest_email'];
    
    
    mysql_connect ("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx") or die ('Error: ' . mysql_error());
    mysql_select_db ("eventform");
    
    $query=mysql_query("INSERT INTO event_form (protest_ID, month_3, day_3, year_3, hour_3, min_3, ampm_3, protest_type, protest_title, protest_description, protest_speaker, url_link, facebook_link, street_address, street_address2, address_city, address_state, address_postal, address_country, protest_email)VALUES ('NULL','".$month_3."','".$day_3."','".$year_3."','".$hour_3."','".$min_3."','".$ampm_3."','".$protest_type."','".$protest_title."','".$protest_description."','".$protest_speaker."','".$url_link."','".$facebook_link."','".$street_address."','".$street_address2."','".$address_city."','".$address_state."','".$address_postal."','".$address_country."','".$protest_email."')") or die(mysql_error());
    
    echo "Database updated with: " .$month_3." ".$day_3." ".$year_3." ".$hour_3." ".$min_3." ".$ampm_3." ".$protest_type." ".$protest_title." ".$protest_description." ".$protest_speaker." ".$url_link." ".$facebook_link." ".$street_address." ".$street_address2." ".$address_city." ".$address_state." ".$address_postal." ".$address_country." ".$protest_email ;
    
    ?>
    PHP:
    This should work.
     
    Simple Management, Dec 20, 2010 IP
  5. Cain Fleming

    Cain Fleming Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks worked a treat!

    Pondered for an hour before I posted there. I can sleep easy now. :)
     
    Cain Fleming, Dec 20, 2010 IP