473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Php: passing variable to new page, but database returns first record

2
I have a webpage that lists the results of a preliminary database search -- (http://www.txlivingus.com/ourListings.php, then click on"non-mls listings." Each item on the list links to a detail page -- the variable is passed to the next page via "get". The correct record id appears when you roll over the link, but when you click the link, the new page seems to only pull the first record from the database and not the one I am actually selecting. No matter which record you select, you get the same info which happens to be the first record in the database.

Help??
Mar 10 '10 #1
3 2203
Atli
5,058 Expert 4TB
Hey.

Can you show us the code that is pulling the record from the database?

I would bet that the variable you are using for the WHERE clause of your query is somehow being populated as TRUE, rather than the value you are passing via GET.

For example, one of my past mistakes looked something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $id = (int)isset($_GET['id']);
  3. $sql = "SELECT stuff FROM tbl WHERE `id` = {$id}";
  4. mysql_query($sql);
  5. ?>
In there, the return value of the isset() function is being used as the ID, rather than the value passed via the $_GET protocol. - And because TRUE get's converted to 1, the first record of the table would always be pulled out, regardless of what I passed.

The correct version of that should of course be:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['id'])) {
  3.     $id = (int)$_GET['id'];
  4.     $sql = "SELECT stuff FROM tbl WHERE `id` = {$id}";
  5.     mysql_query($sql);
  6. }
  7. else {
  8.     echo "No ID passed!";
  9. }
  10. ?>
Perhaps you are having a similar problem?
Mar 10 '10 #2
isak
2
Here's the code that pulls the info from the database. The bolded text is the link that passes the variable to the detail page:

Expand|Select|Wrap|Line Numbers
  1.  <?php do { ?>
  2.      <tr>
  3.        <td width="162" valign="top"><div align="center"><a href="propertyDetail.php?id=<?php echo $row_rsForm4['id']; ?>"><img src="http://www.txlivingus.com/listings/data/form_4/files/<?php echo $row_rsForm4['element_78']; ?>" alt="Texas Living Real Estate in Centerville | Centerville, Texas" border="0" /></a><a href="propertyDetail.php?id=<?php echo $row_rsForm4['id']; ?>" border="0"></a></div></td>
  4.        <td width="426"><h4><a href="propertyDetail.php?id=<?php echo $row_rsForm4['id']; ?>"><?php echo $row_rsForm4['element_73']; ?> <?php echo $row_rsForm4['element_72']; ?></a> |<a href="<?php echo $row_rsForm4['element_156']; ?>"><?php echo $row_rsForm4['element_74']; ?></a><br />
  5.          $<?php echo number_format($row_rsForm4['element_35'],0,'.',','); ?> / <?php echo $row_rsForm4['element_114']; ?></h4>
  6.            <br />
  7.           <p><?php echo $row_rsForm4['element_53']; ?><br />
  8.          <span class="boldText"><?php echo $row_rsForm4['element_1']; ?> acres</span></p></td>
  9.      </tr>
  10.      <?php } while ($row_rsForm4 = mysql_fetch_assoc($rsForm4)); ?>
Here's the code from the head of the page:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!function_exists("GetSQLValueString")) {
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  4. {
  5.   if (PHP_VERSION < 6) {
  6.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.   }
  8.  
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  11.   switch ($theType) {
  12.     case "text":
  13.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14.       break;    
  15.     case "long":
  16.     case "int":
  17.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18.       break;
  19.     case "double":
  20.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  21.       break;
  22.     case "date":
  23.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24.       break;
  25.     case "defined":
  26.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27.       break;
  28.   }
  29.   return $theValue;
  30. }
  31. }
  32.  
  33. mysql_select_db($database_connTxLiving, $connTxLiving);
  34. $query_rsForm4 = "SELECT * FROM ap_form_4 WHERE ap_form_4.element_114 like 'Active' ORDER BY element_35 DESC";
  35. $rsForm4 = mysql_query($query_rsForm4, $connTxLiving) or die(mysql_error());
  36. $row_rsForm4 = mysql_fetch_assoc($rsForm4);
  37. $totalRows_rsForm4 = mysql_num_rows($rsForm4);
  38. ?>
The coding is done via Dreamweaver CS4.
Mar 11 '10 #3
Atli
5,058 Expert 4TB
Ok.

I don't see you actually fetching and using the ID in the second page. It only uses a static SQL query. - It needs to be something like my second example above; the ID needs to be retrieved and placed in the SQL query.

Also, in your first code, why do you use a do-while loop? Unless there is a copy of the while condition above the loop, the first loop should be outputting an invalid row. - We typically use a simple while loop to iterate through SQL result sets.
Mar 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Robert Smith | last post by:
I'm doing a website development course and during an exercise my teacher gave me to do at home I was confronted with errors. Surprisingly, those that did the exercise in class did not receive...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
28
by: Skeets | last post by:
i'm passing session and hidden variables between pages. not to mention post values. i'm a little concerned that someone with sufficient knowledge could spoof these vlaues and manipulate the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
11
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.