Jump to content

[SOLVED] Php/Mysql DropDown ... (I'm sorry)


Recommended Posts

Hello,

First of all, I'm sorry for my bad English, I'm french, but I will do my best to correct my mistake.

 

I'm sorry if this question as been asked many and many time, but I searched on the forum and didn't find the answer... so I decided to post.

 

I only want to know the better and smallest way to insert in mysql a data from a dropdown.

 

If you didn't understand my question, tell me, I will try to rewrite it.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/147252-solved-phpmysql-dropdown-im-sorry/
Share on other sites

* Not tested *

 

This is a form that submits to itself and inserts your selected value into the fake table.

 

Let me know if you have any questions about the code  ;)

 

//include database connection here
if(isset($_POST['submit'])) {
   $name = mysql_real_escape_string($_POST['menu']);
   $sql = "INSERT INTO example(name) VALUES('$name') ";
   $result = mysql_query($sql) or die(mysql_error());
   if($result) {
      echo "successful!  you added $name into the database";
   } else {
      echo "failure...";
   }
}
?>
</pre>
<form action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>" method="POST">

  you
  me
  him
  her



<

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.