3 Replies - 1615 Views - Last Post: 28 June 2007 - 05:37 PM Rate Topic: -----

#1 nomadsoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-May 07

Upload script won't display form

Posted 27 June 2007 - 04:34 PM

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.
<?
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;
} 
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Upload script won't display form

#2 Styx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 192
  • Joined: 04-March 07

Re: Upload script won't display form

Posted 27 June 2007 - 09:33 PM

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.
Was This Post Helpful? 0
  • +
  • -

#3 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Upload script won't display form

Posted 28 June 2007 - 07:47 AM

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.
Was This Post Helpful? 0
  • +
  • -

#4 Styx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 192
  • Joined: 04-March 07

Re: Upload script won't display form

Posted 28 June 2007 - 05:37 PM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1