Hi Guys

I'm trying to create a page which uses session data to find a user in a database and then sends the events that this user has signed up to. I'm a bit of a newbie and have got very confused with where I am at. I am using two different tables to get the data, and this is where I'm getting confused. I'm not getting any errors but I'm not recieving any Events. Thanks in Advance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php

$username = $_SESSION['username'];
$email = $_SESSION['user_email'];

$con=mysqli_connect("localhost","emuas","******","EMUAS_signUp");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

echo "<table>
<tr>
<td> Logged in as:</td>
</tr>
<tr>
<th>" . $username . "</th>
</tr>
<tr>
<th>Event</th>
</tr>";

$find = mysqli_query($con,"SELECT * FROM SIGN_UP_TEST WHERE User = '$username'");

while($find_row = mysqli_fetch_array($find)){
    //Get Event ID
    $eventId = $find_row['EventID'];
    //Use Event ID to get Event Name
   $result = mysqli_query($con,"SELECT * TEST WHERE EventID = $eventId ORDER BY StartDate");
//Insert Event Name into table with link from Page Name
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td> <a href='http://www.emuas.co.uk/members/sign_up_sheets/S" . $row['PageName'] . ".php'>" . $row["EventName"] . "</a> </td>";
  echo "</tr>";
  }
  }
echo "</table>";

?>
<body>
</body>
</html>
Member Avatar for Zagga

Hi,

The first thing I would do is see if the database queries are failing.

Try adding
or die(mysqli_error($con);
to the end of each query and see if you get any error messages.

I added the or die bit and it doesn't run. Not sure where the query is going wrong though. I've double checked the tables and fields. Any ideas?

Member Avatar for Zagga

Hi again,

When you say it doesn't run do you mean the query or the page?

Try removing the single quotes around the variables as this stops them being parsed.
Your first query should look like
$find = mysqli_query($con,"SELECT * FROM SIGN_UP_TEST WHERE User = $username") or die(mysqli_error($con));

Give it a go and let us know what happens.

I still get the username outputted along with events in teh table but before that i get the error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Fitzgerald' at line 1"

Member Avatar for Zagga

I guess your username is Fitzgerald?

Are you absolutely sure there is a user column in your SIGN_UP_TEST table?
Is there definitely a user named called Fitzgerald in that table?

There is definitely a colum called user in the SIGN_UP_TEST table, however the username should be Byron Fitzgerald.

Member Avatar for Zagga

Aha, your query is trying to find just Fitzgrald.

You may be setting the name wrongly when you create $_SESSION['username']

I'm calling $_SESSION['username'] in a table to say "You have logged in as $_SESSION['username']" and that gives me the right output, so no to sure about that

after a bit more researh if used INNER JOIN to select the fields. Thanks for teh help anyway.

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.