Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Code Pull All Data Instead of by ID

Posted on 2011-03-25
8
Medium Priority
?
213 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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 . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

730 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