Grab a row

Reply

Join Date: Dec 2007
Posts: 54
Reputation: rouse is an unknown quantity at this point 
Solved Threads: 1
rouse rouse is offline Offline
Junior Poster in Training

Grab a row

 
0
  #1
Dec 3rd, 2008
I am trying to get a row from a table based on the record number, a unique ID in a table which is passed from another form. The record number seems to be passed correctly and is received on the forwarding page. The query in the PHP page does not bring up values in the receiving page although the query works when tried from an external application. Below is a listing of the PHP code. Could some one point out what I am doing incorrectly. Thanks!
  1. <?php
  2. include("connect.php");
  3. $id = $_GET['id'];
  4.  
  5. $qProfile = "SELECT * FROM signers WHERE recordNum='$id' ";
  6. $rsProfile = mysql_query($qProfile);
  7. $row = mysql_fetch_array($rsProfile);
  8. extract($row);
  9. $recordnum = stripslashes($recordnum);
  10. $firstmiddlename = stripslashes($firstmiddlename);
  11. $lastname = stripslashes($lastname);
  12. mysql_close();?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #2
Dec 3rd, 2008
$qProfile = "SELECT * FROM signers WHERE recordNum='$id' ";
I think it would work to use something like this...

$qProfile = "SELECT * FROM signers WHERE recordNum='".$id."' ";
Hope This Helps.
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 24
Reputation: xarz is an unknown quantity at this point 
Solved Threads: 1
xarz's Avatar
xarz xarz is offline Offline
Newbie Poster

Re: Grab a row

 
0
  #3
Dec 3rd, 2008
i don't know if this will really work or not but instead of having
  1. extract($row);
  2. $recordnum = stripslashes($recordnum);
  3. $firstmiddlename = stripslashes($firstmiddlename);
  4. $lastname = stripslashes($lastname);

you can try

  1. $recordnum = stripslashes($row['recordnum']);
  2. $firstmiddlename = stripslashes($row['firstmiddlename']);
  3. $lastname = stripslashes($row['lastname']);
Last edited by xarz; Dec 3rd, 2008 at 8:42 pm. Reason: wrong closing tag for code
:: xarz ::
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #4
Dec 3rd, 2008
I don't know why I didn't catch that. I usually use something similar to the following.

  1. $qProfile = "SELECT * FROM signers WHERE recordNum='".$id."' ";
  2. $rsProfile = mysql_query($qProfile);
  3. while ($row = mysql_fetch_assoc($rsProfile)){
  4.  
  5. $recordnum = stripslashes($row['recordnum']);
  6. $firstmiddlename = stripslashes($row['firstmiddlename']);
  7. $lastname = stripslashes($row['lastname']);
  8. mysql_close();?>

Hope some of this helps...
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #5
Dec 4th, 2008
Hi try this,
  1.  
  2.  
  3. <?php
  4. include("connect.php");
  5. $id = $_GET['id'];
  6.  
  7. $qProfile = "SELECT * FROM signers WHERE recordNum='$id' ";
  8. $rsProfile = mysql_query($qProfile);
  9. $row = mysql_fetch_array($rsProfile);
  10. $recordnum = stripslashes($row['recordnum']);
  11. $firstmiddlename = stripslashes($row['firstmiddlename']);
  12. $lastname = stripslashes($row['lastname']);
  13. mysql_close();?>
Last edited by Kavitha Butchi; Dec 4th, 2008 at 9:16 am.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 54
Reputation: rouse is an unknown quantity at this point 
Solved Threads: 1
rouse rouse is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #6
Dec 4th, 2008
None of these suggestions worked. I am surprised this task is so tricky.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #7
Dec 4th, 2008
Try This...

  1. <?
  2. $server = ""; // Your MySQL Host - might be local host
  3. $dbusername = ""; // Your Database User Name
  4. $dbpassword = ""; // Your Database PassWord
  5. $db_name = ""; // Your Database Name
  6.  
  7. $connection = @mysql_connect($server,$dbusername,$dbpassword) or die(mysql_error());
  8.  
  9. $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
  10.  
  11. //build and issue query
  12.  
  13. $qProfile = "SELECT * FROM signers WHERE recordNum='".$id."' ";
  14.  
  15. $rsProfile = @mysql_query($qProfile,$connection) or die(mysql_error());
  16.  
  17. while ($row = mysql_fetch_assoc($rsProfile)){
  18.  
  19. $recordnum = stripslashes($row['recordnum']);
  20. $firstmiddlename = stripslashes($row['firstmiddlename']);
  21. $lastname = stripslashes($row['lastname']);
  22.  
  23. mysql_close();?>

You can enter your db info into this script or change references to whatever you want...
Maybe I got everything this time. One thing I like to do is include the
or die(mysql_error()) on MySQL commands. This may tell you what the problem might be.

Again. Hope This Helps!?!?!?
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Grab a row

 
0
  #8
Dec 5th, 2008
Hey,

Just remove the blank spaces from your query string..

  1. $qProfile = "SELECT * FROM signers WHERE recordNum='$id' ";

There are some white spaces at the end of this string..
Remove the white space at the end..

Change it to:

  1. $qProfile = "SELECT * FROM signers WHERE recordNum='$id'";

This was the problem with your query.... thats why it is not running
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Grab a row

 
0
  #9
Dec 5th, 2008
  1. $con = mysql_connect("localhost","root","");
  2. if (!$con)
  3. {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6. else
  7. {
  8. // echo('Connected with Mysql');
  9. }
  10. @mysql_select_db("db_name", $con);
  11. $sql=mysql_query("SELECT * FROM signers WHERE recordNum='$id'");
  12. $row = mysql_fetch_array($sql);
  13.  
  14. $recordNum=$row['recordNum'];
  15. $user_lname=$row['user_lname'];
  16. $user_add=$row['user_add'];
  17. $user_id=$row['user_id'];

check your database column name.....correctly..
whether recordNum or recordnum...or id...

you are got the 'id'...and check with recordNum...

so problem with your sql query not with fetching data in row
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 583 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC