Jump to content

How do i select a mysql database table for input using a drop down menu?


eddieblunt

Recommended Posts

Hi, i'm quite new to php and mysql and i am stuck with the following problem:

i want to create an admin section for a website which includes a page to add links to any one of the links pages

example:


if i set up 5 tables as below in a database called links

area1links
area2links
area3links
area4links
area5links

How would i insert new links to any of the links sections above by using a drop down menu to select the correct mysql database table?


i use this code to add links to a single page:

===========================================
[color=red]<?php
if(isset($_POST['save']))
{
    $name = $_POST['name'];
    $url = $_POST['url'];
    $description = $_POST['description'];
   
    if(!get_magic_quotes_gpc())
    {
        $name   = addslashes($name);
        $url   = addslashes($url);
        $description = addslashes($description);
    }
    include 'config.php';
    include 'opendb.php';
   
    $query = "INSERT INTO links (name, url, description) VALUES ('$name', '$url', '$description')";
    mysql_query($query) or die('Error ,query failed');
    include 'closedb.php';
   
    echo "Link - '$name' was added";
    }
?>[/color]
===========================================



hope that made sense and hope you can help?

Thanks,
Eddie
[code=php:0]
<?php
$area1=$_POST['area1'];
$area2=$_POST['area2'];
$area3=$_POST['area3'];
$area4=$_POST['area4'];
$area5=$_POST['area5'];

if (!empty($area1)){
//do your stuf here
}

if (!empty($area2)){
//do your stuff here
}

if (!empty($area3)){
//do your stuff here
}

if (!empty($area4)){
//do your stuff here
}

if (!empty($area5)){
//do your stuff here
}

?>
[/code]

Just create the drop down that fills those variables and it will work.
Thanks, can you show me how i should integrate that with my current code?

i tried this with 2 links database tables [b]links-uk [/b] and [b]links-new[/b], it didn't submit the info to the database tables?

================================================================
[color=red]<body>

<?php
if(isset($_POST['save']))
{
      $name = $_POST['name'];
      $url = $_POST['url'];
      $description = $_POST['description'];
      $linksnew = $_POST['linksnew'];
      $linksuk = $_POST['linksuk'];
   
    if(!get_magic_quotes_gpc())
    {
      $name  = addslashes($name);
      $url  = addslashes($url);
      $description = addslashes($description);
    }
    include 'config.php';
    include 'opendb.php';
   
if (!empty($linksnew)){
    $query = "INSERT INTO ($links-new) (name, url, description) VALUES ('$name', '$url', '$description')";
    mysql_query($query) or die('Error ,query failed');
}

if (!empty($linksuk)){
    $query = "INSERT INTO ($links-uk) (name, url, description) VALUES ('$name', '$url', '$description')";
    mysql_query($query) or die('Error ,query failed');
}


    include 'closedb.php';
   
    echo "Link - '$name' was added";
    }
?>

</p>
<form method="post">
  <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
    <tr>
      <td align="right" class="unnamed1">Section</td>
      <td class="unnamed1"><select>
        <option value="linksnew">New</option>
        <option value="linksuk">UK</option>
                                      </select>
      </td>
    </tr>
    <tr>
      <td align="right" class="unnamed1">Site Name </td>
      <td class="unnamed1"><input name="name" type="text" class="box" id="name" size="40"></td>
    </tr>
    <tr>
      <td width="100" align="right" class="unnamed1">URL</td>
      <td class="unnamed1"><input name="url" type="text" class="box" id="url" value="http://" size="40"></td>
    </tr>
    <tr>
      <td width="100" align="right" valign="top" class="unnamed1">Description</td>
      <td class="unnamed1"><textarea name="description" cols="50" rows="10" class="box" id="description"></textarea></td>
    </tr>
    <tr>
      <td width="100" class="unnamed1">&nbsp;</td>
      <td class="unnamed1">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" class="unnamed1"><input name="save" type="submit" class="box" id="save" value="Add Link"></td>
    </tr>
  </table>
</form>

</body>[/color]
================================================================

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.