Solved

Code Pull All Data Instead of by ID

Posted on 2011-03-25
8
212 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
[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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 9

Expert Comment

by:EZFrag
ID: 35214407
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
ID: 35214415
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
ID: 35214423
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
 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

 
LVL 15

Author Comment

by:wantabe2
ID: 35214703
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
 
LVL 9

Accepted Solution

by:
EZFrag earned 500 total points
ID: 35214755
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
ID: 35214757
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
ID: 35214767
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
ID: 35214776
SORRY!

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

My apologies.

Mark.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

624 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