Forum Moderators: coopster

Message Too Old, No Replies

String format?

         

ekim_mike

7:41 pm on Nov 6, 2003 (gmt 0)

10+ Year Member



I start a session and I want to dump the row_id of a query into the SID.

(modified example from kevin yanks book)
// Start Session
session_start();
if(!isset($_SESSION['shop']))
$_SESSION['shop'] = array();
if (isset($_GET['buy'])) {
// Add ROW['ID'] to the end of the $_SESSION['cart'] array
$_SESSION['shop'][] = $_GET['buy'];
header('location: ' . $_SERVER['PHP_SELF'] . '?' . $SID);

meanwhile:
echo('
<td><center><a href=\" ' . $_SERVER['PHP_SELF'] . '?buy=' . $row['ID'] . ' \"></center></td>');

I can't seem to get the format correct to get the href to show up. The rest of the table is fine and this produces no errors.

lorax

8:45 pm on Nov 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So how much of the URL in the href do you get?

ekim_mike

9:02 pm on Nov 6, 2003 (gmt 0)

10+ Year Member



This is what it returns:
[......inventory...]

This is returning the rowid in the browser but PHP_SELF is not working:
<td><center><a href=\".$_SERVER['PHP_SELF'] .?buy=" .$row['ID']."\">buy</a></center></td>

Robber

12:34 am on Nov 7, 2003 (gmt 0)

10+ Year Member



It looks to me like you are getting a problem because you are escaping the double quotes in the html tag's attributes, but you dont need to do this as you are using single quotes with the echo.

Rather than:
echo('
<td><center><a href=\" ' . $_SERVER['PHP_SELF'] . '?buy=' . $row['ID'] . ' \"></center></td>');

Try:
echo('
<td><center><a href="'.$_SERVER['PHP_SELF'].'?buy='.$row['ID'].'"></center></td>');

You only need to escape the double quotes if you are using double quotes to enclose the string you are echoing.