m118 Posted December 22, 2010 Share Posted December 22, 2010 I try to use session to keep post data. It is not working. The program likes this . html <select name="type"> <option >for</option> <option value="PC">Photo copier</option> <option value="Fax">Fax</option> <option value="Copier">Copier</option> <option value="Cheque">Cheque</option> <option value="Print">Printer</option> <option value="Copier/Fax">Copier/Fax</option> </select> <br /> PHP CODE $session_start(); $_SESSION[brand]=$_POST[brand]; $_SESSION[sort]=$_POST[sort]; $_SESSION[type]=$_POST[type]; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 18; $select="select * from $chun where brand = '$_SESSION[brand]' or sort ='$_SESSION[sort]' or type='$_SESSION[type]' LIMIT $start_from, 18"; $result2=mysql_query($select, $connection) or die (mysql_error()); $sql = "select count(*) from $chun where brand = '$_SESSION[brand]' or sort ='$_SESSION[sort]' or type='$_SESSION[type]' "; <div class="trunpage"><a href='table2.php?page=<?php echo "$i" ; ?>&id=<?php echo "$_POST[brand]";?>&cd=<?php echo "$_POST[kind]";?>&td=<?php echo "$_POST[type]";?>' ><?php echo "$i" ; ?></a> I get error message. Notice: Undefined variable: session_start in C:\wamp\www\php1000\table2.php on line 174 Fatal error: Function name must be a string in C:\wamp\www\php1000\table2.php on line 174 Please tell me how to solve this problem . Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/ Share on other sites More sharing options...
MMDE Posted December 22, 2010 Share Posted December 22, 2010 your: $_SESSION[brand]=$_POST[brand]; $_SESSION[sort]=$_POST[sort]; $_SESSION[type]=$_POST[type]; remember to use single or double quotes around the key strings $_SESSION['brand']=$_POST['brand']; $_SESSION['sort']=$_POST['sort']; $_SESSION['type']=$_POST['type']; you've done it far more than just what I've corrected here... js so you will have to do that yourself (sorry lol) session start is a function not a variable... $session_start(); correct: session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150368 Share on other sites More sharing options...
m118 Posted December 22, 2010 Author Share Posted December 22, 2010 I am just a beginner, but I do whole project. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150371 Share on other sites More sharing options...
m118 Posted December 22, 2010 Author Share Posted December 22, 2010 I change the program. It is not working . <select name="type"> <option >for</option> <option value="PC">Photo copier</option> <option value="Fax">Fax</option> <option value="Copier">Copier</option> <option value="Cheque">Cheque</option> <option value="Print">Printer</option> <option value="Copier/Fax">Copier/Fax</option> </select> session_start(); $_SESSION['brand']=$_POST['brand']; $_SESSION['sort']=$_POST['sort']; $_SESSION['type']=$_POST['type']; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 18; $select="select * from $chun where brand = "$_SESSION['brand']" or sort ="$_SESSION['sort']" or type="$_SESSION['type']" LIMIT $start_from, 18"; $result2=mysql_query($select, $connection) or die (mysql_error()); $sql = "select count(*) from $chun where brand = "$_SESSION['brand']" or sort ="$_SESSION['sort']" or type="$_SESSION['type']" "; $rs_result = mysql_query($sql,$connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 18); for ($i=1; $i<=$total_pages; $i++) { <div class="trunpage"><a href='table2.php?page=<?php echo "$i" ; ?>&id=<?php echo "$_SESSION['brand']";?>&cd=<?php echo "$_SESSION['sort']";?>&td=<?php echo "$_SESSION['type']";?>' ><?php echo "$i" ; ?></a> Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150377 Share on other sites More sharing options...
MMDE Posted December 22, 2010 Share Posted December 22, 2010 I don't see the start and end of the php... is what you showed the entire page? <?php ?> also, where is the end of this for loop? for ($i=1; $i<=$total_pages; $i++) { <div class="trunpage"><a href='table2.php?page=<?php echo "$i" ; ?>&id=<?php echo "$_SESSION['brand']";?>&cd=<?php echo "$_SESSION['sort']";?>&td=<?php echo "$_SESSION['type']";?>' ><?php echo "$i" ; ?></a> You know you can just write: for ($i=1; $i<=$total_pages; $i++) { echo '<div class="trunpage"><a href="table2.php?page='.$i.'&id='.$_SESSION['brand'].'&cd='.$_SESSION['sort'].'&td='.$_SESSION['type'].'">'.$i.'></a>'; } you might want to end those divs too o.o if you are not sure if the queries actually work or give you what you expect, try this: $query='SELECT ....'; echo $query; $result=mysql_query($query) or die(mysql_error()); $rows=mysql_num_rows($result); echo 'number of rows:'.$rows; while($row=mysql_fetch_array($result)){ $array[]=$row; } print_r($array); Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150383 Share on other sites More sharing options...
m118 Posted December 22, 2010 Author Share Posted December 22, 2010 hello I have fix program now. I got a new problem . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Toner or type=Copier LIMIT 0, 18' at line 1 The whole program is it. <select name="type"> <option >for</option> <option value="PC">Photo copier</option> <option value="Fax">Fax</option> <option value="Copier">Copier</option> <option value="Cheque">Cheque</option> <option value="Print">Printer</option> <option value="Copier/Fax">Copier/Fax</option> </select> include("connection.php"); session_start(); $c=$_SESSION['brand']=$_POST['brand']; $xi=$_SESSION['sort']=$_POST['sort']; $zhang=$_SESSION['type']=$_POST['type']; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 18; $select="select * from $chun where brand = $c or sort =$xi or type=$zhang LIMIT $start_from, 18"; $result2=mysql_query($select, $connection) or die (mysql_error()); <tr> <td><?php echo $row['item'];?></td> <td><?php echo $row['oempart'];?></td> <td><?php echo $row['compatibility'];?></td> <td><?php echo $row['colorful'];?></td> <td><?php echo $row['comprice']; ?></td> <td><?php echo $row['oemprice']; ?></td> </tr> <?php }; ?> </table> <?php $sql = "select count(*) from $chun where brand = $c or sort =$xi or type=$zhang "; $rs_result = mysql_query($sql,$connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 18); for ($i=1; $i<=$total_pages; $i++) { ?> <div class="trunpage"><a href='table2.php?page=<?php echo "$i" ; ?>&id=<?php echo "$c";?>&cd=<?php echo "$xi";?>&td=<?php echo "$zhang";?>' ><?php echo "$i" ; ?></a> </div> Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150487 Share on other sites More sharing options...
m118 Posted December 22, 2010 Author Share Posted December 22, 2010 Thanks for your help . Quote Link to comment https://forums.phpfreaks.com/topic/222398-how-to-use-session-to-keep-post/#findComment-1150488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.