Jump to content

I a noob please help me :(


moriahcgibbs

Recommended Posts

I cannot figure out what is wrong with the form i made that is "supposed" to enter data into my database. It is just a simple form and I cant figure out what im doing wrong.Im still in the process of learning php and this is driving me crazy. can anyone figure out what im doing wrong? here is the HTML form: <html><body> <form method="post" action="output.php"> <table id="email_form"><tbody> <tr> <td><label for="f_name">First:</label></td><td><input type="text" name="f_name" id="f_name" /></td></tr><tr> <td><label for="l_name">Last:</label></td><td><input type="text" name="l_name" id="l_name" /></td></tr><tr> <td><label>Gender:</label></td><td> <input type="radio" name="gender" id="male" value="male" />Male<br /> <input type="radio" name="gender" id="female" value="famale" />Female</td></tr><tr> <td><label for="email">Email:</label></td><td><input type="email" name="email" id="email" /></td></tr><tr> <td><label for="city">City:</label></td><td><input type="text" name="city" id="city" /></td></tr><tr> <td><label for="zip_code">Zip Codde:</label></td><td><input type="text" name="zip_code" id="zip_code" /></td></tr><tr> <td colspan="2"><label for="question" class="f">"insert question here":</label></td></tr><tr><td colspan="2"><textarea id="question" name="question" rows="5" cols="25"></textarea></td></tr><tr><td colspan="2"><input type="submit" value="submit" name="submit" /></td></tr> </tbody></table> </form> </body></html> Here is the php code: <html><body> <?php $f_name = $_POST['f_name'];$l_name = $_POST['l_name']; $selected_radio = $_POST['gender'];$email = $_POST['email']; $city = $_POST['city']; $zip_code = $_POST['zip_code']; $question = $_POST['question']; function spamcheck($field) { $field=filter_var($field, FILTER_SANITIZE_EMAIL); if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } $dbc = mysqli_connect('ServerName', 'UserName', 'Password', 'DatabaseName') or die('error connecting to nmysql server'); $query = 'INSERT INTO email (F_name, L_name, Gender, Email, City, Zip_code, Question)'. 'VALUES ("$f_name", "$l_name", "$selected_radio", "$email", "$city", "$zip_code", "$question")'; $result = mysql_query("$dbc", "$query") or die('Error with result'); echo '<span id="bold">Please check to see that the information submited is correct:</span>' . '<br />';echo '<span id="bold">Name:</span>' . " $f_name" . ' ' . " $l_name" .'<br />';if($selected_radio == "male") {echo '<span id="bold">Gender:</span>' . ' male' . '<br />';}else {echo '<span id="bold">Gender:</span>' . ' female' . '<br />';}echo '<span id="bold">Email:</span>' . " $email" .'<br />';echo '<span id="bold">City:</span>' . " $city" .'<br />';echo '<span id="bold">Zip Code:</span>' . " $zip_code" .'<br />';echo '<span id="bold">Answer To Question:</span>' . '<br />' . " $question" .'<br />'; mysql_close($dbc); ?> </body></html>

Link to comment
Share on other sites

Try removing the concatenation from your query like so: $query = 'INSERT INTO email (F_name, L_name, Gender, Email, City, Zip_code, Question) VALUES ("$f_name", "$l_name", "$selected_radio", "$email", "$city", "$zip_code", "$question")'; Also try unquoting: $result = mysql_query("$dbc", "$query"); and try mysqli_query($dbc, $query) instead.

Link to comment
Share on other sites

both of Don E.'s suggestions are valid. Given that, what have you done to determine where and what the problem could be? At the very least you should be debugging you code by adding print/echo statement's to trace the flow of code, determine if values are what you expect them to be, and checking for errors, especially in mysql_query. Turning error reporting on is also helpful.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...