Jump to content

Recommended Posts

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 PHP

if(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>
<?php
include('styles/default/footer.tpl');
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34082-help-with-mysql_query-insert-into/
Share on other sites

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
Try this:
[code]<?php
include('styles/default/header.tpl');
include('styles/default/navigation.tpl');

require_once('config.php');
//initilize PHP

if(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"
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.