PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Jun 01, 2005 8:07 pm
Hi All,
The following code populates a Dropdown menu from the DB and now I wish to post these setting into another table. I'm guessing I need to somehow transform the Select statement into an input statement with a name. But i'm unsure on how to do this. Does anyone have any pointers?
TAI, Will.
Code: Select all
<?
include "../includes/functions.inc";
include "../includes/common_db.inc";
$link_id = db_connect($db_materials);
if(isset($_GET['commented']))
{
echo('Your comment has been posted.');
$link_id = db_connect($db_materials);
$category = $_GET['category'];
$colloPaperName = $_GET['colloPaperName'];
$sql_add = "INSERT INTO summary values('','$category','$paperName')";
mysql_query($sql_add) or die(mysql_error());
}
else {
?>
<form method='get' action='<? echo $_SERVER['PHP_SELF']; ?>'>
<input type='hidden' name='commented' value='set'>
<?
echo "<table class=\"materials\"><tr>";
$addSummary=array('Category','Paper Name');
$sumTitles = array(listCat1(),'paperName');
for($x = 0; $x<count($addSummary); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$addSummary[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"2\">$sumTitles[$x]</td></tr>\n";
}
?>
<tr><td width=\"200px\" colspan=\"2\" valign=\"top\"><input type='reset' class='btn' value='Reset'></td>
<td width=\"200px\" colspan=\"2\"><input type='submit' class='btn' value='Add'></td></tr>
</form></table>
<?
}
?>
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Wed Jun 01, 2005 8:58 pm
Okay, maybe I'm blind, but I can't see a SELECT in the code you posted...
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Wed Jun 01, 2005 9:00 pm
Or a dropdown menu, for that matter - are you sure you have posted the correct code?
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Jun 01, 2005 9:37 pm
Sorry.. Here's the function that create the Select etc
Code: Select all
function listCat() {
$sql_query = mysql_query("SELECT category, categoryId FROM aupapercategory");
echo "<select name=\"categoryId\">";
echo "<option value=\"\">-- Select Option --</option>";
while(list($catname, $categoryId)=mysql_fetch_array($sql_query)) {
$catname = stripslashes($catname);
echo "<option value=\"$categoryId\">$catname</option>";
}
echo "</select>";
mysql_free_result($sql_query);
}
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Wed Jun 01, 2005 11:09 pm
well, here is an example of something you could do with your function..
Code: Select all
<?php
function listCat(){
Global $catname, $categoryId;
$sql_query = mysql_query("SELECT category, categoryId FROM aupapercategory");
echo "<select name=\"categoryId\">";
echo "<option value=\"\">-- Select Option --</option>";
while($row=mysql_fetch_array($sql_query)) {
$catname = stripslashes($row['category']);
$categoryId = $row['categoryId'];
echo "<option value=\"$categoryId\">$catname</option>";
}
echo "</select>";
mysql_free_result($sql_query);
}
$sql = mysql_query("insert into mytable (myfield1, myfield2) VALUES ('".$catname."','".$categoryId."'")") or die(MySQL_Error());