Post userid to edit form

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
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post userid to edit form

Post 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
Last edited by Jim_Bo on Tue Feb 08, 2005 2:49 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you forgot to put <?php echo .... ?>
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Forgot to put echo where?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

*bump* ... Still cant figure it out :oops:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why can't you use the hidden field again?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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>
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

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

Post 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.
Post Reply