/    Sign up×
Community /Pin to ProfileBookmark

help!! find and display data with PHP/MySQL

Hi, I’m have trouble with this code.
I wants it finds and displays datas of a record that match the id given by $id to the form below.
Please help me ASAP. Thanks.

<?
$id=$_GET[‘txtName’];

$username=”root”;
$password=””;
$database=”Database”;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query=”SELECT * FROM Company”;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num)
{
$name=mysql_result($result,$i,”Name”);
$address=mysql_result($result,$i,”Address”);
$district=mysql_result($result,$i,”District”);
$province=mysql_result($result,$i,”Province”);
$phone=mysql_result($result,$i,”Phone”);
$fax=mysql_result($result,$i,”Fax”);
$email=mysql_result($result,$i,”Email”);
$web=mysql_result($result,$i,”Website”);
?>

<form action=”updated.php”>
<input type=”hidden” name=”ud_id” value=”<? echo “$id”; ?>”>
Name: <input name=”ud_name” type=”text” value=”<? echo “$name”?>” size=”50″ maxlength=”50″>
<br>
Address: <input name=”ud_address” type=”text” value=”<? echo “$address”?>” size=”30″ maxlength=”30″>
<br>
District: <input name=”ud_district” type=”text” value=”<? echo “$district”?>” size=”20″ maxlength=”20″>
<br>
Province: <input name=”ud_province” type=”text” value=”<? echo “$province”?>” size=”20″ maxlength=”20″>
<br>
Phone: <input name=”ud_phone” type=”text” value=”<? echo “$phone”?>” size=”20″ maxlength=”20″>
<br>
Fax: <input name=”ud_fax” type=”text” value=”<? echo “$fax”?>” size=”20″ maxlength=”20″>
<br>
E-mail: <input name=”ud_email” type=”text” value=”<? echo “$email”?>” size=”30″ maxlength=”30″>
<br>
Website: <input name=”ud_web” type=”text” value=”<? echo “$web”?>” size=”30″ maxlength=”30″>
<br>
<input type=”Submit” value=”Update”>
</form>
<?
$i++;
}
?>

Thanks for viewing this ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Bootsman123Jun 10.2005 — You might want to try this:
[code=php]
<form action="updated.php">

<?
$id = $_GET['txtName'];

$username = "root";
$password = "";
$database = "Database";

mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM Company WHERE Id = " . $id;
$result = mysql_query($query);

wile($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$name = $row['Name'];
$address = $row['Address'];
$district = $row['District'];
$province = $row['Province'];
$phone = $row['Phone'];
$fax = $row['Fax'];
$email = $row['Email'];
$web = $row['Website'];
?>


<input type="hidden" name="ud_id" value="<?php echo $id; ?>">
Name: <input name="ud_name" type="text" value="<?php echo $name; ?>" size="50" maxlength="50">
<br>
Address: <input name="ud_address" type="text" value="<?php echo $address; ?>" size="30" maxlength="30">
<br>
District: <input name="ud_district" type="text" value="<?php echo $district; ?>" size="20" maxlength="20">
<br>
Province: <input name="ud_province" type="text" value="<?php echo $province; ?>" size="20" maxlength="20">
<br>
Phone: <input name="ud_phone" type="text" value="<?php echo $phone; ?>" size="20" maxlength="20">
<br>
Fax: <input name="ud_fax" type="text" value="<?php echo $fax; ?>" size="20" maxlength="20">
<br>
E-mail: <input name="ud_email" type="text" value="<?php echo "$email; ?>" size="30" maxlength="30">
<br>
Website: <input name="ud_web" type="text" value="<?php echo $web; ?>" size="30" maxlength="30">
<br>
<input type="Submit" value="Update">

<?
}

mysql_close();
?>

</form>
[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJun 10.2005 — you might also want to wrap your code in php code tags next time ->[ PHP ]..code..[/ PHP] without any spaces. And you also might wanna tab your code a bit
Copy linkTweet thisAlerts:
@raven80authorJun 11.2005 — thank you very much !!
×

Success!

Help @raven80 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...