Jump to content

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


icez

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



<

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.