|
Posted by guitarromantic on 05/11/06 02:45
Hey everyone,
I run a site with staff-submitted reviews, and most of them are written
by one author. However, we also do "multiple" reviews. Up until now I
just had a userid for a 'Multiple' account and submitted them under
that, but this makes it harder to print lists of all the reviews by one
person, so ideally I wanna make a multiple select form so we can just
select all the contributors and have the values saved in the database -
in one row (something like "56,34,21" etc).
I've coded a multiple select form with all the authors of articles for
my site on, and I want to store the results of this in one row so I can
grab them as an array later - how can I go about doing this? I just
googled and came across using <select name="author[]"> in my HTML, and
then using serialize() to process it, but it fails. When I run the
following code, the value for 'multiplearray' remains at 0 whether I
select single OR multiple values on the form:
<?php
$dbhost = ###
$dbuser = ###
$dbpass = ###
$dbname = ###
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');
mysql_select_db($dbname);
if(isset($_POST['save']))
{
$author = serialize($_POST['author']);
$query = "INSERT INTO review_test (multiplearray) VALUES
('$author')";
mysql_query($query) or die('Error ,query failed');
echo "Query successful!";
}
echo "<form name='test' method='post' action=''>";
$query2 = "SELECT Staff_id, displayname FROM users WHERE
userlevel !=0
ORDER BY username";
$result2 = mysql_query($query2) or die('Error : ' .
mysql_error());
echo "<select name='author[]' id='author[]' multiple='multiple'
size='10'>";
while($row2 = mysql_fetch_array($result2, MYSQL_NUM))
{
list($Staff_id, $displayname) = $row2;
echo "<option value='$Staff_id'>$displayname</option>";
}
echo "</select>";
echo "<br><br><input name='save' type='submit' id='save' value='Post
Review'>";
echo "</form>";
?>
-----
Matt
Navigation:
[Reply to this message]
|