d239113g Posted April 15, 2008 Share Posted April 15, 2008 Hello, I am a relitive newbie to php/mysql, and i am having some problems with it at the moment. What i am trying to do is pull course data from my database, and post them as links on the page, (tmc.php) and then when you click on one of those links, it then opens a new page (courses.php) and gets the course data of that link and displays it in courses.php. The 1st part is working fine, (tmc.php) is displaying the course links on the page, but then when i click on one of the links, no data is being pulled from the database. (tmc.php) <?php $con = mysql_connect("localhost","xxxxxx","xxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxx", $con); $mystring = "Select CourseName from Course"; $result = mysql_query ($mystring); while($row = mysql_fetch_array($result)) { // 1st is the Key, 2nd is what is displayed on screen echo "<a href='courses.php?Link1=".$row ['CourseID']."'>".$row['CourseName']."  </a>"; echo "<br>"; } ?> (courses.php) <? $tester = $_GET['Link1']; $con = mysql_connect("localhost","xxxxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxx", $con); $mystring = "Select * from CourseDetails = '".$tester."'"; $result = mysql_query ($mystring); while($row = mysql_fetch_array($result,MYSQL_NUM)) { foreach($row as $attribute) echo $attribute."<br>"; } ?> so when courses.php opens it should show the course information of the link that was clicked. my tables are Course CourseID CourseName CourseDetails CourseID Title Section1 Section2 Section3 Section4 Can somebody help me with this please, as i am going to cry soon :'( Thank You J Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 Verify your query: $mystring = "Select * from CourseDetails = '".$tester; echo $mystring; Make sure the query succeeds: $result = mysql_query($mystring) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 I can't see anything that would make it not work. I agree with hitman, and I would go a step further. 1. Verify that your get is working: $tester = $_GET['Link1']; echo $tester; 2. Then verify that your SQL is what you want: echo $mystring; Go step by step until you find the trouble. Quote Link to comment Share on other sites More sharing options...
d239113g Posted April 15, 2008 Author Share Posted April 15, 2008 Hi, Thanks for your reply guy's. I have put an echo in for $mystring and $tester and now when i click on of the links i get an SQL error. Select * from CourseDetails = ''You have an error in your SQL syntax near '''' at line 1 . I must be pretty simple, but i just cannot see where it is going wrong. When the link is clicked, i want all the information of that course/link to be displayed in courses.php, so SELECT * FROM CourseDetails would be right would it not ? ??? Many Thanks Jon http://www.tmet02.co.uk/TyneMetProject/tmc.php courses.php <?php $tester = $_GET['Link1']; echo $tester; $con = mysql_connect("localhost","xxxxxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxx", $con); $mystring = "SELECT * FROM CourseDetails = '".$tester."'"; echo $mystring; $result = mysql_query ($mystring) or die(mysql_error()); while($row = mysql_fetch_array($result)) { foreach($row as $attribute) echo $attribute."<br>"; } ?> tmc.php <?php $con = mysql_connect("localhost","xxxxxxx","xxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxx", $con); $mystring = "Select CourseName from Course"; $result = mysql_query ($mystring); while($row = mysql_fetch_array($result)) { // 1st is the Key, 2nd is what is displayed on screen echo "<a href='courses.php?Link1=".$row ['CourseID']."'>".$row['CourseName']."  </a>"; echo "<br>"; } ?> Quote Link to comment Share on other sites More sharing options...
d239113g Posted April 15, 2008 Author Share Posted April 15, 2008 Well i figured out that my SQL statement on tmc.php was wrong . Should of been : $mystring = "SELECT CourseName, CourseID FROM Course"; I have now changed to this, and now when i click a link i get an error : You have an error in your SQL syntax near ''1'' at line 1 http://www.tmet02.co.uk/TyneMetProject/tmc.php http://www.tmet02.co.uk/TyneMetProject/courses.php?Link1=1 Can anybody help me with the problem now ? now i am getting an error message, instead of of nothing. Cheers J 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.