help with an update script

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
hamish537
Forum Newbie
Posts: 2
Joined: Tue Aug 15, 2006 2:02 pm

help with an update script

Post by hamish537 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi i am very new to PHP and think that this may be a case of trying to run before i can walk.

What i am trying to do is create a form that allows me to update a users details, sound easy enough i know.

The way that i am doing this is by using a dynamic drop down menu containing the users first and last names to select the user i want to update.  

on clicking the 'submit' button what i want to happen is to pass the id of the user that i have selected to a form where the rest of that users details will be populated from the database, i can then change and update the details.

So far i have managed to write the script for selecting the user, but i am having trouble with passing the users id onto the next form.

I have posted what i have done so far bellow.

If anyone can help it would be much appreciated as i think i might go mad soon

Code: Select all

<? include ('connect.php');?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<? $query="SELECT user_id, user_firstname, user_lastname FROM share_users";
$result = mysql_query ($query);

?>

<form name='user_select' method='post' action='update_user1.php'>
 
  <select name=user value=''>user</option>
  
  <? while($nt=mysql_fetch_array($result))
 {
echo "<option value=$nt[user_id]>$nt[user_firstname] $nt[user_lastname]</option>";
}
?>
</select>
  <br>
  <br>
  <input type='submit' name='submit' value='submit'>
</form>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post by Tom420 »

I notice two problems.

Code: Select all

<select name=user value=''>user</option>
The correct structure of a <select> is as follow:

Code: Select all

<select name='abc'>
<option value='a'>A
<option value='b'>B
</select>

Code: Select all

echo "<option value=$nt[user_id]>$nt[user_firstname] $nt[user_lastname]</option>";
Arrays won't be interpreted correctly in this context. Arrays must be enclosed within curly brackets as this:

Code: Select all

echo "<option value={$nt[user_id]}>{$nt[user_firstname]} {$nt[user_lastname]}</option>";
Hope this helps,
Tom :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Tom420 wrote:The correct structure of a <select> is as follow:

Code: Select all

<select name='abc'>
<option value='a'>A
<option value='b'>B
</select>
Your way isn't exactly correct either: http://www.w3.org/TR/html401/interact/f ... idx-menu-3
Tom420 wrote:

Code: Select all

echo "<option value=$nt[user_id]>$nt[user_firstname] $nt[user_lastname]</option>";
Arrays won't be interpreted correctly in this context. Arrays must be enclosed within curly brackets as this:

Code: Select all

echo "<option value={$nt[user_id]}>{$nt[user_firstname]} {$nt[user_lastname]}</option>";
Although your way one way, so is the previous snippet. They will be handled in that context. I'll direct you to the documentation on strings.
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post by Tom420 »

You are right, always forget the strict standard:

Code: Select all

<select name='abc'>
<option value='a'>A</option>
<option value='b'>B</option>
</select>
I'm I correct now? :)


Check the doc and learned. Didn't now about the difference that the single-quotes (which I actually forgot in my reply) makes withing the square-brackets. I thought my way was the only correct way of getting an array to expand within a string. So the following are both correct:

Code: Select all

"Some text {$array['item']}";
"Some text $array[item]";
hamish537
Forum Newbie
Posts: 2
Joined: Tue Aug 15, 2006 2:02 pm

Thanks

Post by hamish537 »

Thanks Guys,

That has helped, i have got the drop down workinmg properly and now see that i need to call the select name into the next page to get it to call the rets of the users details from the database.

I will let you know how this goes, doubless will not be as straight forward as i think, but thems the joys of learning new things.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Tom420 wrote:Check the doc and learned. Didn't now about the difference that the single-quotes (which I actually forgot in my reply) makes withing the square-brackets. I thought my way was the only correct way of getting an array to expand within a string. So the following are both correct:

Code: Select all

"Some text {$array['item']}";
"Some text $array[item]";
Not quite, you may want to read this Why is $foo[bar] wrong?
Post Reply