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
include("connect.php");
$id = $_GET['id'];

$qProfile = "SELECT * FROM signers WHERE recordNum='$id'  ";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
extract($row);
$recordnum = stripslashes($recordnum);
$firstmiddlename = stripslashes($firstmiddlename);
$lastname = stripslashes($lastname);
…
…
mysql_close();?>

Recommended Answers

All 8 Replies

$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.

i don't know if this will really work or not but instead of having

extract($row);
$recordnum = stripslashes($recordnum);
$firstmiddlename = stripslashes($firstmiddlename);
$lastname = stripslashes($lastname);

you can try

$recordnum = stripslashes($row['recordnum']);
$firstmiddlename = stripslashes($row['firstmiddlename']);
$lastname = stripslashes($row['lastname']);

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

$qProfile = "SELECT * FROM signers WHERE recordNum='".$id."' ";
$rsProfile = mysql_query($qProfile);
while ($row = mysql_fetch_assoc($rsProfile)){

$recordnum = stripslashes($row['recordnum']);
$firstmiddlename = stripslashes($row['firstmiddlename']);
$lastname = stripslashes($row['lastname']);
…
…
mysql_close();?>

Hope some of this helps...

Hi try this,

<?php
include("connect.php");
$id = $_GET['id'];

$qProfile = "SELECT * FROM signers WHERE recordNum='$id'  ";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
$recordnum = stripslashes($row['recordnum']);
$firstmiddlename = stripslashes($row['firstmiddlename']);
$lastname = stripslashes($row['lastname']);
…
…
mysql_close();?>

None of these suggestions worked. I am surprised this task is so tricky.

Try This...

<?
$server = ""; // Your MySQL Host - might be local host
$dbusername = ""; // Your Database User Name
$dbpassword = ""; // Your Database PassWord
$db_name = ""; // Your Database Name

$connection = @mysql_connect($server,$dbusername,$dbpassword) or die(mysql_error());

$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

//build and issue query

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

$rsProfile = @mysql_query($qProfile,$connection) or die(mysql_error());

while ($row = mysql_fetch_assoc($rsProfile)){

$recordnum = stripslashes($row['recordnum']);
$firstmiddlename = stripslashes($row['firstmiddlename']);
$lastname = stripslashes($row['lastname']);

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!?!?!?

Hey,

Just remove the blank spaces from your query string..

$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:

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

This was the problem with your query.... thats why it is not running

$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }
	  @mysql_select_db("db_name", $con);
	  $sql=mysql_query("SELECT * FROM signers WHERE recordNum='$id'");
	  $row = mysql_fetch_array($sql);
	  
	  $recordNum=$row['recordNum'];
	  $user_lname=$row['user_lname'];
	  $user_add=$row['user_add'];
	  $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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.