eddieblunt Posted December 4, 2006 Share Posted December 4, 2006 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 pagesexample:if i set up 5 tables as below in a database called linksarea1linksarea2linksarea3linksarea4linksarea5linksHow 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]<?phpif(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 Link to comment https://forums.phpfreaks.com/topic/29447-how-do-i-select-a-mysql-database-table-for-input-using-a-drop-down-menu/ Share on other sites More sharing options...
jcbarr Posted December 4, 2006 Share Posted December 4, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/29447-how-do-i-select-a-mysql-database-table-for-input-using-a-drop-down-menu/#findComment-135188 Share on other sites More sharing options...
eddieblunt Posted December 5, 2006 Author Share Posted December 5, 2006 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><?phpif(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"> </td> <td class="unnamed1"> </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]================================================================ Link to comment https://forums.phpfreaks.com/topic/29447-how-do-i-select-a-mysql-database-table-for-input-using-a-drop-down-menu/#findComment-135664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.