Solved

PHP Code Dispay Issue

Posted on 2011-03-24
4
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

627 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