Solved

Code Pull All Data Instead of by ID

Posted on 2011-03-25
8
199 Views
Last Modified: 2012-05-11
The attached code is supposed to pull the data from my MySQL database. In my MySQL database I have an autoincrement column for the ID that is named FID. Well, pulls the data correctly BUT it pulls all the data. For instance, I have a shortcut on another page that point to eee.php. When I hover over the shortcut it does have the ID at the end of the URL but instead of pulling that unique FID it pulls all of them in the database & displays them in my form. I just need it to pull that unique ID it says it is going to pull & not all of them....can anyone help me?
<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, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo";
$result = mysql_query($query) or die(mysql_error()); 

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

<?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, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=fid ";
$result = mysql_query($query) or die(mysql_error()); 

echo '<form action="eee.php" method="post">
<h2> <center> Form Review </center></h2>
<table width="75%" border="1">';

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

echo '<tr>
<td><b>PACTS No:</b> <br><input type="text" name="pacts" size="25" maxlength="30" value="'. $row['pacts'] .'" /> 
<td><b>Reviewer:</b> <br><input type="text" name="dock" size="25" maxlength="30" value="" />  
</tr>

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

<tr>
<td><b>Sent Date:</b> <br><input type="text" name="sent_date" size="25" maxlength="30" value="'. $row['sent_date'] .'" />
<td><b>Assign Date:</b> <br><input type="text" name="assgn_date" size="25" maxlength="30" value="'. $row['assgn_date'] .'" />
<td><b>Interview Date:</b> <br><input type="text" name="interv_date" size="25" maxlength="30" value="'. $row['interv_date'] .'" />
</tr>

<tr>
<td><b></b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Reviewer" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to SUSPO" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Clerk" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to Att" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to owner" /> </td>
<td><b>Initials:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
<td><b>Due Date:</b> <br><input type="text" name="due_rev" size="25" maxlength="30" value="'. $row['due_rev'] .'" /> </br> <br> <input type="text" name="due_suspo" size="25" maxlength="30" value="'. $row['due_suspo'] .'" /> </br><br> <input type="text" name="due_clerk" size="25" maxlength="30" value="'. $row['due_clerk'] .'" /> </br><br> <input type="text" name="due_attny" size="25" maxlength="30" value="'. $row['due_attny'] .'" /> </br><br> <input type="text" name="due_" size="25" maxlength="30" value="'. $row['due_owner'] .'" /> </td>
<td><b>Actual Date:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
</tr>

</tr>';

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

?>          
 </tbody>
 </table>

Open in new window

0
Comment
Question by:wantabe2
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 9

Expert Comment

by:EZFrag
Comment Utility
hi there,
I wasn't able to test it , but here is a possible new eee.php for you.

hope it helps ^_^
<html>
<head>

<?php 

require('connection.php');

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=".$_GET['id'];
$result = mysql_query($query) or die(mysql_error()); 

echo '<form action="eee.php" method="post">
<h2> <center> Form Review </center></h2>
<table width="75%" border="1">';

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

echo '<tr>
<td><b>PACTS No:</b> <br><input type="text" name="pacts" size="25" maxlength="30" value="'. $row['pacts'] .'" /> 
<td><b>Reviewer:</b> <br><input type="text" name="dock" size="25" maxlength="30" value="" />  
</tr>

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

<tr>
<td><b>Sent Date:</b> <br><input type="text" name="sent_date" size="25" maxlength="30" value="'. $row['sent_date'] .'" />
<td><b>Assign Date:</b> <br><input type="text" name="assgn_date" size="25" maxlength="30" value="'. $row['assgn_date'] .'" />
<td><b>Interview Date:</b> <br><input type="text" name="interv_date" size="25" maxlength="30" value="'. $row['interv_date'] .'" />
</tr>

<tr>
<td><b></b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Reviewer" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to SUSPO" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Clerk" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to Att" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to owner" /> </td>
<td><b>Initials:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
<td><b>Due Date:</b> <br><input type="text" name="due_rev" size="25" maxlength="30" value="'. $row['due_rev'] .'" /> </br> <br> <input type="text" name="due_suspo" size="25" maxlength="30" value="'. $row['due_suspo'] .'" /> </br><br> <input type="text" name="due_clerk" size="25" maxlength="30" value="'. $row['due_clerk'] .'" /> </br><br> <input type="text" name="due_attny" size="25" maxlength="30" value="'. $row['due_attny'] .'" /> </br><br> <input type="text" name="due_" size="25" maxlength="30" value="'. $row['due_owner'] .'" /> </td>
<td><b>Actual Date:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
</tr>

</tr>';

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

?>          
 </tbody>
 </table>

Open in new window

0
 
LVL 10

Expert Comment

by:aboo_s
Comment Utility
I take a quick look onto your code and I noticed here might be a problem:
$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=fid ";
$result = mysql_query($query) or die(mysql_error());

WHERE fid=$fid
because $fid is a variable that should contain an integer or something!
0
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
Not sure got your question correctly

are you saying now your page fething all the data from the database means multiple Fid'd
you need to fetch only one record for perticular fId which is posted

then you need to change the query and add FId check in where like this

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo Where FAID =" .$_GET['id'];
0
 
LVL 15

Author Comment

by:wantabe2
Comment Utility
EZFrag,
Your code produced the error "Parse error: syntax error, unexpected $end in C:\wamp\www\flow\query\3.php on line 49"
Which is the last line of code </table>

Aboo_s & pratima_cs,
By putting what you suggested I get the error "Undefined variable: fid in C:\wamp\www\flow\query\rev.php on line 14"

Any other help will be greatly appreciated! Thanks
0
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!

 
LVL 9

Accepted Solution

by:
EZFrag earned 500 total points
Comment Utility
Hmm... it seems I missed a closing bracket... It should be executing now.
<html>
<head>

<?php 

require('connection.php');

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=".$_GET['id'];
$result = mysql_query($query) or die(mysql_error()); 

echo '<form action="eee.php" method="post">
<h2> <center> Form Review </center></h2>
<table width="75%" border="1">';

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

echo '<tr>
<td><b>PACTS No:</b> <br><input type="text" name="pacts" size="25" maxlength="30" value="'. $row['pacts'] .'" /> 
<td><b>Reviewer:</b> <br><input type="text" name="dock" size="25" maxlength="30" value="" />  
</tr>

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

<tr>
<td><b>Sent Date:</b> <br><input type="text" name="sent_date" size="25" maxlength="30" value="'. $row['sent_date'] .'" />
<td><b>Assign Date:</b> <br><input type="text" name="assgn_date" size="25" maxlength="30" value="'. $row['assgn_date'] .'" />
<td><b>Interview Date:</b> <br><input type="text" name="interv_date" size="25" maxlength="30" value="'. $row['interv_date'] .'" />
</tr>

<tr>
<td><b></b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Reviewer" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to SUSPO" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Given to Clerk" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to Att" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="Disclosed to owner" /> </td>
<td><b>Initials:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
<td><b>Due Date:</b> <br><input type="text" name="due_rev" size="25" maxlength="30" value="'. $row['due_rev'] .'" /> </br> <br> <input type="text" name="due_suspo" size="25" maxlength="30" value="'. $row['due_suspo'] .'" /> </br><br> <input type="text" name="due_clerk" size="25" maxlength="30" value="'. $row['due_clerk'] .'" /> </br><br> <input type="text" name="due_attny" size="25" maxlength="30" value="'. $row['due_attny'] .'" /> </br><br> <input type="text" name="due_" size="25" maxlength="30" value="'. $row['due_owner'] .'" /> </td>
<td><b>Actual Date:</b><br><input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br> <br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </br><br> <input type="text" name="assgn_date" size="25" maxlength="30" value="" /> </td>
</tr>

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

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
try this

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo Where FID =" .$_GET['id'];
0
 
LVL 10

Expert Comment

by:OnALearningCurve
Comment Utility
Hi wantabe2,

Try changin line 30 in your code from:

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=fid ";

to

$query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE fid=".$_GET['id'];

Hope this helps,

Mark
0
 
LVL 10

Expert Comment

by:OnALearningCurve
Comment Utility
SORRY!

Just hit submit and then realised pratima_mcs: has already suggested the same fix.

My apologies.

Mark.
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

15 Experts available now in Live!

Get 1:1 Help Now