Jump to content

$_GET['Link1'] help please


d239113g

Recommended Posts

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']." &nbsp</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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']." &nbsp</a>";
echo "<br>";
}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.