Last couple days I've had a few problems. I have a select box, with different values. I'm using a JS script so that each time you change the select box it updates 5 other text boxes. Can anyone see what's wrong? Been working on this a day or two. I think the update command is wrong too, but right now if I could get the boxes changing that would be nice.
<?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>
<head>
<SCRIPT LANGUAGE="JavaScript">
function ChangeTheValues()
{
var txtSubject = document.TheForm.TheSelectBox.options[document.TheForm.TheSelectBox.selectedIndex].value
<?php
for ($count = $num_posts; $count >= 1; $count--)
{
?>
if (txtSubject == "<?php echo "$count"; ?>")
{
document.TheForm.update_subject.value = "<?php echo "$subject_array[$count]"; ?>"
document.TheForm.update_name.value = "<?php echo "$name_array[$count]"; ?>"
document.TheForm.update_email.value = "<?php echo "$email_array[$count]"; ?>"
document.TheForm.update_content.value = "<?php echo "$content_array[$count]"; ?>"
document.TheForm.update_date.value = "<?php echo "$date_array[$count]"; ?>"
}
<?php
}
?>
}
</SCRIPT>
</head>
<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 name = "TheForm" 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="TheSelectBox" onChange = "ChangeTheValues();">
<?
$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'];
$name_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">
<p><input type="text" name="update_email">
<p><input type="text" name="update_name">
<p><input type="text" name="update_date">
<p><input type="text" name="update_content">
<p><input type="submit" name="mod_submit" value="Modify this post.">
</form>
</body>
<?php
}
}
?>
All help appreciated. Thanks.