[SOLVED] Form to form problem - please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eatmyshorts
Forum Newbie
Posts: 5
Joined: Tue Jul 06, 2004 9:42 am

[SOLVED] Form to form problem - please help!

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Looks more like an error in your html output, than anything else..
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Post your second script here too.
eatmyshorts
Forum Newbie
Posts: 5
Joined: Tue Jul 06, 2004 9:42 am

Post 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.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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).
eatmyshorts
Forum Newbie
Posts: 5
Joined: Tue Jul 06, 2004 9:42 am

Post by eatmyshorts »

Stupid questions but put that in the 2nd form? Does it matter where I put it?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ?
eatmyshorts
Forum Newbie
Posts: 5
Joined: Tue Jul 06, 2004 9:42 am

Post 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
eatmyshorts
Forum Newbie
Posts: 5
Joined: Tue Jul 06, 2004 9:42 am

Post by eatmyshorts »

just to confirm, that was it. thanks again!
Post Reply