Problem with a <select> option in a PHP form.
Posted: Sat May 15, 2004 1:46 pm
First of all I would like to say hello, since this is my first post in this forum. And having said that I go straight to my problem. I am experimenting with PHP and MySQL to make an activities posting module.
The code of the admin section goes like this:
My problem lies with the INSERT query where I can't seem to insert the value in the first table "category_id" with the variable $id. Everything else seems to be working-if i don't inlude that table.
Can anyone give me any ideas on how to fix this?
Thanks again for any help
The code of the admin section goes like this:
Code: Select all
<?php
include("db\db.inc");
if($Send && $Password==$EntryPassword)
{
$DatabasePointer = mysql_connect($DatabaseHost, $DatabaseUser, $DatabasePassword);
mysql_select_db($Database, $DatabasePointer);
if($NewsDelete)
{
mysql_query("DELETE FROM $TableNews WHERE ID='$ID'", $DatabasePointer);
}
if($NewsInsert)
{
$date = date("Y-m-d H:i:s");
mysql_query("INSERT INTO $TableNews (category_id, title, description, html, user, date) VALUES ('$id', '$title', '$description', '$html', '$user', '$date')", $DatabasePointer);
}
echo"<table bgcolor="#CCAE9F" border="0" cellpadding="2" cellspacing="1">",
"<form action="$PHP_SELF" method="post">",
"<input name="Password" type="hidden" value="$Password">",
"<input name="NewsInsert" type="hidden" value="1">",
"<tr>",
"<td>Τίτλος</td>",
"<td><input name="title" type="text"></td>",
"</tr>",
"<tr>",
"<td>Κείμενο</td>",
"<td><textarea cols="40" name="description" rows="5"></textarea></td>",
"</tr>",
"<tr>",
"<td>Κατηγορία</td>",
"<td>";
{
$sql = mysql_query("SELECT category, cat_id FROM activities_cat");
echo "<select name="id">";
while(list($category, $cat_id)=mysql_fetch_array($sql)){
$category = stripslashes($category);
echo "<option value="$cat_id">$category</option>";
}
echo "</select>";
mysql_free_result($sql);
// $sql=NULL; άδειασμα της μεταβλητής από τη μνήμη
}
echo"</td>",
"</tr>",
"<tr>",
"<td>html</td>",
"<td><input name="html" type="text"></td>",
"</tr>",
"<tr>",
"<td>Χρήστης</td>",
"<td><input name="user" type="text"></td>",
"</tr>",
"<tr>",
"<td colspan="2"><input name="Send" type="submit" value="Εισαγωγή"></td>",
"</tr>",
"</form>",
"</table><br><br>";
echo "$sql <br>";
echo "$id";
//Εδώ ξεκινά η εμφάνιση των ήδη δημοσιευμένων άρθρων
echo"<h4>The latest $MaxNews News Articles:</h4><br><br>";
$ResultPointer = mysql_query("SELECT ID, title, description, html, user, date FROM $TableNews ORDER BY date DESC LIMIT $MaxNews", $DatabasePointer);
if(mysql_num_rows($ResultPointer)>0)
{
for($i=0; $i<mysql_num_rows($ResultPointer); $i++)
{
$Result = mysql_fetch_object($ResultPointer);
echo"<table bgcolor="#A6A681" border="0" cellpadding="2" cellspacing="1">",
"<tr>",
"<td><b>",
$Result->title,
"</b></td>",
"<td align="right"><b><i>",
substr($Result->date, 8, 2) . "." . substr($Result->date, 5, 2) . "." . substr($Result->date, 0, 4) . substr($Result->date, 10, 6),
"</i></b></td>",
"</tr>",
"<tr>",
"<td colspan="2">",
nl2br($Result->description),
"</td>",
"</tr>",
"<tr>",
"<td>";
if(!Empty($Result->html))
{
echo"<a href="http://",
$Result->html,
"" target=_blank>Περισσότερα...</a>";
}
else
{
echo" ";
}
echo"</td>",
"<td align="right"><i>author ",
$Result->user,
"</i></td>",
"</tr>",
"<tr>",
"<form action="$PHP_SELF" method="post">",
"<input name="Password" type="hidden" value="$Password">",
"<input name="NewsDelete" type="hidden" value="1">",
"<input name="ID" type="hidden" value="",
$Result->ID,
"">",
"<td colspan="2"><input name="Send" type="submit" value="Διαγραφή!!"></td>",
"</form>",
"</tr>",
"</table><br><br>";
}
}
else
{
echo"No news is good news ";
}
}
else
{
?>
<form action="<?php echo$PHP_SELF; ?>" method="post">
<table border="0">
<tr>
<td>Κωδικός</td>
<td><input name="Password" size="10" type="password"></td>
</tr>
<tr>
<td align="center" colspan="2"><input name="Send" type="submit" value="Είσοδος"></td>
</tr>
</table>
</form>
?>Can anyone give me any ideas on how to fix this?
Thanks again for any help