mike12255 Posted March 3, 2009 Share Posted March 3, 2009 So im trying to grab data from a form and throw it into my database but its telling me the query was empty below ill post the form and then the insertpost.php file. The form: <!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=UTF-8" /> <title>Have a Question?</title> <style type="text/css"> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; } body { background-color: #FFFFFF; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .style2 { font-size: 16px; font-weight: bold; } --> </style></head> <body> <div align="center"> <p><img src="../banner.gif" width="778" height="130" /><br /> </p> <table width="780" border="0" cellpadding="5" cellspacing="5"> <tr> <td><div align="center" class="style2">Have a question about Stayner?</div></td> </tr> <tr> <td><form id="form1" name="form1" method="post" action="insertquestion.php"> <p><strong> Ask your question here:</strong><br /> <br /> Your Name : <label> <input type="text" name="name" id="name" /> </label> </p> <p>Question Subject: <input type="text" name="subject" id="subject" /> <br /> <br /> Email : <label> <input type="text" name="email" id="email" /> </label> <br /> <br /> Question: <label> <br /> <textarea name="question" id="question" cols="45" rows="5"></textarea> </label> <br /> <br /> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> <label> <input type="reset" name="reset" id="reset" value="Reset" /> </label> </p> </form> </td> </tr> </table> <p><br /> </p> </div> </body> </html> The insertpost.php: <?php include ("connect.php");//Connect to the database $thedate=date("U"); //get unix timestamp $displaytime=date("F j, Y, g:i a");//Convert UNIX timestamp to something readable // lets get the variables from the form $subject=$_POST['subject']; $name=$_POST['name']; $yourpost=$_POST['question']; //the Strip_tags ensures that people cannot insert code into your website - its secruity $name = strip_tags($name); $subject = strip_tags($subject); $yourpost = strip_tags($yourpost); //the mysql_real_escape_string protects our database - so if they enter a mysql command its ignored. $name = mysql_real_escape_string($name); $subject = mysql_real_escape_string($subject); $yourpost = mysql_real_escape_string($yourpost); $displayetime = mysql_real_escape_string($displayetime); $thedate = mysql_real_escape_string($thedate); // Lest insert this stuff into the database $insertpost="INSERT INTO forumtutorial_posts(answered,author,title,post,showtime,realtime,lastposter) values('0','$name','$subject','$yourpost','$displaytime','$thedate','$name')"; $post = mysql_query($insertport) or die (mysql_error()); if ($post){ header("Location: index.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/147811-solved-query-empty/ Share on other sites More sharing options...
Philip Posted March 3, 2009 Share Posted March 3, 2009 $insertport is what you're trying to call, it should be $insertpost Link to comment https://forums.phpfreaks.com/topic/147811-solved-query-empty/#findComment-775845 Share on other sites More sharing options...
Maq Posted March 3, 2009 Share Posted March 3, 2009 And your form is posting to: action="insertquestion.php"> while you're showing us The insertpost.php: Link to comment https://forums.phpfreaks.com/topic/147811-solved-query-empty/#findComment-775855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.