Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,673 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,174 people online right now. Registration is fast and FREE... Join Now!




Upload script won't display form

 
Reply to this topicStart new topic

Upload script won't display form, Php mysql

nomadsoul
post 27 Jun, 2007 - 03:34 PM
Post #1


New D.I.C Head

*
Joined: 15 May, 2007
Posts: 1


My Contributions


Hi all,
I am building a basic php mysql website for contacts, later to add too and mod for other projects. The other scripts such as the output and input.php work great with the Mysql tables. Except for the update.php posted below. The form is not appearing in the browser and niether are the variables.
The $id variable is not declared in the script because it's an autoincrement in the main table.
The problem is: the form is not showing up in the browser. The connection is fine so it's not that.
What am I leaving out? Only when I comment out the all the php does the form appear.
CODE

<?
include("dbinfo.inc.php");
mysql_connect(192.168.2.6,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);


$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

?>

<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo "$id"; ?>">
First Name: <input type="text" name="ud_first" value="<? echo "$first"?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo "$last"?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo "$phone"?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo "$mobile"?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo "$fax"?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo "$email"?>"><br>
Web Address: <input type="text" name="ud_web" value="<? echo "$web"?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;
}
?>
User is offlineProfile CardPM

Go to the top of the page

Styx
post 27 Jun, 2007 - 08:33 PM
Post #2


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


Check that you actually have data for that query in your database. If there are 0 rows, it wont display. Other than that, it's fine.
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 28 Jun, 2007 - 06:47 AM
Post #3


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 2 times

Dream Kudos: 228
My Contributions


Regardless of the query returning results or not the form should show up, the only difference is that if the query doesn't return any rows that there won't be any values in the text boxes.

as to fixing your problem of the form showing up or not, i'm not sure if this is the problem but it is a problem.

you need to correct all your echo statments that you have your values set to.

i.e. you have:
value="<? echo "$id"; ?>"

the quotes around your variable names are not necesary, as it's a variable that you want to print out, currently your text box would have a value of "$id"

change them to:
value="<? echo $id ?>"

and actually, upon further thought, that could be your issue because you've got embedded quotes.

make that change and give us an update.
User is offlineProfile CardPM

Go to the top of the page

Styx
post 28 Jun, 2007 - 04:37 PM
Post #4


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


Actually, if the query returns 0 rows and $num turns out to be 0, the while loop stops there and nothing within it is displayed seeing as the condition is already met (0 is not less than 0)

Also, what fyrestorm posted as a the possible problem is not really a problem at all. Whether you put quotes around the variable names is up to you, but php doesn't have a problem with it. It processes it just fine. And since it's not being echo'd or printed with double quotes, it wont clash with anything. (It is recommended you don't put them if all you have are variables to echo, but either way still works.) If you want to check, just replace the form with 'test' and see how many times it's being displayed.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:16AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month