Forum Moderators: coopster

Message Too Old, No Replies

Im in a muddle...

running a sql when a form drop down is changed

         

dj_lysuc

9:36 pm on Mar 9, 2004 (gmt 0)

10+ Year Member




mysql_select_db("Office",$dbcon)or die("Sorry, the database is unavailable.<BR><BR>".mysql_error());
$result = mysql_query( "SELECT * FROM users WHERE name='$user'" );
$row = mysql_fetch_object($result);
<form action="update.php" method="post">
<select name="reports">
<? if ($row->Team1 == "1") {?> <option>Team1</option>
<? } if ($row->Team2 == "1") {?> <option>Team2</option>
<? } if ($row->team3 == "1") {?> <option>Team3</option>
<? }?>
</select><br>
<input type="button" name="Button1" value="Go" onClick="?"><br>
<?
$result2 = mysql_query( "SELECT * FROM weeklyinfo WHERE team='?'" );
$row2 = mysql_fetch_object($result2);
?>
Person1: <input type="text" name="week1" value="<? echo$row2->week1;?>"><br>
Person2: <input type="text" name="week2" value="<? echo$row2->week2;?>"><br>
<input type="Submit" value="Update">
</form>

Sorry, im new to php and getting in a right muddle. I may be going about this in the wrong way but basicaly im trying to make a page to update a mysql table but with a dropdown to retieve a certain row of data and enable me to update that row.

In the code above I have a drop down list (reports) that changes depending on the user logged on, this is working on my test page. But im not sure how to get the last two input fields to display the correct row of data depending on the drop down option. Also when the update button is hit, I need to update that same row.

Any help will be great! Thanx.

stargeek

1:02 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



I may be missunderstanding, but what you are talking about sounds like a job for javascript, since normally there is no client-server communication while a user is filling out a form.
You could use PHP to load a javascript array up with all the possible values of the input box. then you could call a javascript function from the dropdown's onChange event that would select the correct value from the array and set the value of the input boxes equal to it.
Does this sound like i understand what you're saying?
HTH

dj_lysuc

4:43 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



stargeek, that sounds like what I am looking for, I didnt try an array and not too sure how to do it. I did try and play around with a function with document.week1.value and document.week2.value but couldnt seem to get it to work with the php code and update properly. Can you explian your method with the array and how best to code this. Thanx.