Page 1 of 1

[SOLVED] Form to form problem - please help!

Posted: Tue Jul 06, 2004 9:42 am
by eatmyshorts
Brief description of forms:

First form: Administrator can view members usernames and choose from drop down list.

Second Form: Take selected value from first form and view contents of the row based on the selected username while being able to replace any data that is within those fields, which when submitted updates the fields.

Problem:

I can't seem to get the selected value from the first form to go into the second form. I have tried hidden fields, $_POST, etc. I'm not really good with php - most times it's all trial and error.

Here is the first form, viewm.php:

Code: Select all

<? $sql="SELECT userID, username FROM $db_table"; 
$result=mysql_query($sql); 

$options=""; 

while ($row=mysql_fetch_array($result)) { 

    $id=$row["userID"]; 
    $viewmember=$row["username"]; 
    $options.="<OPTION VALUE="$id">".$viewmember; 
} 
?> 
<form action="viewm2.php" method="post">
  <table width="450" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr valign="bottom"> 
      <td width="216"><blockquote>
        <p>Member Name:</font></p>
      </blockquote></td>
      <td width="234" valign="top"> 
        <select name="viewmember">
		<option value=0>Choose
		<? echo $options ?></option>
        </select></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td></td>
      <td> <br>
	  <input name="Submit" type="image" src="../../../images/viewmprofilesm.png" width="171" height="34">
	  <BR>
        <input type="hidden" name="Submit" value="View Member">
      </td>
    </tr>
  </table>
</form>
In the second form, viewm2.php, i have my sql queries and such working "correctly" but it's constantly pulling the last entry from the database instead of the submitted value from the first form.

How can I correctly pass the viewmember value to my second form?

Thanks!


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jul 06, 2004 10:13 am
by feyd
Looks more like an error in your html output, than anything else..

Posted: Tue Jul 06, 2004 10:17 am
by launchcode
Post your second script here too.

Posted: Tue Jul 06, 2004 11:01 am
by eatmyshorts
ok and sorry about the php codes. I'm not real good at this... I think I messed up the code because now after I choose a member name I get a blank page so I'm starting from scratch again with:

Code: Select all

<?php $link = mysql_connect($db_host,$db_user,$db_passwd);

if (!$link) {

echo "Could not connect to sql server ";

}

$select = mysql_select_db($db_database);

if (!$select) {

echo "Could not select database";

}

$sql = "SELECT * FROM $db_table WHERE username='$viewmember' ";

$query = mysql_query($sql,$link);


while ($vrow = mysql_fetch_array($query) ) {

if ($vrow[mailing] == 1) {

$list = "Yes";
$vlist = "Yes&nbsp;<input type="radio" name="mailing" value="1" checked>&nbsp; No&nbsp;<input type="Radio" name="mailing" value="0">";
}

if ($vrow[mailing] != 1) {

$list = "No";
$vlist = "Yes&nbsp;<input type="radio" name="mailing" value="1">&nbsp; No&nbsp;<input type="Radio" name="mailing" value="0" checked>";


}
print("<form action="updatem.php" method="post">
              <table width=80%  border=0>
                <tr>
                  <td width=36%>Member Name:</td>
                  <td width=44%>$vrow[username]</td>
                </tr>
                <tr>
                  <td width="36%"></td>
                  <td width="44%"><input type="hidden" name="username" value="$vrow[username]"</td>
                </tr>
                <tr>
                  <td>First Name </td>
                  <td>$vrow[firstname]</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td width="44%"><input type="text" name="firstname" value="$vrow[firstname]" size="20"</td>
                </tr>
                <tr>
				<td>Last Name </td>
                  <td>$vrow[lastname]</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td width="44%"><input type="text" name="lastname" value="$vrow[lastname]" size="20"</td>
                </tr>
                <tr>
                  <td>Email Address: </td>
                  <td>$vrow[email]</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td width="44%"><input type="text" name="email" value="$vrow[email]" size="20"</td>
                </tr>
                <tr>
                  <td>Member Mailing List: </td>
                  <td>$list</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>$vlist</td>
                </tr>
                <tr>
                                    <td><div align=center><a href="../admin.php"><img src="images/mainadminmenu.png" border="0"></a></div></td>
                  <td><div align="left"><input type="image" src="images/updatemember.png"><br>
                  <input type="hidden" value="Update Member"></div></td>
                </tr>
              </table></form>
			  ");


				}

				?>
I know I need to pull in the $viewmember value for this to work and also for the next page where the member information will be updated. I initally got this to work when there was only one record in the database, but now that I have populated it with say 12 members it was wanting to go to the last record. Now it is blank where the info and input fields should be.

Posted: Tue Jul 06, 2004 11:03 am
by launchcode
You may need to do this:

Code: Select all

$viewmember = $_POST['viewmember'];
If your server has Register Globals disabled (which most do these days).

Posted: Tue Jul 06, 2004 11:11 am
by eatmyshorts
Stupid questions but put that in the 2nd form? Does it matter where I put it?

Posted: Tue Jul 06, 2004 11:14 am
by markl999
Just put it anywhere in the 2nd form before you try to use $viewmember
I'd also do:

Code: Select all

$sql = "SELECT * FROM $db_table WHERE username='$viewmember'";
echo $sql.'<br />'; //for debugging
$query = mysql_query($sql,$link) or die(mysql_error());
.. just to make sure all is well.

I also can't see where you define $db_table ?

Posted: Tue Jul 06, 2004 11:20 am
by eatmyshorts
thanks for the tip. now at least I can figure it out better since I can see what it's really trying to pull. From what it's telling me I should be matching it with the userID instead of username.

Thanks! :D

Posted: Tue Jul 06, 2004 11:21 am
by eatmyshorts
just to confirm, that was it. thanks again!