Fetching and Displaying SQL Data

Hi, I wondered if someone would be able to help. I am trying to set up a timetable site for my students, where they can enter their username and then retrieve their timetable. We work on a bi-weekly timetable of 5 lessons per day (e.g. 1Mon1 would be Week 1, Monday, Lesson 1, 1Mon2 would be lesson 2 etc). I have the data all in my database, but I am having problems getting the data out. The code I have below is how far I have gotten but I just keep getting a blank screen. I am very very new to PHP and any help would be massively appreciated.
[php]

<?php $userName = '07cnunn'; $host = "localhost"; $db_name = "conyerst_timetables"; $user = "********"; $pass = "********!"; mysql_connect($host, $user, $pass); mysql_select_db($db_name); $sql=("SELECT core.UserID, wstt.Period, wstt.Lesson, wstt.Staff, wstt.Room\n FROM wstt INNER JOIN core ON wstt.Adno = core.Adno\n WHERE core.UserID=core.UserID='%s'", mysql_real_escape_string($userName)); $result = mysql_query($sql); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } while ($row = mysql_fetch_array($result)) { $field1= $row['core.UserID']; $field2= $row['wstt.Period']; $field3= $row['wstt.Staff']; $field4= $row['wstt.Room']; echo "$field1
"; echo "$field2
"; echo "$field3
"; echo "$field4

"; } mysql_free_result($result); ?>[/php]

OpzMaster: Removed poster’s database username and password. Please do not post your code with your database’s user credentials!

check below 2 line

$conn = mysql_connect($host, $user, $pass);
$dbselected = mysql_select_db($db_name,$conn);

you haven’t do this in your code thru which connection is made to the database.

please do the above changes in your code and execute the program and let me know

Sorry did not see it was a month old

\n are they supposed to be there ?
[php]
wstt.Room\n FROM wstt INNER JOIN core ON wstt.Adno = core.Adno\n
[/php]

make sure you do a mysql query or die error make sure the query is right

[php]
$sql=(“SELECT core.UserID, wstt.Period, wstt.Lesson, wstt.Staff, wstt.Room FROM wstt INNER JOIN core ON wstt.Adno = core.Adno WHERE core.UserID=core.UserID=’%s’”, mysql_real_escape_string($userName)) or die (‘this did not go to plan must find the right fields’);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service