/    Sign up×
Community /Pin to ProfileBookmark

Please Help, Stumped, looked at code so long, just don’t see why not working.

New to PHP, have seent several codes for pagination. The code below has all I want in the code. I run code I get results for first page, and subsequent href tags for pages. When I click on link it runs again inserted pg num and limit into the sql statement, but pg num is being reset to O or the pg num is not being stored or recalled. So I get, “No results found matching your query”.

[CODE] the query.
$numrows = mysql_num_rows($numresults);
if ($numrows == 0){
echo(“No results found matching your query – $query”); // bah, modify the “Not Found” error for your needs.
exit();}[/CODE]

You can view the php page in action by following this link, [url]www.historiccharlestonsc.net/accomodations/accomodations.html[/url] just fill in the form and search it will take you to the results from the php page.

The complete code is as follows: (I omitted the actual db name and passwords.)

[CODE]
</head>

<?php

// declare variables
$city= $_POST[location];
$accommodationstype=$_POST[accomodations_type];
$roomrates= $_POST[room_rates];
$theme=$_POST[theme];
$dining=$_POST[dining];
$breakfast=$_POST[breakfast];
$roomservice=$_POST[room_service];
$pool=$_POST[pool];
$gym=$_POST[gym];
$spaservices=$_POST[spa_services];
$airportpickup=$_POST[airport_pickup];
$internetaccess=$_POST[internet_access];
$businesscenter=$_POST[business_center];
$banquetfacilities=$_POST[banquet_facilities];
$conferencerooms=$_POST[conference_rooms];
$meetingrooms=$_POST[meeting_rooms];
$frontdesk=$_POST[front_desk];
$parking=$_POST[parking];
$petfriendly=$_POST[pet_friendly];
$conciergeservices=$_POST[concierge_services];
$rating=$_POST[rating];

if (!isset($_POST[‘submit’]))

$localhost=”######”; //the name of the host
$dbname=”########”; // the name of the database
$dbsearch=”##############”; // user name
$dbpass=”##########################”; // password
$results = mysql_query;

// connect to mysql server on inmotionhosting
$db=mysql_connect($localhost, $dbsearch, $dbpass) or die(“Connection Failure to Database”); //(host, username, password)

// select correct db histor28_data from mysql server
mysql_select_db($dbname, $db) or die ($dbname . ” <p><font size=”+3″>Unable to connect to the database server.</font></p>. ” . $dbsearch);

if (!($db)) // If no connect, error and exit().
{
echo( “<p><font size=”+3″>Unable to connect to the database server.</font></p>”);
exit();
}
if (!(@mysql_select_db($dbname))) // If can’t connect to database, error and exit().
{
echo(“<p>Unable to locate the $db_name database.</p>”);
exit();
}
if (!($page)){
$page = 0;} // Default page value.
if (!($limit)){
$limit = 10;} // Default results per-page.

$numresults = mysql_query(“SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM `hoteldata` WHERE city like ‘$city’ and accomodations_type like ‘$accommodationstype’ and rating like ‘$rating’ and room_rates like ‘$roomrates’ and theme like ‘$theme’ “); // the query.

$numrows = mysql_num_rows($numresults);
if ($numrows == 0){
echo(“No results found matching your query – $query”); // bah, modify the “Not Found” error for your needs.
exit();}

$pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows%$limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $numrows;} // If last results page, last result equals total number of results.

//escape from PHP mode.
?>

<!– end Search by multi categories –>

</head>
<body>
<div id=”header”>
<div id=”splash”>
<div id=”logo”><a href=”http://www.historiccharlestonsc.net/index.html” title=”Historic Charleston Harbor”><strong>Historic Charleston SC</strong></a>.net</div>
<div id=”navigation”><a href=”http://www.historiccharlestonsc.net/index.html”><img src=”http://www.historiccharlestonsc.net/images/historiccharlestonbanner.jpg” alt=”Historic Charleston Harbor” width=”950″ height=”160″ id=”arthurravenelbridge” name=”arthurravenelbridge” /></a><br />
</div>
</div>
</div>

<div id=”wrapper”>
<div id=”page”>

<div id=”content”>

<br />

<table width=”480″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td align=”center” bgcolor=”#333333″><font size=”+2″><?=$numrows?> Search Results Found</font><br /><br /></td>
</tr>
<tr>
<td align=”left” bgcolor=”#333333″>&nbsp; &nbsp; Page –

<?
if ($page != 0) { // Don’t show back link if current page is first page.
$back_page = $page – $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit”>back</a> n”);}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i – 1);
if ($ppage == $page){
echo(“<b>$i</b> n”);} // If current page don’t give link, just text.
else{
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit”>$i</a> n”);}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don’t give next link.
$next_page = $page + $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit”>next</a>n”);}
?>
</td>
</tr>
<tr>
<td align=”right” bgcolor=”#333333″>
Results per-page: <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5″>5</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10″>10</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20″>20</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50″>50</a>&nbsp; &nbsp;<br /><br /></td></tr></table>

<?php

$results = mysql_query(“SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM `hoteldata` WHERE city like ‘$city’ and accomodations_type like ‘$accommodationstype’ and rating like ‘$rating’ and room_rates like ‘$roomrates’ and theme like ‘$theme’ ORDER by name ASC LIMIT $page, $limit”); // the query.

echo “<table width=”480″ border=”1″ cellpadding=”15″ cellspacing=”0″>”;
while ($row = mysql_fetch_array($results))
{
echo “<tr>”;
echo “<td bgcolor=”#333333″ width=”75px” align=”left”><img src=$row[logo]><br /><h5>Property Type:<br />$row[accomodations_type]<br /><br />
Theme:<br />$row[theme]<br /><br />
$row[webadd]<br /><br />
</h5><img src=$row[pmt_methods]></td>”;

echo “<td bgcolor=”#333333″><p align=”center”><h4>$row[name]</h4>
$row[address], $row[city]<br /><br /></p>

<p>| <A HREF=$row[reviewadd]
onClick=”return popup(this, ‘notes’)”>Review</a> | <a href=$row[amenities]
onClick=”return popup(this, ‘notes’)”>Amenities</a> | <a href=$row[map]
onClick=”return popup(this, ‘notes’)”>Map</a> | <a href=$row[reservation_page]
onClick=”return popup(this, ‘notes’)”>Reservations</a> |</p>

<h5 align=”left”>$row[description]</h5>
<h6 align=”left”>$row[recommended]</h6></td>”;
echo “</tr>”;
}
echo “</table>”;
?>

<table width=”480″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td bgcolor=”#333333″ align=”left”><br />&nbsp; &nbsp; Page –

<?
if ($page != 0) { // Don’t show back link if current page is first page.
$back_page = $page – $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit”>back</a> n”);}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i – 1);
if ($ppage == $page){
echo(“<b>$i</b> n”);} // If current page don’t give link, just text.
else{
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit”>$i</a> n”);}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don’t give next link.
$next_page = $page + $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit”>next</a>n”);}
?>

</td>
<tr>
<td align=”right” bgcolor=”#333333″>
Results per-page: <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5″>5</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10″>10</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20″>20</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50″>50</a>&nbsp; &nbsp;<br /><br /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
[/CODE]

I just don’t know enough to figure out what I am doing wrong.

Thanks.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@DasherNov 14.2010 — On line 34 is $results = mysql_query; Which should cause a php error when encountered.

Also when you mouse over the link for results per page you can look at the url in the status line of the browser;

i.e. "http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=&page=0&limit=10"

The parameter for query= is empty. $query is not defined anywhere in the code.
Copy linkTweet thisAlerts:
@jej704authorNov 14.2010 — Thanks Dasher I saw the line 34 problem right after I posted this and removed it. What I did was to name the mysql_query, $query Which makes the sql statement the $query correct? That is how I understood what you said. Now I get a resource id #3 where ?query=$query
Copy linkTweet thisAlerts:
@DasherNov 14.2010 — I don't see in your code where you "get" the values of query, page, and limit. Since these are part of the url you should have something like this code added;
[code=php]
$myquery = "SELECT * FROM hoteldata
WHERE city like '$city' and accomodations_type like '$accommodationstype' and rating like '$rating' and room_rates like '$roomrates' and theme like '$theme'
ORDER by name ASC
LIMIT $page, $limit"); // the query.

if(isset($_GET['page'])){$page = $_GET['page'];} else {$page=0;}
if(isset($_GET['limit'])){$limit = $_GET['limit'];} else {$limit=10;}
if(isset($_GET['query'])){$query = $_GET['query'];} else {$query=$myquery;}
//echo $query.", ".$page.", ".$limit."<br>";
[/code]


Also you are using php script shortcuts such as;

[CODE]
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | //etc

But many php processors do not recognize the <?= ?> short cuts and require the full <?php echo $page; ?>

That may or may not be a problem. I always use the complete method.

You can check your php.ini file to see if short_open_tags = Off or On

; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On

[/CODE]


Or you could do something like this;

[code=php]
echo "Results per-page: <a href="$_SERVER[PHP_SELF]?query=".$query."&page=".$page."&limit=5">5</a>" ; //etc

[/code]


I also noticed in the actual site that when you click on information about a particular hotel that the popup may return information about a different hotel than the one selected.
Copy linkTweet thisAlerts:
@DasherNov 14.2010 — One other thing your query in the url should be formatted with ;

$query = urlencode($query);

It should not say something like Resource ID #3
Copy linkTweet thisAlerts:
@jej704authorNov 17.2010 — OK Dasher, I believe now that I have $query declared and I still have the same problem. The parameter for query= is empty. I must be lost totally!

New code looks just like this:
[CODE]<?php

// get post from hotel search form
if (!isset($_POST['submit'])) // if page is not submitted to itself echo the form

if(isset($_GET['page'])){$page = $_GET['page'];} else {$page=0;}
if(isset($_GET['limit'])){$limit = $_GET['limit'];} else {$limit=10;}
if(isset($_GET['query'])){$query = $_GET['query'];} else {$query=$myquery;}

$city= $_POST[location];
$accommodationstype=$_POST[accomodations_type];
$roomrates= $_POST[room_rates];
$theme=$_POST[theme];
$dining=$_POST[dining];
$breakfast=$_POST[breakfast];
$roomservice=$_POST[room_service];
$pool=$_POST[pool];
$gym=$_POST[gym];
$spaservices=$_POST[spa_services];
$airportpickup=$_POST[airport_pickup];
$internetaccess=$_POST[internet_access];
$businesscenter=$_POST[business_center];
$banquetfacilities=$_POST[banquet_facilities];
$conferencerooms=$_POST[conference_rooms];
$meetingrooms=$_POST[meeting_rooms];
$frontdesk=$_POST[front_desk];
$parking=$_POST[parking];
$petfriendly=$_POST[pet_friendly];
$conciergeservices=$_POST[concierge_services];
$rating=$_POST[rating];

$localhost="localhost"; //the name of the host
$dbname="*"; // the name of the database
$dbsearch="*"; // user name
$dbpass="*L"; // password

$db=mysql_connect($localhost, $dbsearch, $dbpass) or die("Connection Failure to Database"); //(host, username, password)

mysql_select_db($dbname, $db) or die ($dbname . " <p><font size="+3">Unable to connect to the database server.</font></p>. " . $dbsearch);


if (!($db)) // If no connect, error and exit().
{
echo( "<p><font size="+3">Unable to connect to the database server.</font></p>");
exit();
}
if (!(@mysql_select_db($dbname))) // If can't connect to database, error and exit().
{
echo("<p>Unable to locate the $db_name database.</p>");
exit();
}
if (!($page)){
$page = 0;} // Default page value.
if (!($limit)){
$limit = 10;} // Default results per-page.

$numresults = mysql_query("SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM hoteldata WHERE city like '$city' and accomodations_type like '$accommodationstype' and rating like '$rating' and room_rates like '$roomrates' and theme like '$theme' "); // the query.

$numrows = mysql_num_rows($numresults);

if ($numrows == 0){
echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs.
exit();}

$pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows%$limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $numrows;} // If last results page, last result equals total number of results.

//escape from PHP mode.
?>

<!-- end Search by multi categories -->

</head>
<body>

<div id="content">

<br />

<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="#333333"><font size="+2"><?=$numrows?> Search Results Found</font><br /><br /></td>
</tr>
<tr>
<td align="left" bgcolor="#333333">&nbsp; &nbsp; Page -

<?php

$myquery = mysql_query("SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM hoteldata WHERE city like '%$city%' and accomodations_type like '%$accommodationstype%' and rating like '%$rating%' and room_rates like '%$roomrates%' and theme like '%$theme%' ORDER by name LIMIT $page, $limit"); // the query.

$query = mysql_query($myquery);

$query = urlencode($query);

if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit">back</a> n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> n");} // If current page don't give link, just text.
else{
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit">$i</a> n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit">next</a>n");}
?>

</td>
</tr>
<tr>
<td align="right" bgcolor="#333333">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>&nbsp; &nbsp;<br /><br /></td></tr></table>

<?php

// Now we can display results.

echo "<table width="480" border="1" cellpadding="15" cellspacing="0">";
while ($row = mysql_fetch_assoc($myquery))
{
echo "<tr>";
echo "<td bgcolor="#333333" width="75px" align="left"><img src=$row[logo]><br /><h5>Property Type:<br />$row[accomodations_type]<br /><br />
Theme:<br />$row[theme]<br /><br />
$row[webadd]<br /><br />
</h5><img src=$row[pmt_methods]></td>";

echo "<td bgcolor="#333333"><p align="center"><h4>$row[name]</h4>
$row[address], $row[city]<br /><br /></p>

<p>| <A HREF=$row[reviewadd]
onClick="return popup(this, 'notes')">Review</a> | <a href=$row[amenities]
onClick="return popup(this, 'notes')">Amenities</a> | <a href=$row[map]
onClick="return popup(this, 'notes')">Map</a> | <a href=$row[reservation_page]
onClick="return popup(this, 'notes')">Reservations</a> |</p>

<h5 align="left">$row[description]</h5>
<h6 align="left">$row[recommended]</h6></td>";
echo "</tr>";
}
echo "</table>";
// always close database connection – now at the end of the file
mysql_close($db);
?>

<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#333333" align="left"><br />&nbsp; &nbsp; Page -

<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit">back</a> n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> n");} // If current page don't give link, just text.
else{
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit">$i</a> n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit">next</a>n");}
?>

</td>
<tr>
<td align="right" bgcolor="#333333">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>&nbsp; &nbsp;<br /><br /></td>
</tr>
</table>
</td>
</tr>
</table>[/CODE]


I am banging head against wall! You can see how it is working by following link again http:// www.historiccharlestonsc.net/accomodations/accomodations.html
Copy linkTweet thisAlerts:
@DasherNov 17.2010 — You have quite a mess here. You are trying to execute a query when all you want to do is to pass it back to the page to recreate the same data with a different number of items, or a different page of the same data.

You want the number of items links to look something like this;

[code=php]

echo "<a href="http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=SELECT+&#37;2A+FROM+%60hoteldata%60+WHERE+city+LIKE+%27%251%25%27+AND+accomodations_type+LIKE+%27%252%25%27+AND+rating+LIKE+%27%252%25%27+AND+room_rates+LIKE+%27%252%25%27+AND+theme+LIKE+%27%251%25%27+ORDER+BY+name+LIMIT+0%2C+10&page=0&limit=10">10</A>";

[/code]


[B][COLOR="Red"]IMPORTANT: However including an actual query in a url is a very dangerous practice[/COLOR] since someone could easily change the query from a SELECT to an INSERT and create all sorts of mischief to your database. [/B]

[B]It would be better to save the users selections of location, room rates, etc. in cookies or as session variables[/B]. So the first time the user makes those selections they will get stored somewhere and not have be recreated in a dangerous $query. Since all you really want to do is change the number of items displayed on a particular page or to get the next page.

I don't like to use the practice of doing a mysql query and defining the query all in the same line.

Instead I do this;

[code=php]
$query = "SELECT * FROM hoteldata
WHERE city LIKE '%$city%'

AND accomodations_type LIKE '%$accommodationstype%'
AND rating LIKE '%$rating%'
AND room_rates LIKE '%$roomrates%'
AND theme LIKE '%$theme%'
ORDER by name LIMIT $page, $limit"; // the query.

$results = mysql_query($query);

$numresults = mysql_num_rows($results);



[/code]


I get the impression you are attempting to fix some code that someone else originally created.
Copy linkTweet thisAlerts:
@jej704authorNov 18.2010 — Yes you are correct being knew to this I have very little expertise in writing code. I modify examples that hopefully do what I would like them to do. I had not thought about the possibility of someone changing an sql statement I guess I better look at calling stored statements or something like that also. I have never tried cookies and I am aware that it is one way to store form selections, but what happens when someoone has disables cookies. I guess at this point I am just trying to get it to work and understand what I am doing wrong. I do thank you for your help Dasher.
Copy linkTweet thisAlerts:
@DasherNov 18.2010 — The other option is to use sessions. Session variables are available to the script, and can be user specific. The variables die when the browser is closed.

Here is a quick intro to sessions; http://php.about.com/od/advancedphp/ss/php_sessions.htm

Also see http://php.net/manual/en/intro.session.php

Sessions are alot like cookies in that they must be loaded before headers are sent. So it has to appear above the <!DOCTYPE statement. Make sure you have no white space before <?php

Also you likely need to buffer the data with ob_start() something like...

<i>
</i>&lt;?php
ob_start();
if (isset($_POST[submit])){

$_SESSION[accomdationtype] = $_POST[accomdationtype];
// etc.
}
ob_end_flush();
?&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Page title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
$accomdationtype = $_SESSION[accomdationtype];
//etc
?&gt;
&lt;/body&gt;
&lt;/html&gt;


If you haven't done so already the php manual in .chm form is very handy to have http://us3.php.net/get/php_manual_es.chm/from/a/mirror
×

Success!

Help @jej704 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...