Solved

PHP Code Dispay Issue

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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