Jump to content

mcurtis

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mcurtis's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your answer btherl - but do I not already use $offset, $rowsperpage and $i in: // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) {
  2. Hi phpfreaks, I'm trying to get a '10 result per page' pagination but it just doesn't seem to want to work properly... It does actually put the [page number] at the bottom of the page, but displays ALL the results on 1 long page instead of splitting them up in to different pages of 10. If anyone could help, I would seriously appreciate it!!! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" > <head> <title>Renewal Dates</title> <meta name="robots" content="index,no_follow"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <? // Connects to your Database include("db_connect.php"); // Connect to server and select database. $conn=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db($db_name,$conn) or die ("cannot select DB"); $query="SELECT * FROM users"; $result=mysql_query($query); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $field_1=mysql_result($result,$i,"field_1"); $field_2=mysql_result($result,$i,"field_2"); $field_3=mysql_result($result,$i,"field_3"); $field_4=mysql_result($result,$i,"field_4"); $field_5=mysql_result($result,$i,"field_5"); $field_6=mysql_result($result,$i,"field_6"); $field_7=mysql_result($result,$i,"field_7"); $field_8=mysql_result($result,$i,"field_8"); // while there are rows to be fetched... // echo data echo "<table width=100% align=center>"; echo "<tbody>"; echo "<tr>"; echo "<td colspan=4><hr width=100% size=2 /></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left><b>ID: $field_1</b></td>"; echo "<td align=left><b>$field_2</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left colspan=2>field 3: <b>$field_3</b></td>"; echo "<td align=right colspan=2>field 4: <b>€$field_4</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left>field 5: <b>$field_5</b></td>"; echo "<td align=left>field 6: <b>$field_6</b></td>"; echo "<td align=left colspan=2>field 7: <b>$field_7</b></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=left colspan=4>field 8: $field_8</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; $i++; } ?></td> <? /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>start</a> | "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>prev</a> | "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " | <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>next</a> "; // echo forward link for lastpage echo " | <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>end</a> "; } // end if /****** end build pagination links ******/ ?> </body>
  3. Thanks again Doddsey!!! Your assistance was VERY much appreciated and got me looking in the right place! I took out the ."" from the end of the header line and whilst there noticed: $_SESSION['SESS_MAIN_ID'] = $member['main_id']; session_write_close(); header("Location: test_admin_panel.php?user_id=".$main_id.""); and changed it to $_SESSION['SESS_MAIN_ID'] = $member['main_id']; session_write_close(); header("Location: test_admin_panel.php?user_id=".$member['main_id']); It was part after the ?user_id= which needed to reflect the $_SESS_MAIN_ID Thanks again - Now I can sleep!
  4. Thanks Doddsey for your reply! This is exactly what I would like it to do but it just doesn't seem to want to carry over.. The bottom of my login_exec.php has what I thought would carry it in the header, but to no avail: //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_CLIENT_EMAIL'] = $member['client_email']; $_SESSION['SESS_MAIN_ID'] = $member['main_id']; session_write_close(); header("Location: test_admin_panel.php?user_id=".$main_id.""); exit(); }else { The reason why there are "user_id" & "main_id" is that the user db uses "user" and their information is held in a separate db using "main_id" (I know, I should have made them the same )
  5. Hello, I've been racking my brains (and spending sleepless nights) trying to get a login system to work by where the member will insert their email address as [username] and password (already stored in the DB) - then the page to divert to an administration panel with their User_id for them to only edit their information. The Code I have so far..... The login_form.php <?php //Start session session_start(); //Unset the variables stored in session unset($_SESSION['SESS_CLIENT_EMAIL']); unset($_SESSION['SESS_MAIN_ID']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Client Admin Panel</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"> <h1>CLIENT LOGIN</h1> <h2>CLIENT ADMINISTRATION PANEL</h2> version 2.10 </div> <div id="menu"> </div> <div id="content"> <div id="right"> <div class="post"> <h2>CLIENT ADMINISTRATION PANEL - CLIENT LOGIN</h2><br /> <h3><span class="err"><strong><font color="#800000">PLEASE LOGIN</font></strong></span></h3><form id="loginForm" name="loginForm" method="post" action="login-exec.php"> <table width="315" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="150"><b>Email Address:</b></td> <td width="157"><input name="login" type="text" class="textfield" id="client_email" /></td> </tr> <tr> <td><b>Secret Word:</b></td> <td><input name="password" type="password" class="textfield" id="client_password" /></td> </tr> <tr bgcolor='#f1f1f1'> <td> </td> <td><input type="submit" name="Submit" value="Login" /></td> </tr> <tr> <td colspan="2"><hr /></td> </tr> <tr> <td><b>Forgot SecretWord?:</b></td> <td><font face='tahoma, arial, helvetica' size='2' ><a href='forgot-password.php'>Click Here</a></font></td> </tr> <tr> <td colspan="2"><hr /></td> </tr> <tr> <td><b>New Client?:</b></td> <td><font face='tahoma, arial, helvetica' size='2' ><a href='../dhsite/webpages/reg_1.php'> Register Here</a></font></td> </tr> </table> <br /> </form></p> </div> </div> </div> <div id="footer"> <p class="copyright">Copyright © *****************</p> </div> </div> </body> </html> And the handler: login_exec.php <?php //Start session session_start(); $_SESSION['var'] = $val; //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $client_email = clean($_POST['login']); $client_password = clean($_POST['password']); //Input Validations if($client_email == '') { $errmsg_arr[] = 'Email Address missing'; $errflag = true; } if($client_password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT client_email, client_password, main_id FROM users WHERE client_email='$client_email' AND client_password='$client_password'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_CLIENT_EMAIL'] = $member['client_email']; $_SESSION['SESS_MAIN_ID'] = $member['main_id']; session_write_close(); header("Location: test_admin_panel.php?user_id=".$main_id.""); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> Any help would be VERY much appreciated!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.