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? 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:
Not there clearly :S I am a complete novice and have been using this outdated guide to help me.http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php If that is the problem, what are my next steps to fixing this? Your help is very much appreciated. Cheers
<?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.