Jump to content

Processing Drop-down menu info from a form with PHP?


woolyg

Recommended Posts

Hey all,

 

I have a simple form, with a dropdown menu as one of the sources of data.

Sources:

Title (textfield)

Group (dropdown menu)

Body (textfield)

 

 

In the processing PHP file, i connect to the db and specify

 

<?

$title = $_POST['title'];
$group = $_POST['group'];
$body = $_POST['body'];

$query="INSERT INTO documentation (title, group, body) VALUES ('$title', '$group', '$body')";
mysql_query($query) or die ("That did not work");

?> 

 

..but the problem lies in trying to insert the group dropdown selection into the DB - when I remove it from the insert command, the data inserts OK.

 

Have I used $_POST incorrectly?

 

Cheers,

Woolyg

Link to comment
Share on other sites

Change this line:

mysql_query($query) or die ("That did not work");

 

To:

 

mysql_query($query) or die (mysql_error());

 

So you can catch any errors if there is one. Double check your database tables spelling and any other spelling that might effect this.

 

If you get no errors, post your form code.

Link to comment
Share on other sites

Just get an error 1064 when I put in the mysql error handling - I know my syntax is incorrect..

 

Form code:

 

<body>
<form name="submitdoco" id="submitdoco" method="post" action="submitdoco.php">
  <table width="100%"  border="0">
    <tr>
      <td>Username here </td>
    </tr>
    <tr>
      <td><select name="group" class="pg" id="group">
        <option value="Rules" selected="selected">Rules</option>
        <option value="Club">Club</option>
        <option value="Other">Other</option>
      </select> 
      Subject Group </td>
    </tr>
    <tr>
      <td><input name="title" type="text" class="pg" id="title" size="40" maxlength="255" /> 
      Document Title </td>
    </tr>
    <tr>
      <td><input name="caption" type="text" class="pg" id="caption" size="40" maxlength="255" /> 
      Caption (for quick & easy search reference) </td>
    </tr>
    <tr>
      <td><textarea name="full_body" cols="120" rows="10" class="pg" id="full_body">Main document body goes here. Try to be consice and to the point.</textarea></td>
    </tr>
    <tr>
      <td><input name="Submit" type="submit" class="pg" value="Submit for publishing" /></td>
    </tr>
  </table>
</form>
</body>

 

 

And here's the processing PHP, after DB connection:

 

<?


$group = $_POST['group'];
$title = $_POST['title'];
$dts=time();
$timestamp=date('l M dS, Y, H:i:s');
$caption = $_POST['caption'];
$full_body = $_POST['full_body'];


$query = "INSERT INTO documentation (id, full_body, caption, timestamp, dts, title, group) VALUES ('null', '$full_body', '$caption', '$timestamp', '$dts', '$title', '$group')";
mysql_query($query) or die ("The document could not be added - ".mysql_errno()." - please contact the documentation administrator");
echo "Went in OK";

?>

 

For some reason it's not accepting the data from the dropdown part of the form. I've doublechecked all spelling..

Link to comment
Share on other sites

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.