Jump to content

dropdown menu for select different table


vaskovasilev

Recommended Posts

Hello ,

I have one database with 6 same structure tables (only with different names).

I want to put one dropdown menu to choose in wich table to insert the data .

I have this code :

 

 

<form action="" method="post">

<select name="dropdown">

<option>business</option>

<option>design</option>

<option >entertainment</option>

<option >it</option>

<option >lifestyle</option>

<option >press</option>

 

</select>

<input class="input_text" type="text" name="name">

<input class="input_text" type="text" name="mail">

<input class="input_text" type="text" name="address">

<textarea class="input_textarea" name="comment"></textarea>

<input type="submit" name="submit" value="Изпрати" class="button">

</form>

<?php

if (isset($_POST["submit"])) {

$dbhost = "localhost";

$dbuser = "";

$dbpass = "";

$dbname = "";

$conn = mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error());

mysql_select_db($dbname, $conn)or die(mysql_error());

if (!empty($_POST["name"])) $name = htmlspecialchars($_POST["name"]);

else $errMsg = " <a class=maintext2><font color=#000000>please write name!</font></a><br />";

if (!empty($_POST["mail"])) $mail = htmlspecialchars($_POST["mail"]);

else $errMsg = "<a class=maintext2><font color=#000000>please write e-mail!</font></a><br />";

if (!empty($_POST["address"])) $address = htmlspecialchars($_POST["address"]);

else $errMsg = "<a class=maintext2><font color=#000000>please write address!</font></a><br />";

if (!empty($_POST["comment"])) $comment = htmlspecialchars($_POST["comment"]);

else $errMsg = "<a class=maintext2><font color=#000000>please write message!</font></a><br />";

if (empty($errMsg)) {

$insert = mysql_query("INSERT INTO $dropdown(name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error());

echo '<a class=maintext2><font color=#000000> message send!</font></a><br />';

} else echo $errMsg;

mysql_close();

}

?>

 

Can you help me with this code ?

thank you

you want to say this :

 

$insert = mysql_query("INSERT INTO $_POST['dropdown'] (name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error());

 

or not :)

because now it says :

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/biznes/admin.php  on line 73 .. the line where is $_POST

.. i made it with case :)

 

switch ($_POST['dropdown'])

{

case "business":

$insert = mysql_query("INSERT INTO table (name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error());

break;

....

}

 

 

so thank you for the idea :)

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.