Page 1 of 1

Post userid to edit form

Posted: Fri Jan 28, 2005 7:07 pm
by Jim_Bo
hi,

I have a form that shows all members .. within there I have a link that displays if user = admin .. to edit user level

I have created the form to show the existing data and also makes changes on submit ..

I can get it to display the user information when the link is clicked within the members page.

How is it done?

I thought something like:

Code: Select all

<a href="../login/userlevel.php?userid=$userid">CHANGE USERS LEVEL</a>
But when the link is clicked no data is displayed in the browser as the url displays:

Code: Select all

http://www.bla.com/login/userlevel.php?userid=$userid
members.php looks like:

Code: Select all

$sql = mysql_query("SELECT * FROM users");

while($row = mysql_fetch_array($sql))&#123; 

$userid = $row&#1111;'$userid'];
$first = $row&#1111;'first_name'];
$last_name = $row&#1111;'last_name'];

<table width="100%" cellspacing="1" cellpadding="3">
    <tr> 
      <td width="16%" class="txt"><strong>Name</strong></td>
      <td class="txt"><?php echo $row&#1111;'first_name']; ?> <?php echo $row&#1111;'last_name']; ?> 
      </td>
    </tr>
    <tr> 
      <td colspan="2" class="txt"><div align="center"><a href="../login/userlevel.php?userid=$userid">UPDATE 
          USER LEVEL</a></div></td>
    </tr>
  </table>
and the form that UPDATE USER LEVEL links to:

Code: Select all

<?
include("db.php");

$userid=$_GET&#1111;'userid'];

$sql="SELECT * FROM users WHERE userid='$userid'";
$result=mysql_query($sql);
$num=mysql_numrows($result); 
mysql_close();

$i=0;
while ($i < $num) &#123;
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
$user_name=mysql_result($result,$i,"user_name");
$user_level=mysql_result($result,$i,"user_level");

?>

<form action="../login/userlevelparse.php">
<input type="hidden" name="userid" value="<? echo "$userid"; ?>">
  First Name: <? echo "$first_name"?><br>
  Last Name: <? echo "$last_name"?><br>
  User Name: <? echo "$user_name"?><br>
User Level: <input type="text" name="user_level" value="<? echo "$user_level"?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;
&#125; 
?>
How should it be?

Cheers

Posted: Fri Jan 28, 2005 7:16 pm
by feyd
you forgot to put <?php echo .... ?>

Posted: Fri Jan 28, 2005 7:20 pm
by Jim_Bo
Forgot to put echo where?

Posted: Fri Jan 28, 2005 7:24 pm
by feyd

Code: Select all

<tr>
      <td width="16%" class="txt"><strong>Name</strong></td>
      <td class="txt"><?php echo $row&#1111;'first_name']; ?> <?php echo $row&#1111;'last_name']; ?>
      </td>
    </tr>
    <tr>
      <td colspan="2" class="txt"><div align="center"><a href="../login/userlevel.php?userid=$userid">UPDATE
You remembered to use it earlier in the text, but forgot at the link.

Posted: Fri Jan 28, 2005 10:03 pm
by Jim_Bo
hey,

Im not sure what you mean .. I dont want it as a visual field, its not a form so I cant use <input name="id" type="hidden" value="<?php echo $row['userid']; ?>"> bla bla .. Im not sure how to carry it across via a link rather than a form?


Cheers

Posted: Sun Jan 30, 2005 12:51 am
by Jim_Bo
*bump* ... Still cant figure it out :oops:

Posted: Sun Jan 30, 2005 9:07 am
by John Cartwright
Why can't you use the hidden field again?

Posted: Sun Jan 30, 2005 11:30 am
by magicrobotmonkey
its the same as doing it in the form fields. All you are doing is echoing out the variable to the html so don't sweat it. ITs not going to appear on the page or anything. :

Code: Select all

//change 
 <td colspan="2" class="txt"><div align="center"><a href="../login/userlevel.php?userid=$userid">UPDATE
          USER LEVEL</a></div></td>

to 

 <td colspan="2" class="txt"><div align="center"><a href="../login/userlevel.php?userid=<?php echo $userid ?>">UPDATE
          USER LEVEL</a></div></td>

Posted: Sun Jan 30, 2005 3:38 pm
by Jim_Bo
Hey,

I had tried that .. but it wasnt posting a userid .. It should be the obvious:

Code: Select all

<a href="../ethan/login/userlevel.php?userid=<?php echo $row&#1111;'userid']; ?>">UPDATE USER LEVEL</a>
Cheers

Posted: Sun Jan 30, 2005 3:43 pm
by feyd
the code you originally posted makes use of mysql_fetch_result, not a row level fetch... so unless you changed the original code to use a row level fetch, $row['userid'] wouldn't exist.