OK. To sum up what I have: a database which holds news posts (email, author, date, subject, content). I have a page where you can modify the posts. To do this, i call a database query to grab all the info from the database. I want to use the select box to fill 5 text input boxes below with the data associated with the corresponding subject. I'm having a problem somewhere. The data in the text boxes doesn't change with the select box. Here's the code.
<?php
$connection = mysql_connect("localhost", "root", "");
mysql_select_db("moe", $connection);
if ($mod_submit)
{
mysql_query("UPDATE news WHERE post_number = $update_number SET subject = '$update_subject', email = '$update_email', author = '$update_name', the_date = '$pdate_date', content = '$update_content' ", $connection);
echo "News has been updated.";
}
else
{
$blank = "";
$pw_check = mysql_query("SELECT passID FROM admins WHERE userID='$user_check'", $connection);
list($passID) = mysql_fetch_row($pw_check);
$num_posts_query = mysql_query("SELECT post_number FROM news WHERE post_number < 500", $connection);
$num_posts = mysql_num_rows($num_posts_query);
if (!$pw_check || $passID != $password_check || $password_check == $blank || $user_check == $blank)
{
?>
<title>Login FAILED</title>
<body>
That username was not found, or the password is incorrect. Click <a href="login.php">here</a> to try again.
</body>
<?php
}
else
{
?>
<title>Login SUCCESSFUL</title>
<body>
You have been logged in successfully.<p>
Proceed to modify a news post.<p>
<?php
echo "(TEST) The current post number is $num_posts. (Tests to see if script connects to database properly.)<p>";
?>
<form action="mod.php" method="post">
<?php
$num_posts_query = mysql_query("SELECT post_number FROM news WHERE post_number < 5000", $connection);
$num_posts = mysql_num_rows($num_posts_query);
?>
<select name="pick" onChange = "update_number=form.pick.options[form.pick.selectedIndex].value;">
<?
$select_query = "SELECT * FROM news WHERE post_number < 5000";
$results = mysql_query($select_query, $connection);
while($row = mysql_fetch_array($results))
{
$subject_array[] = $row['subject'];
$content_array[] = $row['content'];
$date_array[] = $row['the_date'];
$author_array[] = $row['author'];
$email_array[] = $row['email'];
}
for ($counter = $num_posts; $counter >= 0; $counter--)
{
?>
<OPTION VALUE="<?php echo $counter; ?>"><?php echo "$subject_array[$counter]"; ?>
<?php
}
?>
</select>
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
<p><input type="text" name="update_subject" value="<?php echo "$subject_array[$update_number]"; ?>">
<p><input type="text" name="update_email" value="<?php echo "$email_array[$update_number]"; ?>">
<p><input type="text" name="update_name" value="<?php echo "$author_array[$update_number]"; ?>">
<p><input type="text" name="update_date" value="<?php echo "$date_array[$update_number]"; ?>">
<p><input type="text" name="update_content" value="<?php echo "$content_array[$update_number]"; ?>">
<p><input type="submit" name="mod_submit" value="Modify this post.">
</form>
</body>
<?php
}
}
?>
Basically, I want what's in the boxes to change each time I change the select box. Thanx in advanced. Oh, and something might be bogus in the UPDATE command too, see anything wrong? Thanks.
-Alex