Solved

PHP Code Dispay Issue

Posted on 2011-03-24
4
296 Views
Last Modified: 2012-06-27
The attached code is supposed to pull data from my MySQL database & display it in the desigated fields...but is is not, when I go to it in the browser it displays the attached picture...what am I missing?
<html
<head>
<?php
require('connection.php');

if (isset($_GET['op']) && $_GET['op'] == "d") 
if($_GET['op'] == "d" && !empty($_GET['id']) )
{

   $result = mysql_query($query) or die(mysql_error());  
}

$query="SELECT fid, cust_no, fname, lname, office FROM psrinfo";
$result = mysql_query($query) or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
  
<?php } 

echo '<form action="111.php" method="post">

<table width="75%" border="1">
<tr>
<td><b>Customer No:</b> <br><input type="text" name="cust_no" size="25" maxlength="30" value="$row[cust_no]" /><br> </td>
<td><b>Office:</b> <br><input type="text" name="office" size="25" maxlength="30" value="$row[office]" /><br> </td> 
</tr>

<tr>
<td><b>Customer First Name:</b> <br><input type="text" name="fname" size="25" maxlength="30" value="$row[fname]" /><br> </td>
<td><b>Customer Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="$row[lname]" /><br> </td>
</tr>

</table>
</form>';
mysql_close(); // Close the database connection.
?>           
 </tbody>
 </table>

Open in new window

eeeee.JPG
0
Comment
Question by:wantabe2
  • 3
4 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35207960
Try this:

echo '<form action="111.php" method="post">

<table width="75%" border="1">
<tr>
<td><b>Customer No:</b> <br><input type="text" name="cust_no" size="25" maxlength="30" value="'. $row[cust_no] .'" /><br> </td>
<td><b>Office:</b> <br><input type="text" name="office" size="25" maxlength="30" value="'. $row[office] .'" /><br> </td> 
</tr>

<tr>
<td><b>Customer First Name:</b> <br><input type="text" name="fname" size="25" maxlength="30" value="'. $row[fname] .'" /><br> </td>
<td><b>Customer Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'. $row[lname] .'" /><br> </td>
</tr>

</table>
</form>';

Open in new window

0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35208040
Some read material to help you with this in the future:
http://ca.php.net/types.string
0
 
LVL 15

Author Comment

by:wantabe2
ID: 35208772
Now I am getting:

Use of undefined constant  - assumed 'cust_no' in C:\wamp\www\flow\query\111.php on line 25

Use of undefined constant office - assumed 'office' in C:\wamp\www\flow\query\111.php on line 26

Use of undefined constant fname - assumed 'fname' in C:\wamp\www\flow\query\111.php on line 30

Use of undefined constant lname - assumed 'lname' in C:\wamp\www\flow\query\111.php on line 31

In the browser when I go to this file....
<html
<head>
<?php
require('connection.php');

if (isset($_GET['op']) && $_GET['op'] == "d") 
if($_GET['op'] == "d" && !empty($_GET['id']) )
{

   $result = mysql_query($query) or die(mysql_error());  
}

$query="SELECT fid, cust_no, fname, lname, office FROM psrinfo";
$result = mysql_query($query) or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
  
<?php } 

echo '<form action="111.php" method="post">

<table width="75%" border="1">
<tr>
<td><b>Customer No:</b> <br><input type="text" name="cust_no" size="25" maxlength="30" value="'. $row[cust_no] .'" /><br> </td>
<td><b>Office:</b> <br><input type="text" name="office" size="25" maxlength="30" value="'. $row[office] .'" /><br> </td> 
</tr>

<tr>
<td><b>Customer First Name:</b> <br><input type="text" name="fname" size="25" maxlength="30" value="'. $row[fname] .'" /><br> </td>
<td><b>Customer Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'. $row[lname] .'" /><br> </td>
</tr>

</table>
</form>';
mysql_close(); // Close the database connection.
?>           
 </tbody>
 </table>

Open in new window

0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35208803
The $row array can only be accessed in the while loop,
you have putted everything outside of it.

<html
<head>
<?php
require('connection.php');

if (isset($_GET['op']) && $_GET['op'] == "d") 
if($_GET['op'] == "d" && !empty($_GET['id']) )
{

   $result = mysql_query($query) or die(mysql_error());  
}

$query="SELECT fid, cust_no, fname, lname, office FROM psrinfo";
$result = mysql_query($query) or die(mysql_error());  
 

echo '<form action="111.php" method="post">

<table width="75%" border="1">';

while($row = mysql_fetch_array( $result )) {

echo '<tr>
<td><b>Customer No:</b> <br><input type="text" name="cust_no" size="25" maxlength="30" value="'. $row[cust_no] .'" /><br> </td>
<td><b>Office:</b> <br><input type="text" name="office" size="25" maxlength="30" value="'. $row[office] .'" /><br> </td> 
</tr>

<tr>
<td><b>Customer First Name:</b> <br><input type="text" name="fname" size="25" maxlength="30" value="'. $row[fname] .'" /><br> </td>
<td><b>Customer Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'. $row[lname] .'" /><br> </td>
</tr>';

 } 



echo '</table>
</form>';
mysql_close(); // Close the database connection.
?>           
 </tbody>
 </table>

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now