Forum Moderators: coopster
Ok here is the scene... I have created a database called horses with a table called Tracks also have a fieldname called Tracks which holds horse track names ie Aintree, Newbury etc etc.
I am trying to pass an individual trackname as a $ to the next page so that i don't have to make 59 seperate pages one to display each tracks details.
Essentially i have made a table which I can use as a template on another page and intened to just insert the following in the row of the table required.
<?php
/* This program places the info into a table */
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("Horses");
$sql = "select * from Tracks where Tracks ='$Tracks'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
printf("<left><font face=arial color=\"blue\"><font size=\"2\">%s</font></font>\n",
$row["Tracks"]);
}
?>
That code should work fine and i have already inserted the $Tracks in the connection line.
However my problem lies in passing the $Tracks from the previous page the idea is to have a list on the page with the 59 courses as links when you click on the link it sends you to the page above and passes the name of the link that you clicked on as $Tracks.
This is the current setup of the page but is setup just to open the seperate file instead of passing the $Tracks how can i change it so it passes on the $Tracks instead of openeing it's own page?
If this doesnt make any sense at all then I can see no easier way of explaining it...
<?php
/* This program lists Tracks on the database */
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("Horses");
$sql = "select * from Tracks";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
print '<img src="gfx/redbullet.gif" />';
printf("<left><font face=arial color=\"#000066\"></font><font size=\"-4\"><a href=\" %scoursedata.php\">%s</a>\n",
$row["Tracks"], $row["Tracks"]);
}
?>
Any ideas would be apreciated
Thanks
You mentioned
“Where tracks=$tracks
I assume that $tracks is passed via a form
If not how do you set a value for it?
If it passes through a form then
We will use a SESSION
On the VERY TOP of each concerned page add
<? session_start();
// get the Tracks value
$tracks=$_POST[‘tracks’];
// then we use the value now posted of tracks
// to create a SESSION
$_SESSION[‘tracks’]=$tracks
?>
USING IT
<? Session_start();
// to use $tracks on another page
$tracks=$_SESSION[‘tracks’];
// rest of script
?>
No it's not being passed from a form which is the whole problem but surely if it can print the name to the screen then there must be some way of turning into $Tracks and passing it to the next page.
The following line picks the name from the database and adds it to coursedata.php to create the filename Aintreecoursedata.php as a link so why cant it pass the name Aintree onto the next page?
The template page being coursedata.php instead of having 1 page for each course like i am having to do at present.
printf("<left><font face=arial color=\"#000066\"></font><font size=\"-4\"><a href=\" %scoursedata.php\">%s</a>\n",
$row["Tracks"], $row["Tracks"]);
do something like
echo "line24.$tracks";
echo "line36.$tracks";
so you know what's ref to what
if it does not pass then it will read for example
line36."the rest will be empty"
Next: Instead of passing a var try to pass a direct value so you will know if there is a glitch in the script
$tracks="test";
and figure if the session works
by echoing that value to your next page.
also after session_start();
add
error_reporting (E_ALL);
and report what it reads
<? Session_start();
error_reporting (E_ALL);
// to use $tracks on another page
$Tracks=$_SESSION["Tracks"];
// rest of script
?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Track Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="680" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td colspan="3"><font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><strong>Track:
</strong></font><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
<?php
/* This program gets members info from the database */
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("Horses");
$sql = "select * from Tracks WHERE Tracks = '$Tracks'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
printf("<left><font face=arial color=\"blue\"><font size=\"2\">%s</font></font>\n",
$row["Tracks"]);
}
?>
</font></b></font></b></font></b></font><font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><strong>
</strong></font></td>
</tr>
<tr>
<td width="150" height="130" rowspan="4" valign="top"> <table width="150" height="130" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="150" height="130"><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
</font></b></font></b></font></b></font></td>
</tr>
</table></td>
<td width="150" height="130" rowspan="4" valign="top"><table width="150" height="130" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="20">
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Address:</strong></font></div></td>
</tr>
<tr>
<td width="150" height="110"><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
</font></b></font></b></font></b></font></td>
</tr>
</table></td>
<td height="69" valign="top"> </td>
</tr>
<tr>
<td height="20" valign="bottom"><strong><font size="2" face="Arial, Helvetica, sans-serif">Telephone:</font><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
</font></b></font></b></font></b></font></strong></td>
</tr>
<tr>
<td height="20" valign="bottom"><strong><font size="2" face="Arial, Helvetica, sans-serif">Email:</font><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
</font></b></font></b></font></b></font></strong></td>
</tr>
<tr>
<td height="21" valign="bottom"><strong><font size="2" face="Arial, Helvetica, sans-serif">Website:</font><font size="2" face="Arial" color="#3333FF"><b><font size="2" face="Arial" color="#3333FF"><b><font face="Arial" size="3"><b><font color="#000000" size="4">
</font></b></font></b></font></b></font></strong></td>
</tr>
</table>
</body>
</html>
OK
you sre missing a " ; "
here:$Tracks=$_POST[‘Tracks’];
// then we use the value now posted of tracks
// to create a SESSION
$_SESSION[‘Tracks’]=$Tracks
it should read
$Tracks=$_POST[‘Tracks’];
// then we use the value now posted of tracks
// to create a SESSION
$_SESSION[‘Tracks’]=$Tracks;
here is the following error message that im still getting....
Notice: Undefined index: tracks in /horses/Aintreecoursedata.php on line 4
Notice: Undefined index: tracks in /horses/Aintreecoursedata.php on line 5
VerifySession.
Anyway here is the error message im now getting..
and no it's not passing anything as your Verify Session is coming back blank...
Notice: Undefined index: Tracks in /home/jshyeuwt/public_html/horses/Aintreecoursedata.php on line 4
VerifySession.
<? session_start();
// get the Tracks value
$Tracks=$_POST[‘Tracks’];
// then we use the value now posted of tracks
// to create a SESSION
$_SESSION[‘Tracks’]=$Tracks
try this from the very first page
<? session_start();
// get the Tracks value
$Tracks=11111;
// then we use the value now posted of tracks
// to create a SESSION
$_SESSION[‘Tracks’]=$Tracks;
// we set a value to tracks.
second page
<? Session_start();
//error_reporting (E_ALL);
// to use $tracks on another page
$Tracks=$_SESSION["Tracks"];
echo"TestSession.$tracks";
// should read: TestSession1111
// rest of script
Note we have commented error reporting
we are testing your db with 2 values id and horses
if no id and horses exist then change by whatever is in your table, remember to do the changes in the 2 locations that call for those field names
mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("Horses");
$sql = "select id, horses from Tracks WHERE Tracks = '$Tracks'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
printf("id: %s horses: %s", $row[0], $row[1]);
}
what is the HTML for?
each td seems to be empty?
The html is so that i can insert the php code into each part of the table seperately.
By just getting one to work copy and pasting it then changing the field name that it refers too......
There must be a simple way of doing this the session we are trying is not working as it has no information to pass unless we manually give it one.
It is getting the info from the database then displaying it and creating a link to %scoursedata.php which i made to originally go to a page corresponding to the track name....
This line can be changed as i no longer wish to do it like that i want all output for all tracks going to a page called coursedata which then will just need the $Tracks info passed to display the relevant info.
But essentially it has already created a variable as it already puts it in the filename to create the link so we just need to capture that and send it to the next page.
But until you click on the link then it wont know which track you want so it can't pass the info on.....
printf("<left><font face=arial color=\"#000066\"></font><font size=\"-2\"><a href=\" %scoursedata.php\">%s</a>\n",
$row["Tracks"], $row["Tracks"]);
echo "line24.$tracks";
Little tip. This will change when you edit, so it's easier to use
echo "Tracks = $tracks (" . __FILE__ . " :: " . __LINE__ . ")";
Notice: Use of undefined constant ‘Tracks’
That typically means you left out a $ before a variable name or you have an unquoted array index as in $row[Tracks]. I didn't see either in your code though.
Similarly for undefined index.