Deanznet Posted August 13, 2009 Share Posted August 13, 2009 Okay I got a drop down box and it grabs tables from mysql and list. now i need to post from it. heres the code <?php $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo "<select name=Field>"; while ($row= mysql_fetch_row($result)) { echo "<option value={$row[0]}>{$row[0]}</option>"; } echo "</select>"; ?> That works fine but $cat = $_POST['Field']; Dose not work.. Understand? Second problem is my php script to create Tables in mysql works only with single words so if i do Cow it will work but if i do Big Cow i get this error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Cow ( `id` int(255) NOT NULL default '0', `Product` varchar(32) NOT NULL d' at line 1 <? include("conn.php"); if($_POST['submit']) //If submit is hit { $name= $_POST['catname']; // Create a MySQL table in the selected database mysql_query("CREATE TABLE IF NOT EXISTS $name ( `id` int(255) NOT NULL default '0', `Product` varchar(32) NOT NULL default '', `Cat` varchar(32) NOT NULL default '', `Info` text NOT NULL, `Paypal code` text NOT NULL, `Img1` varchar(50) NOT NULL default '', `Img2` varchar(50) default NULL, `Img3` varchar(50) default NULL, `Img4` varchar(50) default NULL, `Img5` varchar(50) default NULL, `Img6` varchar(50) default NULL )") or die(mysql_error()); } header("Location: newcat.php"); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/170008-2-quick-problems-posting-info-from-drop-down-box/ Share on other sites More sharing options...
jhyatt1271 Posted August 13, 2009 Share Posted August 13, 2009 You need to put your select boxes in a form and send to a processer like your second set of code. I would put them all on the same page like the following. <?php include("conn.php"); if($_POST['submit']) //If submit is hit proccess the form else display the form { $name= $_POST['catname']; // Create a MySQL table in the selected database mysql_query("CREATE TABLE IF NOT EXISTS $name ( `id` int(255) NOT NULL default '0', `Product` varchar(32) NOT NULL default '', `Cat` varchar(32) NOT NULL default '', `Info` text NOT NULL, `Paypal code` text NOT NULL, `Img1` varchar(50) NOT NULL default '', `Img2` varchar(50) default NULL, `Img3` varchar(50) default NULL, `Img4` varchar(50) default NULL, `Img5` varchar(50) default NULL, `Img6` varchar(50) default NULL )") or die(mysql_error()); } else { $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo "<form action=".$_SERVER['PHP_SELF'].">"; // Here is where your the form starts and defines where to process the input. echo "<select name='Field'>"; while ($row= mysql_fetch_row($result)) { echo "<option value={$row[0]}>{$row[0]}</option>"; } echo "</select>"; //Now lets add a Submit button and close the form. echo " <input type='submit' value='Submit' name='Submit'> </form> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170008-2-quick-problems-posting-info-from-drop-down-box/#findComment-896906 Share on other sites More sharing options...
Deanznet Posted August 13, 2009 Author Share Posted August 13, 2009 Ya i understand but you mixing the 2 problems up.. First problem is have a drop down and i need help getting the information from the post. You know if i have a text box names catname and i hit submit to go to process php i will have $name= $_POST['catname']; so i can echo $name and it will echo what ever was posted.. How do i do that with the drop down box? Quote Link to comment https://forums.phpfreaks.com/topic/170008-2-quick-problems-posting-info-from-drop-down-box/#findComment-896929 Share on other sites More sharing options...
Deanznet Posted August 13, 2009 Author Share Posted August 13, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/170008-2-quick-problems-posting-info-from-drop-down-box/#findComment-896989 Share on other sites More sharing options...
jhyatt1271 Posted August 14, 2009 Share Posted August 14, 2009 I dont know what I was thinking that code wouldnt even post the info into sql anyway Change this $name= $_POST['catname']; To $name= $_POST['Field']; OR Change this echo "<select name='Field'>"; to echo "<select name='catname'>"; Final code should be this if you changed the select name to "catname" <?php if($_POST['submit']) //If submit is hit proccess the form else display the form { $name= $_POST['catname']; echo "Name = ".$name; } else { $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo "<form action=".$_SERVER['PHP_SELF'].">"; // Here is where your the form starts and defines where to process the input. echo "<select name='Field'>"; while ($row= mysql_fetch_row($result)) { echo "<option value={$row[0]}>{$row[0]}</option>"; } echo "</select>"; //Now lets add a Submit button and close the form. echo " <input type='submit' value='Submit' name='submit'> </form> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170008-2-quick-problems-posting-info-from-drop-down-box/#findComment-897814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.