Page 1 of 1

Problem with a <select> option in a PHP form.

Posted: Sat May 15, 2004 1:46 pm
by n3m0
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:

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>&#932;&#943;&#964;&#955;&#959;&#962;</td>",
		"<td><input name="title" type="text"></td>",
		"</tr>",
		"<tr>",
		"<td>&#922;&#949;&#943;&#956;&#949;&#957;&#959;</td>",
		"<td><textarea cols="40" name="description" rows="5"></textarea></td>",
		"</tr>",
		"<tr>",
		"<td>&#922;&#945;&#964;&#951;&#947;&#959;&#961;&#943;&#945;</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; &#940;&#948;&#949;&#953;&#945;&#963;&#956;&#945; &#964;&#951;&#962; &#956;&#949;&#964;&#945;&#946;&#955;&#951;&#964;&#942;&#962; &#945;&#960;&#972; &#964;&#951; &#956;&#957;&#942;&#956;&#951;
}
		echo"</td>",
		"</tr>",
		"<tr>",
		"<td>html</td>",
		"<td><input name="html" type="text"></td>",
		"</tr>",
		"<tr>",
		"<td>&#935;&#961;&#942;&#963;&#964;&#951;&#962;</td>",
		"<td><input name="user" type="text"></td>",
		"</tr>",
		"<tr>",
		"<td colspan="2"><input name="Send" type="submit" value="&#917;&#953;&#963;&#945;&#947;&#969;&#947;&#942;"></td>",
		"</tr>",
		"</form>",
		"</table><br><br>";
echo "$sql <br>";
echo "$id";

//&#917;&#948;&#974; &#958;&#949;&#954;&#953;&#957;&#940; &#951; &#949;&#956;&#966;&#940;&#957;&#953;&#963;&#951; &#964;&#969;&#957; &#942;&#948;&#951; &#948;&#951;&#956;&#959;&#963;&#953;&#949;&#965;&#956;&#941;&#957;&#969;&#957; &#940;&#961;&#952;&#961;&#969;&#957;
	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>&#928;&#949;&#961;&#953;&#963;&#963;&#972;&#964;&#949;&#961;&#945;...</a>";
			}
			else
			{
				echo"&nbsp;";
			}
			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="&#916;&#953;&#945;&#947;&#961;&#945;&#966;&#942;!!"></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>&#922;&#969;&#948;&#953;&#954;&#972;&#962;</td>
  <td><input name="Password" size="10" type="password"></td>
 </tr>
 <tr>
  <td align="center" colspan="2"><input name="Send" type="submit" value="&#917;&#943;&#963;&#959;&#948;&#959;&#962;"></td>
 </tr>
</table>
</form>

?>
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 ;)

Posted: Sun May 16, 2004 6:43 am
by ghost007
hi,

you should try to use '$ID' in your insert statement instead of '$id'.

hope this helps

siech