Code will not work
Moderator: General Moderators
Code will not work
Still trying to get code to work if anyone can tell me the problem ...thanks in advance.
Search Page coded in HTML!
<html>
<head><title>Bookday & Week Search</title></head>
<body>
<br><br>
<h1 align="center" h1><b><FONT COLOR="black">FIND THE RIGHT TIME TO FLY!!</b></font></h1>
<body background="http://images.google.com/images?q=tbn:H ... far/flying">
<div align="center"><center>
<br>
<table border="2" cellspacing="0" width="700">
<tr>
<td align="center" width="700" bgcolor="#00FFFF"><h1
align="center" h1><b>Search by Bookday And Week No.</b></h1>
</td>
</tr>
<tr>
<form action=""bookday&weeknoresults.php" method="post">
<td align="center" valign="top" bgcolor="#66FFFF"
height="67"><p align="center">Select Bookday & Week Number from the Search Lists.
<br> Then Press the Search Button</p>
</td>
</tr>
<tr>
<td height="308" bgcolor="#66FFFF">
<form action=""bookday&weeknoresults.php" method="post">
<br>
<center><h3>Select Bookday:</h3>
<br></center>
<center>Bookday;
<select name="bookday">
<option value="sunday">Sunday</option>
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thursday">Thursday</option>
<option value="friday">Friday</option>
<option value="saturday">Saturday</option>
</select>
<br><br>
<center>Week Number;
<select name="weekno">
<option value="1">Week 1</option>
<option value="2">Week 2</option>
<option value="3">Week 3</option>
<option value="4">Week 4</option>
<option value="5">Week 5</option>
</select>
<br><br>
<input type=submit value="search">
</center>
</form>
</td>
</tr>
</table>
</center></div>
</body>
</html>
________________
Results Page in PHP
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$user = "";
$db = "";
$link = mysql_connect("",$user);
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";
//Connect to database
mysql_select_db($db:, $link)
or die ("Couldn't open $db: ".mysql_error() );
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]';";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else {
echo"<strong>You Searched for: '$_POST[bookday]' & '$_POST[weekno]'</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>
Search Page coded in HTML!
<html>
<head><title>Bookday & Week Search</title></head>
<body>
<br><br>
<h1 align="center" h1><b><FONT COLOR="black">FIND THE RIGHT TIME TO FLY!!</b></font></h1>
<body background="http://images.google.com/images?q=tbn:H ... far/flying">
<div align="center"><center>
<br>
<table border="2" cellspacing="0" width="700">
<tr>
<td align="center" width="700" bgcolor="#00FFFF"><h1
align="center" h1><b>Search by Bookday And Week No.</b></h1>
</td>
</tr>
<tr>
<form action=""bookday&weeknoresults.php" method="post">
<td align="center" valign="top" bgcolor="#66FFFF"
height="67"><p align="center">Select Bookday & Week Number from the Search Lists.
<br> Then Press the Search Button</p>
</td>
</tr>
<tr>
<td height="308" bgcolor="#66FFFF">
<form action=""bookday&weeknoresults.php" method="post">
<br>
<center><h3>Select Bookday:</h3>
<br></center>
<center>Bookday;
<select name="bookday">
<option value="sunday">Sunday</option>
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thursday">Thursday</option>
<option value="friday">Friday</option>
<option value="saturday">Saturday</option>
</select>
<br><br>
<center>Week Number;
<select name="weekno">
<option value="1">Week 1</option>
<option value="2">Week 2</option>
<option value="3">Week 3</option>
<option value="4">Week 4</option>
<option value="5">Week 5</option>
</select>
<br><br>
<input type=submit value="search">
</center>
</form>
</td>
</tr>
</table>
</center></div>
</body>
</html>
________________
Results Page in PHP
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$user = "";
$db = "";
$link = mysql_connect("",$user);
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";
//Connect to database
mysql_select_db($db:, $link)
or die ("Couldn't open $db: ".mysql_error() );
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]';";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else {
echo"<strong>You Searched for: '$_POST[bookday]' & '$_POST[weekno]'</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
use the tags
.. and the PHP
Code: Select all
<html>
<head><title>Bookday & Week Search</title></head>
<body>
<br><br>
<h1 align="center" h1><b><FONT COLOR="black">FIND THE RIGHT TIME TO FLY!!</b></font></h1>
<body background="http://images.google.com/images?q=tbn:Hf4apddYBQMJ:www.millan.net/anims/giffar/flying">
<div align="center"><center>
<br>
<table border="2" cellspacing="0" width="700">
<tr>
<td align="center" width="700" bgcolor="#00FFFF"><h1
align="center" h1><b>Search by Bookday And Week No.</b></h1>
</td>
</tr>
<tr>
<form action=""bookday&weeknoresults.php" method="post">
<td align="center" valign="top" bgcolor="#66FFFF"
height="67"><p align="center">Select Bookday & Week Number from the Search Lists.
<br> Then Press the Search Button</p>
</td>
</tr>
<tr>
<td height="308" bgcolor="#66FFFF">
<form action=""bookday&weeknoresults.php" method="post">
<br>
<center><h3>Select Bookday:</h3>
<br></center>
<center>Bookday;
<select name="bookday">
<option value="sunday">Sunday</option>
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thursday">Thursday</option>
<option value="friday">Friday</option>
<option value="saturday">Saturday</option>
</select>
<br><br>
<center>Week Number;
<select name="weekno">
<option value="1">Week 1</option>
<option value="2">Week 2</option>
<option value="3">Week 3</option>
<option value="4">Week 4</option>
<option value="5">Week 5</option>
</select>
<br><br>
<input type=submit value="search">
</center>
</form>
</td>
</tr>
</table>
</center></div>
</body>
</html>Code: Select all
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$user = "";
$db = "";
$link = mysql_connect("",$user);
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";
//Connect to database
mysql_select_db($db:, $link)
or die ("Couldn't open $db: ".mysql_error() );
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]';";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else {
echo"<strong>You Searched for: '$_POST[bookday]' & '$_POST[weekno]'</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
first error.............
should beyou wrote:Code: Select all
$user = ""; $db = ""; $link = mysql_connect("",$user); if(! $link) die("could not connect to MySQL"); print "Successfully conected to Server<p>";
Code: Select all
$host = "localhost";
$user = "yourname";
$pass = "yourpass";
$link = mysql_connect("$host","$user","$pass");
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
error 2 is..........
should beyou wrote:Code: Select all
$sql = "select destinationfrom,destinationtill,price,bookday,weekno from flights,flightprices where flights.flightid=flightprices.flightid and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]' and flightprices.weekno='$_POST[weekno]';";
Code: Select all
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]'";- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
malcolmboston - Instead of
you should have:
Single variables should not be quoted.
Mac
Code: Select all
$link = mysql_connect("$host","$user","$pass");Code: Select all
$link = mysql_connect($host, $user, $pass);Mac
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
i see no good reason of doig it this way.......
i believe this is much better
edit*
Thanks, ive always done "$var" and never encountered any problems
it could be simplified to.....you wrote:Code: Select all
$user = ""; $db = ""; $link = mysql_connect("",$user); if(! $link) die("could not connect to MySQL"); print "Successfully conected to Server<p>"; //Connect to database mysql_select_db($db:, $link) or die ("Couldn't open $db: ".mysql_error() );
Code: Select all
$host = "localhost";
$user = "yourname";
$pass = "yourpass";
$db = "database";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());edit*
Thanks, ive always done "$var" and never encountered any problems
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
also from what i see of your script your problems are pure syntax wise as the general theory is sound
just some notes for you to take on board
i do not believe that is standard terminology and i have never seen it so your better of sticking with what i stated
just some notes for you to take on board
Code: Select all
// you are checking to see if a var is set
if (isset($var))
// you are checking that a var isnt set
if (!isset($var))Code: Select all
if (! isset($var))
Last edited by malcolmboston on Mon Mar 29, 2004 6:23 am, edited 1 time in total.
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
Still having problems with new code??
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$host = "mysql";
$user = "u2ell";
$pass = "blank";
$db = "u2ell";
$link = mysql_connect("$host","$user","$pass");
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";
//Connect to database
mysql_select_db($db:, $link)
or die ("Couldn't open $db: ".mysql_error() );
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]'";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else {
echo"<strong>You Searched for: '$_POST[bookday]' & '$_POST[weekno]'</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$host = "mysql";
$user = "u2ell";
$pass = "blank";
$db = "u2ell";
$link = mysql_connect("$host","$user","$pass");
if(! $link)
die("could not connect to MySQL");
print "Successfully conected to Server<p>";
//Connect to database
mysql_select_db($db:, $link)
or die ("Couldn't open $db: ".mysql_error() );
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]'";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else {
echo"<strong>You Searched for: '$_POST[bookday]' & '$_POST[weekno]'</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
Sorry this is the error i get when the php opens..mayb not so much an error!
__________________
Bookday & Week No Results
No Results Found.
Please Try Again
"; } else { echo"You Searched for: '$_POST[bookday]' & '$_POST[weekno]'
"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); } } ?>
__________________
Bookday & Week No Results
No Results Found.
Please Try Again
"; } else { echo"You Searched for: '$_POST[bookday]' & '$_POST[weekno]'
"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); } } ?>
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
the vars arent secure so you'll need to sort that out after you've got it working
try this
also make sure there is actually data in the database!!!!
try this
Code: Select all
<?php session_start(); ?>
<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>
<?
$host = "localhost";
$user = "u2ell";
$pass = "blank";
$db = "u2ell";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die (mysql_error());
// the connection to the database was successful
// lets make the vars easier to work with (personal preference)
$bookday = "$_POST[bookday]";
$weekno = "$_POST[weekno]";
//Run Query for search
$sql = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday=$bookday
and flightprices.weekno=$weekno";
//Count Results
$query = mysql_query($sql);
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0)
{
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}
else
{
echo"<strong>You Searched for: $bookday & $weekno</strong></p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>