mfandel Posted April 2, 2010 Share Posted April 2, 2010 I am trying to use a form that will post data to the MYSQL database. I don't get any errors, but the data is not appearing in my database. Any help is appreciated. It is a form we used last year, with just some update info. I am not very proficient with php/mysql. This was actually built for me but the developer is MIA. The strange thing is that it worked. Is it possible that my hosting provider has a setting which has changed that would make this now now work. I also tried adding: <?php error_reporting(E_ALL); ?> But I don't get any errors. It just seems to process the form, but then in phpmyadmin there is no data. I changed the database logins for security. front end can be viewed at: http://www.avsabonline.org/admin_form.php Syntax: [ Download ] [ Hide ] [ Select ] [ Contract ] Syntax: [ Download ] [ Show ] <?php $db_host = "localhost"; $db_user = "avsab_user"; $db_pwd = "pwd"; $db_name = "avsab_registration"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <?php include 'states.php' ?> <br /> <?php function showOptionsDrop($array){ $string = ''; foreach($array as $k => $v){ $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n"; } return $string; } $em = $_GET; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="http://avsabonline.org/avsabonline/administrator/templates/minted_one-point-five/css/template_css.css" type="text/css" /> <link rel="stylesheet" href="http://avsabonline.org/avsabonline/administrator/templates/minted_one-point-five/css/theme.css" type="text/css" /> <title>AVSAB Scientific Session Manual Add</title> <style> body{font-family:arial;color:#333333;font-size:12px;} .space{padding-right:20px;padding-bottom:20px;} select{font-family:arial;color:#333333;width:100px;font-size:12px;} input{font-size:12px;border:1px solid #cccccc;background:#eeeeee;} a:link{color:#1E90FF;text-decoration:none;} a:visited{color:#1E90FF;text-decoration:none;} a:active{color:#1E90FF;text-decoration:none;} a:hover{color:#1E90FF;text-decoration:none;} </style> <link rel="stylesheet" type="text/css" href="reset.css"> <link rel="stylesheet" type="text/css" href="form_style.css"> <link rel="stylesheet" type="text/css" href="form_style2.css"> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> </head> <body> <center> <div style="width:820px;"> <table style="width:720px;""> <tr> <td> <?php if (!isset($_POST['submit'])) { ?> <div id="container"> <form method="post" name="avsab"> <fieldset id="personal" class="repeat"> <legend>Personal Information</legend> <div style="float:left;"> <span class="oneField"> <label class="preField">Prefix <select name="prefix"><?php echo showOptionsDrop($prefix_arr); ?></select> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Degree / Suffix for badge <select name="degree"><?php echo showOptionsDrop($degree_arr); ?></select> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Other <input TYPE="text" NAME="otherdegree" size="20"></label> </span> </div> <br><br><br><br> <div style="float:left;"> <span class="oneField"> <label class="preField">Last (family) Name <input TYPE="text" NAME="lastname" size="36"> <span class="reqMark">*</span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">First (given) Name <input TYPE="text" NAME="firstname" size="36"> <span class="reqMark">*</span></label><br></span> </div> <br><br><br><br> <div style="float:left;"> <span class="oneField"> <label class="preField">If Student List College(s) Attended <input TYPE="text" NAME="college" size="40"> <span class="reqMark"> </span></label><br></span> </div> <div> <span class="oneField"> <label class="preField">Year of Graduation <input TYPE="text" style="text-align:left;" id="gradyear" NAME="gradyear" size="15" value=""></label> </span> </div> <br /><br /> <div style="float:left;"> <style>.radio_tag{font-size:12px;}.radio_tag input{border:none;}.other_tag{font-size:12px;}</style> <label class="preField" style="float:left;v">Dietary Preference</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="No Preference">No Preference</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Vegetarian">Vegetarian</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Vegan">Vegan</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Other">Other</label> <label class="other_tag"><input TYPE="text" name="other_dietary_preference" size="20"></label> </div> </fieldset> <fieldset id="contact" class=""> <legend>Contact Information</legend> <span class="oneField"> <label class="preField">Address <input TYPE="text" NAME="address" size="120"> <span class="reqMark"> </span></label><br></span> <div style="float:left;"> <span class="oneField"> <label class="preField">City <input TYPE="text" NAME="city" size="50"> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">State/Province <select name="state"><?php echo showOptionsDrop($states_arr); ?></select></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Poastal Code <input TYPE="text" NAME="zipcode" size="10"> <span class="reqMark">*</span></label><br></span> </div> <br /><br /><br /><br /> <div style="float:left;"> <span class="oneField"> <label class="preField">Country <select name="country"><?php echo showOptionsDrop($country_arr); ?></select> <span class="reqMark"></span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Email <input TYPE="text" NAME="email" size="50" value="<?php echo $em ?>"> <span class="reqMark">*</span></label><br></span> </div> <br /><br /><br /><br /> <div id="phone" style="float:left;"> <span class="oneField"> <label class="preField">Daytime Phone <input type="text" name="phone_first" size=4 onKeyup="autotab(this, document.avsab.phone_second)" maxlength=3> <input type="text" name="phone_second" size=4 onKeyup="autotab(this, document.avsab.phone_third)" maxlength=3> <input type="text" name="phone_third" size=5 maxlength=4> <span class="reqMark"></span></label><br></span> </div> <div id="phone" style="float:left;"> <span class="oneField"> <label class="preField">Fax <input type="text" name="fax_first" size=4 onKeyup="autotab(this, document.avsab.fax_second)" maxlength=3> <input type="text" name="fax_second" size=4 onKeyup="autotab(this, document.avsab.fax_third)" maxlength=3> <input type="text" name="fax_third" size=5 maxlength=4> <span class="reqMark"></span></label><br></span> </div> <br /><br /><br /><br /> <div style="padding-top:40px;"> <div style="float:right;"> <input type="hidden" name="year" value="2010"> <input type="submit" name="submit" value="Submit Registration"> </div> </div> </fieldset> </div><!--eof container--> </body> </html> <?php }else{ ?> <?php $phone_main = '('.$_POST['phone_first'].') '.$_POST['phone_second'].'-'.$_POST['phone_third']; $fax_main = '('.$_POST['fax_first'].') '.$_POST['fax_second'].'-'.$_POST['fax_third']; $prefix = $_POST['prefix']; $degree = $_POST['degree']; $otherdegree = $_POST['otherdegree']; $lastname = $_POST['lastname']; $firstname = $_POST['firstname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $country = $_POST['country']; $email = $_POST['email']; $phone = $phone_main; $fax = $fax_main; $college = $_POST['college']; $gradyear = $_POST['gradyear']; $year = $_POST['year']; $dietary_preference = $_POST['dietary_preference']; $other_dietary_preference = $_POST['other_dietary_preference']; mysql_query("INSERT INTO `register` (prefix,degree,otherdegree,lastname,firstname,address,city,state,zipcode,country,email,phone,fax,college,gradyear,year,dietary_preference,other_dietary_preference) VALUES ('$prefix','$degree','$otherdegree','$lastname','$firstname','$address','$city','$state','$zipcode','$country','$email','$phone','$fax','$college','$gradyear','$year','$dietary_preference','$other_dietary_preference')"); echo ""; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>ACVB/AVSAB Behavior Symposium - July 30, 2010</title> <link rel="stylesheet" type="text/css" href="reset.css"> <link rel="stylesheet" type="text/css" href="form_style.css"> <link rel="stylesheet" type="text/css" href="form_style2.css"> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> </head> <body> <div> Thank-You. The registrant has been submitted. <a href="http://avsabonline.org/avsabonline/administrator/addon3.php">Return to Annual Meeting Registrants.</a> </div> <? } ?> </table> </div> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/197333-send-data-to-mysql/ Share on other sites More sharing options...
ialsoagree Posted April 3, 2010 Share Posted April 3, 2010 It really helps when code is enclosed in PHP or CODE bb tags... Users will format posts as best as they can by using proper code /code or php /php tags and following Proper Code Indentation guidelines. http://www.phpfreaks.com/page/rules-and-terms-of-service#toc_forum_guidelines Your problem is with your form: <form method="post" name="avsab"> You need an action attribute equal to the PHP script you want to run. <form method="post" name="asvab" action="your_php_file_name.php"> I haven't checked your code for any other errors. Link to comment https://forums.phpfreaks.com/topic/197333-send-data-to-mysql/#findComment-1036577 Share on other sites More sharing options...
mfandel Posted April 5, 2010 Author Share Posted April 5, 2010 Do I have to have an outside file. I thought I could have within the same file as I currently have setup. I did try what you mentioned though and setup a action and seperate file, but still no luck. I have been reading everywhere and trying different things, Here is my updated code.... that after countless hours still doesn't work. page can be found here: http://www.avsabonline.org/admin_form.php CODE: <?php $db_host = "localhost"; $db_user = "avsab_admin"; $db_pwd = "admin"; $db_name = "avsab_registration"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <?php include 'states.php' ?> <br /> <?php function showOptionsDrop($array){ $string = ''; foreach($array as $k => $v){ $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n"; } return $string; } ?> <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="http://avsabonline.org/avsabonline/administrator/templates/minted_one-point-five/css/template_css.css" type="text/css" /> <link rel="stylesheet" href="http://avsabonline.org/avsabonline/administrator/templates/minted_one-point-five/css/theme.css" type="text/css" /> <title>AVSAB Scientific Session</title> <style> body{font-family:arial;color:#333333;font-size:12px;} .space{padding-right:20px;padding-bottom:20px;} select{font-family:arial;color:#333333;width:100px;font-size:12px;} input{font-size:12px;border:1px solid #cccccc;background:#eeeeee;} a:link{color:#1E90FF;text-decoration:none;} a:visited{color:#1E90FF;text-decoration:none;} a:active{color:#1E90FF;text-decoration:none;} a:hover{color:#1E90FF;text-decoration:none;} </style> <link rel="stylesheet" type="text/css" href="reset.css"> <link rel="stylesheet" type="text/css" href="form_style.css"> <link rel="stylesheet" type="text/css" href="form_style2.css"> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> </head> <body> <center> <div style="width:820px;"> <table style="width:720px;""> <tr> <td> <?php if (!isset($_POST['submit'])) { ?> <div id="container"> <form method="post" name="avsab"> <fieldset id="personal" class="repeat"> <legend>Personal Information</legend> <div style="float:left;"> <span class="oneField"> <label class="preField">Prefix <select name="prefix"><?php echo showOptionsDrop($prefix_arr); ?></select> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Degree / Suffix for badge <select name="degree"><?php echo showOptionsDrop($degree_arr); ?></select> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Other <input TYPE="text" NAME="otherdegree" size="20"></label> </span> </div> <br><br><br><br> <div style="float:left;"> <span class="oneField"> <label class="preField">Last (family) Name <input TYPE="text" NAME="lastname" size="36"> <span class="reqMark">*</span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">First (given) Name <input TYPE="text" NAME="firstname" size="36"> <span class="reqMark">*</span></label><br></span> </div> <br><br><br><br> <div style="float:left;"> <span class="oneField"> <label class="preField">If Student List College(s) Attended <input TYPE="text" NAME="college" size="40"> <span class="reqMark"> </span></label><br></span> </div> <div> <span class="oneField"> <label class="preField">Year of Graduation <input TYPE="text" style="text-align:left;" id="gradyear" NAME="gradyear" size="15" value=""></label> </span> </div> <br /><br /> <div style="float:left;"> <style>.radio_tag{font-size:12px;}.radio_tag input{border:none;}.other_tag{font-size:12px;}</style> <label class="preField" style="float:left;v">Dietary Preference</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="No Preference">No Preference</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Vegetarian">Vegetarian</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Vegan">Vegan</label> <label class="radio_tag"><input type="radio" name="dietary_preference" value="Other">Other</label> <label class="other_tag"><input TYPE="text" name="other_dietary_preference" size="20"></label> </div> </fieldset> <fieldset id="contact" class=""> <legend>Contact Information</legend> <span class="oneField"> <label class="preField">Address <input TYPE="text" NAME="address" size="120"> <span class="reqMark"> </span></label><br></span> <div style="float:left;"> <span class="oneField"> <label class="preField">City <input TYPE="text" NAME="city" size="50"> <span class="reqMark"> </span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">State/Province <select name="state"><?php echo showOptionsDrop($states_arr); ?></select></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Poastal Code <input TYPE="text" NAME="zipcode" size="10"> <span class="reqMark">*</span></label><br></span> </div> <br /><br /><br /><br /> <div style="float:left;"> <span class="oneField"> <label class="preField">Country <select name="country"><?php echo showOptionsDrop($country_arr); ?></select> <span class="reqMark"></span></label><br></span> </div> <div style="float:left;"> <span class="oneField"> <label class="preField">Email <input TYPE="text" NAME="email" size="50"> <span class="reqMark">*</span></label><br></span> </div> <br /><br /><br /><br /> <div id="phone" style="float:left;"> <span class="oneField"> <label class="preField">Daytime Phone <input type="text" name="phone_first" size=4 onKeyup="autotab(this, document.avsab.phone_second)" maxlength=3> <input type="text" name="phone_second" size=4 onKeyup="autotab(this, document.avsab.phone_third)" maxlength=3> <input type="text" name="phone_third" size=5 maxlength=4> <span class="reqMark"></span></label><br></span> </div> <div id="phone" style="float:left;"> <span class="oneField"> <label class="preField">Fax <input type="text" name="fax_first" size=4 onKeyup="autotab(this, document.avsab.fax_second)" maxlength=3> <input type="text" name="fax_second" size=4 onKeyup="autotab(this, document.avsab.fax_third)" maxlength=3> <input type="text" name="fax_third" size=5 maxlength=4> <span class="reqMark"></span></label><br></span> </div> <br /><br /><br /><br /> <div style="padding-top:40px;"> <div style="float:right;"> <input type="hidden" name="year" value="2010"> <input type="submit" name="submit" value="Submit Registration"> </div> </div> </fieldset> </div><!--eof container--> </body> </html> <?php }else{ ?> <?php $phone_main = '('.$_POST['phone_first'].') '.$_POST['phone_second'].'-'.$_POST['phone_third']; $fax_main = '('.$_POST['fax_first'].') '.$_POST['fax_second'].'-'.$_POST['fax_third']; $prefix = mysql_real_escape_string($_POST['prefix']); $degree = mysql_real_escape_string($_POST['degree']); $otherdegree = mysql_real_escape_string($_POST['otherdegree']); $lastname = mysql_real_escape_string($_POST['lastname']); $firstname = mysql_real_escape_string($_POST['firstname']); $address = mysql_real_escape_string($_POST['address']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zipcode = mysql_real_escape_string($_POST['zipcode']); $country = mysql_real_escape_string($_POST['country']); $email = mysql_real_escape_string($_POST['email']); $phone = $phone_main; $fax = $fax_main; $college = mysql_real_escape_string($_POST['college']); $gradyear = mysql_real_escape_string($_POST['gradyear']); $year = mysql_real_escape_string($_POST['year']); $dietary_preference = mysql_real_escape_string($_POST['dietary_preference']); $other_dietary_preference = mysql_real_escape_string($_POST['other_dietary_preference']); // Put the SQL query string together $query = "INSERT INTO `register` (prefix, degree, otherdegree, lastname, firstname, address, city, state, zipcode, country, email, phone, fax, college, gradyear, year, dietary_preference, other_dietary_preference) VALUES ('$prefix', '$degree', '$otherdegree', '$lastname', '$firstname', '$address', '$city', '$state', '$zipcode', '$country', '$email', '$phone', '$fax', '$college', '$gradyear', '$year', '$dietary_preference', '$other_dietary_preference')"; // Perform the query $queryResult = mysql_query($query); // Dump the result for debugging purposes echo '<br />The SQL query that was attempted was:<br />'; var_dump($query); echo '<br />The queryResult resource was:<br />'; var_dump($query); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>ACVB/AVSAB Behavior Symposium - July 10, 2009</title> <link rel="stylesheet" type="text/css" href="reset.css"> <link rel="stylesheet" type="text/css" href="form_style.css"> <link rel="stylesheet" type="text/css" href="form_style2.css"> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> </head> <body> <div> Thank-You. The registrant has been submitted. <a href="http://avsabonline.org/avsabonline/administrator/addon3.php">Return to Annual Meeting Registrants.</a> </div> <? } ?> </table> </div> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/197333-send-data-to-mysql/#findComment-1037047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.