Zigster316 Posted August 18, 2007 Share Posted August 18, 2007 I am using a server that has MySQL v4.1 and my code is supposed to take data entered into an HTML for and insert it into a database. All that is happening though is that I am only having on field fill out and that is my person id which isn't retrieved from the form. Any ideas?! Here is the whole code(with php) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Form Output</title> </head> <body> <?php include("header.php"); ?> <?php $con=mysql_connect ("localhost", "prince_Prince", "password");//not real password for security if (!$con) { die('Could not connect: ' . mysql_error()); } $name = mysql_real_escape_string($_POST["name"]); $gender = mysql_real_escape_string($_POST["gender"]); $email = mysql_real_escape_string($_POST["email"]); $comments = mysql_real_escape_string($_POST["comments"]); mysql_query("INSERT INTO `emails` (`Name`, `Gender`, `Email`, `Comments`) VALUES ('$name', '$gender', '$email', '$comments')"); mysql_close($con); ?> <?php $name = $_REQUEST['name']; $email = $_REQUEST['email']; $subject = $_REQUEST['subject']; $age = $_REQUEST['age']; $gender = $_REQUEST['gender']; $comments = $_REQUEST['comments']; $to = "ziggy6005@gmail.com"; $subject = "$subject"; $message = "$name $email $gender $comments"; mail($to,$subject,$message); echo "Thank you $name. I have now received an email containing the following information: <br/> Name: $name <br/> Email: $email <br/> Email Subject: $subject <br/> Age: $age <br/> Gender: $gender <br/> Comments: $comments"; ?> <?php include ("footer.php"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/ Share on other sites More sharing options...
AndyB Posted August 18, 2007 Share Posted August 18, 2007 I suppose we need to see the form - just the form not a whole bunch of html. Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/#findComment-327808 Share on other sites More sharing options...
Zigster316 Posted August 18, 2007 Author Share Posted August 18, 2007 The form code is: <form action="handle_form.php" method="post"> <fieldset><legend>Suggestions Form</legend> <p><b>Name:</b><input type="text" name="name" maxlength="40"></p> <p><b>Email:</b><input type="text" name="email" maxlength="60"></p> <p><b>Email Subject:</b><input type="text" name ="subject" maxlength="40"></p> <p><b>Gender:</b><input type="radio" name="gender" value="M">M <input type="radio" name="gender" value="F">F</p> <p><b>Age:</b><select> <option value ="012">0-12</option> <option value ="1320">13-20</option> <option value ="2140">21-40</option> <option value ="4060">40-60</option> <option value ="61over">61+</option> </select></p> <p><b>Comments:</b><textarea name="comments" rows="5" cols="40"></textarea></fieldset> <center><input type="submit" value="Submit"> Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/#findComment-327811 Share on other sites More sharing options...
AndyB Posted August 19, 2007 Share Posted August 19, 2007 I see host, username, and password in the connection, but I don't see anything that selects the database you want to use (database, not the table) Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/#findComment-327835 Share on other sites More sharing options...
js_280 Posted August 19, 2007 Share Posted August 19, 2007 Try this to see what errors you get... mysql_select_db("Database Name Goes Here", $con); mysql_query("INSERT INTO `emails` (`Name`, `Gender`, `Email`, `Comments`) VALUES ('$name', '$gender', '$email', '$comments')") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/#findComment-327838 Share on other sites More sharing options...
Zigster316 Posted August 19, 2007 Author Share Posted August 19, 2007 Andy you got the problem right! I forgot a database select query! Now I have the query in there and it works! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/65633-solved-why-isnt-it-working/#findComment-327848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.