943,568 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 770
  • PHP RSS
Dec 3rd, 2008
0

Grab a row

Expand Post »
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!
PHP Syntax (Toggle Plain Text)
  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();?>
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
rouse is offline Offline
111 posts
since Dec 2007
Dec 3rd, 2008
0

Re: Grab a row

Quote ...
$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.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Dec 3rd, 2008
0

Re: Grab a row

i don't know if this will really work or not but instead of having
php Syntax (Toggle Plain Text)
  1. extract($row);
  2. $recordnum = stripslashes($recordnum);
  3. $firstmiddlename = stripslashes($firstmiddlename);
  4. $lastname = stripslashes($lastname);

you can try

php Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
xarz is offline Offline
24 posts
since Nov 2008
Dec 3rd, 2008
0

Re: Grab a row

I don't know why I didn't catch that. I usually use something similar to the following.

PHP Syntax (Toggle Plain Text)
  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...
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Dec 4th, 2008
0

Re: Grab a row

Hi try this,
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Dec 4th, 2008
0

Re: Grab a row

None of these suggestions worked. I am surprised this task is so tricky.
Reputation Points: 10
Solved Threads: 1
Junior Poster
rouse is offline Offline
111 posts
since Dec 2007
Dec 4th, 2008
0

Re: Grab a row

Try This...

php Syntax (Toggle Plain Text)
  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!?!?!?
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Dec 5th, 2008
0

Re: Grab a row

Hey,

Just remove the blank spaces from your query string..

php Syntax (Toggle Plain Text)
  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:

php Syntax (Toggle Plain Text)
  1. $qProfile = "SELECT * FROM signers WHERE recordNum='$id'";

This was the problem with your query.... thats why it is not running
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Dec 5th, 2008
0

Re: Grab a row

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC