Solved

PHP Code Dispay Issue

Posted on 2011-03-24
4
299 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

820 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