Lee-Bartlett Posted October 24, 2008 Share Posted October 24, 2008 I am trying to select the row in my db which is echoed on a page. This code makes the button work on the page, a little pop up of a map with specific cords. Only problem is it only goes to the first entry and not the row it is in. Heres the code for both pages. -- The php popup page. -- <?php $link = mysql_connect('localhost','root', 'password'); if($link && mysql_select_db('nexodom_test')) { $sql = "SELECT * FROM tblbasicform WHERE id='id'"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $addr = 'http://maps.google.com/staticmap?center='.$row[latitude].','.$row[longitude].'&zoom=12&size=400x400&key=ABQIAAAAgnVrcDn5i-V_BsqvXy3j8RRle8Rt1EK93-n5qGMjk9aCuGqlpBQ2sCqItCc79KzQksp90dVmLGk45w'; header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); header("Location: $addr"); //echo "We will call this URL: <b>$addr</b>"; //exit(); } echo 'Cannot connect to database'; ?> -- Page where the db and the button which makes the pop up work. -- <?php require_once("includes/db_connection.php"); ?> <html> <head> <script language='javascript' type='text/javascript'> <!-- function openWindow() { popupWin = window.open('popup.php', 'popup', 'width=550,height=400,resizable=no,scrollbars=yes,toolbar=no,screenX=0,screenY=0,Top=0,Left=0') } // --> </script> </head> <body onLoad="load()" onUnload="GUnload()" > <table width="802" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td colspan="2" bgcolor="#0099FF"><p> </p> <p align="center" class="style1">Nexodom.com</p> <p> </p></td> </tr> <tr> <td width="102" height="318" align="left" valign="top"><p><a href="index.html">Home</a><br> <a href="wifi.php">WIFI Hot Spots</a></p> </td> <td width="674" align="left" valign="top"><p align="center">WIFI Hot Spot List</p> <?php $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=2>"; echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Latitude</td><td>Longitude</td> <td>Free or Paid</td><td>New</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['latitude']."</td>"; echo "<td>".$row['longitude']."</td>"; echo "<td>".$row['type']."</td>"; echo "<form>"; echo "<td><input type=\"button\" onClick=\"openWindow(); return false;\" value=\"Pop Up Map\">"; echo "</td></tr>"; echo "</form>"; } ?> </table><br> <a href="userform.php">Submit a WIFI hotspot</a> <br /> <br /> </body> </html> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 24, 2008 Share Posted October 24, 2008 is the popup wifi.php? In your popup's query, you are selecting a row WHERE id = 'id', what exactly does that do? are you ids strings and one happens to be the string "id"? You more than likely need to pass the id to wifi.php like wifi.php?id=some_id and then in wifi.php validate that $_GET['id'] is a number and use that variable in your query WHERE id = {$cleaned_varified_id} Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted October 24, 2008 Author Share Posted October 24, 2008 Ok im fairly new to this, the top code is the pop up, wifi.php is the database where a button is which creats the pop up. If im reading correct, im probally not, in popup.php i need to use $_GET to get my ID from wifi.php? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 24, 2008 Share Posted October 24, 2008 in the link that opens the popup, you need to append ?id=9 to the page's name ie popup.php?id=9 to tell the query get the ninth entry. Looking at your code, you need to edit both the JavaScript function openWindow() and the link that is used to call that function echo "<td><input type=\"button\" onClick=\"openWindow(); return false;\" value=\"Pop Up Map\">"; you could change that to echo "<td><input type=\"button\" onClick=\"openWindow(9); return false;\" value=\"Pop Up Map\">"; and update your openWindow function to this function openWindow(id) { popupWin = window.open('popup.php?id=' + id, 'popup', 'width=550,height=400,resizable=no,scrollbars=yes,toolbar=no,screenX=0,screenY=0,Top=0,Left=0') } Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted October 24, 2008 Author Share Posted October 24, 2008 Still only opens row 1, it broke it when my WHERE id='id' had the ''' arround it, took it away it only opened one row, the array broke + the header, but i think that cause i didnt exit the header. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 24, 2008 Share Posted October 24, 2008 echo this line and work backwards $sql = "SELECT * FROM tblbasicform WHERE id='id'"; Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted October 24, 2008 Author Share Posted October 24, 2008 i get these error messages Warning: Cannot modify header information - headers already sent by (output started at /home/nexodom/public_html/website/popup.php:5) in /home/nexodom/public_html/website/popup.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at /home/nexodom/public_html/website/popup.php:5) in /home/nexodom/public_html/website/popup.php on line 13 Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 24, 2008 Share Posted October 24, 2008 comment out the header calls. You need to see what query is being run and understand how to edit it through $_GET superglobal Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted October 24, 2008 Author Share Posted October 24, 2008 if i edit it all out, i get my echo cannot connect to db, if i un comment 2 headers, i dont get that error anymore Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.