Unholy Prayer Posted January 14, 2007 Share Posted January 14, 2007 I'm trying to make a support script where users send in a form that's added to the database. The page is working perferctly, other than the fact that it doesn't insert the info into the database and the message doesn't appear. Can someone help me? This is my code:[code]<? include('styles/default/header.tpl');include('styles/default/navigation.tpl');require_once('config.php');//initilize PHPif(isset($_POST['submit'])){ $username = $_POST['username']; $email = $_POST['email']; $content = $_POST['content']; MYSQL_QUERY("INSERT INTO support (username,email,content)". "VALUES ('$username', '$email', '$content')"); echo "Thank you for your submission. A support representative will help you shortly."; }?><td class="content"><table align="center" cellspacing="1" cellpadding="1" border="0"><tr><form action="support.php" method="POST"><td align="center" colspan="2">Submit a Support Request</td></tr><tr><td align="right">Your Username:</td><td align="left"><input type="text" name="username" size="30"></tr><tr><td align="right">Email Address:</td><td align="left"><input type="text" name="email" size="30"></tr><tr><td align="right">What are you having trouble with?</td><td align="left"><textarea name="content" cols="25" rows="5"></textarea></td></tr><tr><td align="center" colspan="2"><input type="submit" value="submit"></td></tr></table></td><?phpinclude('styles/default/footer.tpl');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/ Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 Instead of:[code]MYSQL_QUERY("INSERT INTO support (username,email,content)". "VALUES ('$username', '$email', '$content')");[/code]try:[code]MYSQL_QUERY("INSERT INTO support (username,email,content)". "VALUES ('$username', '$email', '$content')") or die (mysql_error());[/code]and tell us what you get.regards Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/#findComment-160216 Share on other sites More sharing options...
Unholy Prayer Posted January 14, 2007 Author Share Posted January 14, 2007 I insert the info into the text fields and hit the submit button but the error doesn't show up or anything else. It just resets the form. Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/#findComment-160217 Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 I dont think you have ended the form tag </form>Not sure if that is causing it though.. Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/#findComment-160221 Share on other sites More sharing options...
Unholy Prayer Posted January 14, 2007 Author Share Posted January 14, 2007 I noticed that also but I added it into my code and it still didn't fix it. Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/#findComment-160327 Share on other sites More sharing options...
Philip Posted January 14, 2007 Share Posted January 14, 2007 Try this:[code]<?phpinclude('styles/default/header.tpl');include('styles/default/navigation.tpl');require_once('config.php');//initilize PHPif(isset($_POST['submit'])){ $username = $_POST['username']; $email = $_POST['email']; $content = addslashes($_POST['content']); $query = mysql_query("INSERT INTO `support` (`username`, `email`, `content`) VALUES ('".$username."', '".$email."', '".$content."')") or die(mysql_error()); if($query) { echo "Thank you for your submission. A support representative will help you shortly."; } else { echo "Problem adding submission."; }} else { ?> <td class="content"><form action="support.php" method="POST"> <table align="center" cellspacing="1" cellpadding="1" border="0"> <tr> <td align="center" colspan="2">Submit a Support Request</td> </tr><tr> <td align="right">Your Username:</td> <td align="left"><input type="text" name="username" size="30"> </tr><tr> <td align="right">Email Address:</td> <td align="left"><input type="text" name="email" size="30"> </tr><tr> <td align="right">What are you having trouble with?</td> <td align="left"><textarea name="content" cols="25" rows="5"></textarea></td> </tr><tr> <td align="center" colspan="2"><input type="submit" name="submit" value="submit"></td> </tr> </table> </form></td> <?php}include('styles/default/footer.tpl');?>[/code]I added a few things to it, but the reason it wasn't working was because you didn't have a name="submit" on the submit button. Then when you hit submit, your PHP was looking for an input with the name "submit" Quote Link to comment https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/#findComment-160342 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.