Page 1 of 1

Code will not work

Posted: Mon Mar 29, 2004 5:45 am
by eoinmick
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);
}
}
?>

Posted: Mon Mar 29, 2004 5:46 am
by twigletmac
What isn't working?

Mac

Posted: Mon Mar 29, 2004 5:47 am
by malcolmboston
use the tags

Code: Select all

&lt;html&gt; 
&lt;head&gt;&lt;title&gt;Bookday &amp; Week Search&lt;/title&gt;&lt;/head&gt; 

&lt;body&gt; 
&lt;br&gt;&lt;br&gt; 
&lt;h1 align="center" h1&gt;&lt;b&gt;&lt;FONT COLOR="black"&gt;FIND THE RIGHT TIME TO FLY!!&lt;/b&gt;&lt;/font&gt;&lt;/h1&gt; 
&lt;body background="http://images.google.com/images?q=tbn:Hf4apddYBQMJ:www.millan.net/anims/giffar/flying"&gt; 
&lt;div align="center"&gt;&lt;center&gt; 
&lt;br&gt; 
&lt;table border="2" cellspacing="0" width="700"&gt; 
&lt;tr&gt; 
&lt;td align="center" width="700" bgcolor="#00FFFF"&gt;&lt;h1 
align="center" h1&gt;&lt;b&gt;Search by Bookday And Week No.&lt;/b&gt;&lt;/h1&gt; 
&lt;/td&gt; 
&lt;/tr&gt; 

&lt;tr&gt; 
&lt;form action=""bookday&amp;weeknoresults.php" method="post"&gt; 
&lt;td align="center" valign="top" bgcolor="#66FFFF" 
height="67"&gt;&lt;p align="center"&gt;Select Bookday &amp; Week Number from the Search Lists. 
&lt;br&gt; Then Press the Search Button&lt;/p&gt; 
&lt;/td&gt; 
&lt;/tr&gt; 

&lt;tr&gt; 
&lt;td height="308" bgcolor="#66FFFF"&gt; 


&lt;form action=""bookday&amp;weeknoresults.php" method="post"&gt; 
&lt;br&gt; 
&lt;center&gt;&lt;h3&gt;Select Bookday:&lt;/h3&gt; 
&lt;br&gt;&lt;/center&gt; 
&lt;center&gt;Bookday; 
&lt;select name="bookday"&gt; 
&lt;option value="sunday"&gt;Sunday&lt;/option&gt; 
&lt;option value="monday"&gt;Monday&lt;/option&gt; 
&lt;option value="tuesday"&gt;Tuesday&lt;/option&gt; 
&lt;option value="wednesday"&gt;Wednesday&lt;/option&gt; 
&lt;option value="thursday"&gt;Thursday&lt;/option&gt; 
&lt;option value="friday"&gt;Friday&lt;/option&gt; 
&lt;option value="saturday"&gt;Saturday&lt;/option&gt; 
&lt;/select&gt; 

&lt;br&gt;&lt;br&gt; 

&lt;center&gt;Week Number; 
&lt;select name="weekno"&gt; 
&lt;option value="1"&gt;Week 1&lt;/option&gt; 
&lt;option value="2"&gt;Week 2&lt;/option&gt; 
&lt;option value="3"&gt;Week 3&lt;/option&gt; 
&lt;option value="4"&gt;Week 4&lt;/option&gt; 
&lt;option value="5"&gt;Week 5&lt;/option&gt; 
&lt;/select&gt; 

&lt;br&gt;&lt;br&gt; 

&lt;input type=submit value="search"&gt; 

&lt;/center&gt; 
&lt;/form&gt; 

&lt;/td&gt; 
&lt;/tr&gt; 

&lt;/table&gt; 
&lt;/center&gt;&lt;/div&gt; 
&lt;/body&gt; 
&lt;/html&gt;
.. and the PHP

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); 
} 
} 
?>

Posted: Mon Mar 29, 2004 5:49 am
by malcolmboston
first error.............
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>";
should be

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>";

Posted: Mon Mar 29, 2004 5:55 am
by malcolmboston
error 2 is..........
you 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]';";
should be

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]'";

Posted: Mon Mar 29, 2004 5:55 am
by twigletmac
malcolmboston - Instead of

Code: Select all

$link = mysql_connect("$host","$user","$pass");
you should have:

Code: Select all

$link = mysql_connect($host, $user, $pass);
Single variables should not be quoted.

Mac

Posted: Mon Mar 29, 2004 5:59 am
by malcolmboston
i see no good reason of doig it this way.......
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() );
it could be simplified to.....

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());
i believe this is much better

edit*
Thanks, ive always done "$var" and never encountered any problems :?

Posted: Mon Mar 29, 2004 6:11 am
by malcolmboston
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

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))
i do not believe that

Code: Select all

if (! isset($var))
is standard terminology and i have never seen it so your better of sticking with what i stated

Posted: Mon Mar 29, 2004 6:23 am
by eoinmick
thanks alot project phrozen! Will take on board

Posted: Mon Mar 29, 2004 6:24 am
by malcolmboston
eoinmick wrote:thanks alot project phrozen! Will take on board
the names malcolmboston 8)

Posted: Mon Mar 29, 2004 6:36 am
by eoinmick
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);
}
}
?>

Posted: Mon Mar 29, 2004 6:38 am
by malcolmboston
you havent taken on board what i told you

read my articles again then come back

and it would help massively if you actually gave us your error message

Posted: Mon Mar 29, 2004 6:56 am
by eoinmick
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); } } ?>

Posted: Mon Mar 29, 2004 6:59 am
by malcolmboston
the vars arent secure so you'll need to sort that out after you've got it working

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); 
} 
} 
?>
also make sure there is actually data in the database!!!!