0

Hi I am pretty new to php, trying to do this account page, the php use $session_username to draw out a row(listingname) from the database, the individual result are turned into links, they all link to another php. And what i am trying to do is, $SESSION the specific Listingname as i clicked on it.

For Example, Within the row of Listing name there are John, Ben, Tom, They are within the Array, they are all individual links, when clicked it goes to list.php, and what i want to do is. When John is clicked, $SESSION_['listingname'] will be John, and if Ben is clicked, the $SESSION_['listingname'] will be Ben etc. So then i can use that name to pull more info from the database related to that name inside List.php.

THanks for your time!

php

<?php

ini_set('display_errors', 1); error_reporting(E_ALL);

session_start();
include 'connect.php';

echo "Welcome  ".$_SESSION['username'];
echo "</br>";
echo $_SESSION['password'];
echo "</br>";
echo "</br>";



{





?>

<FORM METHOD="LINK" ACTION="Submitlisting5.php">
<INPUT TYPE="submit" VALUE="Go to submit">
</br>
</br>

</FORM>
Existing List
</br>
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);


include 'connect.php';
$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Listing WHERE username = '$username'")or die( mysqli_error($con));

while ($row = mysqli_fetch_assoc($result))
        {

          echo '<a href="SpecificListing.php">'.$row['Listingname'].'</br>';
        }
        $_SESSION['Listingname']=$row['Listingname'];
}



?>
4
  • What is method="link"? You should use POST or GET. Commented Nov 26, 2013 at 13:48
  • Your html is invalid. Replace </br>s to <br />. Also, xhtml is lower-case. Commented Nov 26, 2013 at 13:58
  • @ArlaudAgbePierre that is for another button on the page, i have a button that links to another php. Commented Nov 26, 2013 at 14:01
  • @aksu that part is ok at the moment, but i can't really figure out how to $SESSION the individual result from the array, as described in the question. Commented Nov 26, 2013 at 14:02

1 Answer 1

1

You should pass the link to the next page.

For instance :

echo '<a href="SpecificListing.php?listingName='.urlencode($row['Listingname']).'">'.$row['Listingname'].'</br>';

And on SpecificListing.php you can set

$_SESSION['Listingname'] = $_GET['listingName'];
Sign up to request clarification or add additional context in comments.

3 Comments

Am i doing something wrong? cos i am getting Undefined index: Listingname in, but if i pass the whole Array across, would i still be able to Session just that particular item within the array?
This is the the link that is created inside the loop that fetches $result into $row. Every link is different because its url will contain a get parameter with the right Listingname.
I just managed to get that to work, i have no idea why, i didn't change anything i just refreshed and it suddenly works :) Thanks so much for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.