Jump to content

php form <select> help


echocpt

Recommended Posts

Hi, can anyone surgest a reason why this piece of script aint working. It should be filling the text boxes but wont. The select feature seems to be working fine and redirects the url fine, but the boxes wont fill with info. Thanks.

 

                       <?php
				$query =  "SELECT id, username
												FROM user";
												$result = mysql_query($query) or die(); 
												?>   
<form>  
      Select user to edit: 
      <select name="menu">
<?php
while($row = mysql_fetch_assoc($result))
{
    echo "<option value='http://www.zerodefex.net/ccf/redo/pages/admin.php?user=true?UserID=" . $row['id'] . "'>" . $row['username'] . "</option>";
}
?>
</select>

<input type="button"
  onClick="location=this.form.menu.options
  [this.form.menu.selectedIndex].value;" value="Edit User">
    </form>
    						<?php include('connection.php');
					$query = "SELECT id, username, password, permission, pin, email
									FROM user
									WHERE id = '" . $_GET['UserID'] . "'";
									$result = mysql_query($query) or die();
									$row = mysql_fetch_object($result);
									?>
					<form id="form7" name="form7" method="post" action="update.php">
					<table width="638" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td width="190" height="28" valign="top"><p><strong>Edit User:</strong></p>							    </td>
						  <td width="449"><label></label></td>
						</tr>
						<tr>
							<td height="30">Username:</td>
						  <td><input name="username2" type="text" class="area" id="username2" value="<?php echo $row->username; ?>" /></td>
						</tr>
						<tr>
							<td height="30">Password:</td>
						    <td><label>
						      <input name="password3" type="text" class="area" id="password3" value="<?php echo $row->password; ?>" />
						    </label></td>
						</tr>
						<tr>
							<td height="30">Email:</td>
					        <td><label>
					          <input name="email2" type="text" class="area" id="email2" value="<?php echo $row->email; ?>" />
					        </label></td>
						</tr>
						<tr>
							<td height="30">Pin:</td>
						  <td><label>
						  <input name="pin5" type="text" class="area" id="pin5" value="<?php echo $row->pin; ?>" />
						  </label></td>
						</tr>
						<tr>
							<td height="30"> </td>
							<td><label>
							 <input name="userid" type="hidden" value="<?php echo $_GET['UserID']; ?>" />
                                 <input type="submit" name="submit3" id="submit3" value="Edit User" />
							</label></td>
					  </tr>
						<tr>
							<td> </td>
                                	
							<td> </td>
						</tr>
						<tr>
							<td> </td>
							<td> </td>
						</tr>
						<tr>
							<td> </td>
							<td> </td>
						</tr>
						<tr>
							<td> </td>
							<td> </td>
						</tr>
					</table>
                      </form>
					<br />
					<br />
				</div>
				<?php } ?>

Link to comment
Share on other sites

well for the first select box in particular you didnt define a row that equals ID or username

 

i.e

while($row = mysql_fetch_assoc($result))
{
$id=$row['id'];
$username=$row['username'];

 

you need to define them or call them instead by their row number i.e $row[0] $row[1]

 

I didnt not look further past this assuming it is a common error throughout.

 

Hope this helps!

 

 

Link to comment
Share on other sites

Hi, thanks for that, i changed the code as advised, however it still doesn't work. I am wondering (as i have used this same idea in a pervious site with sucsess) if it is something to do with the line

echo "<option value='http://www.zerodefex.net/ccf/redo/pages/admin.php?user=true?UserID=" . $row['id'] . "'>" . $row['username'] . "</option>";

and in particular the

/admin.php?user=true?UserID=" 

bit as iv never used the double "?" before. I persoanlly can't see anything else wronge with the select area, but if its not what i just stated, i assume its to do with the actuall form area with the textboxes? Any help? Thanks.

Link to comment
Share on other sites

If I were writing it without defining the rows would look like:

 

 

<SELECT name=menu>
<script language="php">

$SQL = " SELECT id, username FROM user ";
  
    # execute SQL statement
    $result = mysql_db_query($db, $SQL, $cid);


     if(mysql_num_rows($result)) {
       // we have at least one result, so show all users as options in select form
       while($row = mysql_fetch_row($result))
       {
          print"<option value=\"http://www.zerodefex.net/ccf/redo/pages/admin.php?user=true?UserID=$row[0]">$row[1]</option>");
       }
     } else {
       print("<option value=\"\">No Users Created Yet</option>");
     }
</script>
</select>

Link to comment
Share on other sites

didnt notice the double ?, why do you use it? why not just use like .. ?this=this&that=that

 

... but that wouldn't effect it as it's within a string. I personally can't see anything wrong with that line at all, but i would advise you switch the quotes. ie...

 

echo '<option value="http://www.zerodefex.net/ccf/redo/pages/admin.php?user=true?UserID=' . $row['id'] . '">' . $row['username'] . '</option>';

 

.. notice now the HTML is correct and valid.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.