PHP - Exit Function Early
There is a function (that cannot be changed) which has an include:
<?php function a() { include 'file.php'; echo 'work'; } ?> ==file.php== <?php echo 'play'; ## Need to leave a() now! ?>The included file can be changed. I would like a way for file.php to cause PHP to return out of the function a(). A return; statement in file.php has PHP pick up execution with the statement following include. What is there in PHP that will allow returning out of a() at some point in file.php? Similar TutorialsI really hit a wall while trying to figure out how to stop my script from terminating early. First, my website is located on an IIS server. Second, the script I'm referring to is supposed to be some kind of a 'thread' (and I know this is not the place to use PHP but it's not my website and it's not my script - I only need to get it to work). So it basically opens in the background and stays alive by using the Sleep function inside a For loop (until some term has been met). My problem is that the script is being terminated after about 3-5 minutes (not sure exactly after how long). I already tried adding the set_time_limit(0) and it had no effect. Does anyone have an idea how can I solve this problem and why the set_time_limit(0) is not working? P.S. The server is not in Safe Mode. hi guys.. im not sure if im in the right section but. i have this script below and it exits BUT i would like it to exit After it applies the CSS to my Error. i want it to display nothing except the error if there is an error.. the php is being included on the index.php page which links to the css. this works IF i put the include after the CSS link but wondering if theres a better way. PHP <?php $host = 'localhost'; $user = 'user'; $pass = 'password'; $db = 'upload'; $link = @mysqli_connect( $host, $user, $pass, $db); if(!$link){?> <div id='conn_error'> <?php echo 'There was an Error Connecting to the Server'; ?> </div><?php } ?> Css Code: [Select] #conn_error{ background: red; font-size: 24px; font-family: arial; color: white; width: 500px; text-align: center; border: solid 2px black; position: absolute; top: 150px; left: 30%; padding: 2px; } I'm new to php and I created a user registration form. But whenever I submit the form, part of my page doesn't load. I see the "successful registration" message, but I don't see my right sidebar, footer, or my wrapper div. After searching the internet all day, I concluded it was the exit() function. But if I leave in the exit function and submit the form, all of my page loads, but the original registration form is still shown below my "successful registration" message. Can someone please help? Code: [Select] <?php require_once('_includes/connectvars.php'); if (isset($_POST['submitted'])) { $firstname = mysql_real_escape_string(trim($_POST['firstname'])); $lastname = mysql_real_escape_string(trim($_POST['lastname'])); $email = mysql_real_escape_string(trim($_POST['email'])); $birthdate = mysql_real_escape_string(trim($_POST['birthdate'])); $zipcode = mysql_real_escape_string(trim($_POST['zipcode'])); $gender = $_POST['gender']; $username = mysql_real_escape_string(trim($_POST['username'])); $password1 = mysql_real_escape_string(trim($_POST['password1'])); $password2 = mysql_real_escape_string(trim($_POST['password2'])); $terms = $_POST['terms']; $newsletter = $_POST['newsletter']; $activationkey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $captchchk = 1; require_once('_includes/recaptchalib.php'); $privatekey = "some#"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (preg_match ('%^[A-Za-z\.\' \-]{2,15}$%', stripslashes(trim($_POST['firstname'])))) { $firstname = escape_data($_POST['firstname']); } else { $firstname = FALSE; echo '<p class="error">Please enter a valid first name!</p>'; } if (preg_match ('%^[A-Za-z\.\' \-]{2,30}$%', stripslashes(trim($_POST['lastname'])))) { $lastname = escape_data($_POST['lastname']); } else { $lastname = FALSE; echo '<p class="error">Please enter a valid last name!</p>'; } if (preg_match('%^(0?[1-9]|1[012])[/](0?[1-9]|[12][0-9]|3[01])[/](19|20)?[0-9]{2}$%', stripslashes(trim($_POST['birthdate'])))) { $birthdate = escape_data($_POST['birthdate']); } else { $birthdate = FALSE; echo '<p class="error">Please enter a valid date of birth in the format of MM/DD/YYYY</p>'; } if (preg_match ('%^[0-9]{5}$%', stripslashes(trim($_POST['zipcode'])))) { $zipcode = escape_data($_POST['zipcode']); } else { $zipcode = FALSE; echo '<p class="error">Please enter a valid 5 digit zip code!</p>'; } if ($gender !== 'M') { if ($gender !== 'F') { echo '<p class="error">Please select your gender!</p>'; } } if (preg_match ('%^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*(\S{4,75})$%', stripslashes(trim($_POST['username'])))) { $username = escape_data($_POST['username']); } else { $username = FALSE; echo '<p class="error">Please enter a valid username!</p>'; } if (preg_match ('%^[A-Za-z0-9]{6,15}$%', stripslashes(trim($_POST['password1'])))) { $password1 = escape_data($_POST['password1']); if (($_POST['password1'] == $_POST['password2']) && ($_POST['password1'] != $_POST['username'])) { $password1 = escape_data($_POST['password1']); } elseif ($_POST['password1'] == $_POST['username']) { $password1 = FALSE; echo '<p class="error">Your password cannot be the same as the username!</p>'; } else { $password1 = FALSE; echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { $password1 = FALSE; echo '<p class="error">Please enter a valid password!</p>'; } if ($terms !== 'Y') { echo '<p class="error">You must agree to the terms of use!</p>'; } if (!$resp->is_valid) { echo '<p class="error">The CAPTCHA Code wasn\'t entered correctly!</p>'; $captchchk = 0; } if ($firstname && $lastname && $email && $birthdate && $zipcode && $gender && $username && $password1 && $terms && $captchchk) { $query = "SELECT * FROM members WHERE username = '$username'"; $result = mysql_query($query) or trigger_error(mysql_error().$query); if(mysql_num_rows($result) == 1) { echo '<br><br><p class="error">An account already exists for this username. Please select a different username.</p>'; $username = ""; } else { if(mysql_num_rows($result) == 0) { $query = "INSERT INTO members (first_name, last_name, email, dob, zip_code, gender, username, password, join_date, newsletter, active, terms, status) VALUES ('$firstname', '$lastname', '$email', STR_TO_DATE('$birthdate', '%m/%d/%Y'), '$zipcode', '$gender', '$username', SHA('$password1'), NOW(), '$newsletter', '$activationkey', '$terms', 'verify')"; $result = mysql_query($query) or trigger_error(mysql_error().$query); if (mysql_affected_rows() == 1) { $to = $_POST['email']; $subject = "Registration"; $message = "Welcome to Mysite.com!\n\nYou, or someone using your email address, has completed registration at Mysite.com. You can complete registration by clicking the following link:\n\nhttp://www.mysite.com/verify.php?$activationkey\n\nIf this is an error, ignore this email and you will be removed from our mailing list.\n\nRegards,\n\nThe Mysite.com Team"; $headers = 'From: noreply@ Mysite.com' . "\r\n" . 'Reply-To: noreply@ Mysite.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); echo '<br /><br /><p>Thank you for registering! A confirmation email has been sent to your email. Please click on the link in that email in order to activate your account.</p>'; } else { $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM members"; $result = mysql_query($query) or trigger_error(mysql_error().$query); while($row = mysql_fetch_array($result)){ if ($queryString == $row["active"]){ echo "Congratulations!" . $row["username"] . " is now a member of Mysite.com!"; $query="UPDATE members SET active = '', status='activated' WHERE (user_id = $row[user_id])"; if (!mysql_query($query)) { die('Error: ' . mysql_error()); } } } } } } } exit(); mysql_close(); } The code seems to cear debug until I attempt to exit after doing a while loop. PHP Parse error: syntax error, unexpected T_ELSE in C:\Users\Bob\Desktop\TAFT WEB\test\login.php on line 46 Here's the code: <?php /* -----------------------NOVEMBER 2010-------------------- */ // User has 3 trys to enter correct username and password // increment by one $num_log = ($num_logs + 1); if ($_POST['username']) { //Connect to the database through our include include_once "connect_to_mysql.php"; $username = stripslashes($_POST['username']); $username = strip_tags($username); $username = mysql_real_escape_string($username); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password = md5($password); } // Make query and then register all database data that - // cannot be changed by member into SESSION variables. // Data that you want member to be able to change - // should never be set into a SESSION variable. $sql = mysql_query("SELECT * FROM register WHERE username='$username' AND password='$password'"); $login_check = mysql_num_rows($sql); if($login_check > 0); { while($row = mysql_fetch_array($sql)){ // Get member ID into a session variable $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; // Get member username into a session variable $username = $row["username"]; session_register('username'); $_SESSION['username'] = $username; // Update last_log_date field for this member now mysql_query("UPDATE user_log SET log_on=now() WHERE id='$id'"); // Print success message here if all went well then exit the script header("location: memPage.shtml php?id=$id"); exit(); } // close while ERROR ---> else { exit() } // Print login failure message to the user and link them back to your login page print '<br><br> <font color="#FF0000"> No match was found in our member records, try again. </font> <br><br> <a href="login.php">Click here</a> to go back to the login page.'; exit(); // close if post ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login to your profile</title> <script type="text/javascript"> <!-- Form Validation --> function validate_form ( ) { valid = true; if ( document.logform.email.value == "" ) { alert ( "Please enter your User Name" ); valid = false; } if ( document.logform.pass.value == "" ) { alert ( "Please enter your password" ); valid = false; } return valid; } <!-- Form Validation --> </script> </head> <body> <div align="center"> <h3 style="test-align:center;font-weight:bold; color:blue;padding-top:25px;padding-bottom;15px;"> Log in to your account here </h3> </div> <table align="center" cellpadding="5"> <form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );"> <tr> <td class="style7"><div align="right">Username:</div></td> <td><input name="username" type="varchar" id="username" size="30" maxlength="50" /></td> </tr> <tr> <td class="style7"><div align="right">Password:</div></td> <td><input name="password" type="password" id="password" size="50" maxlength="24" /></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" value="Login" /></td> </tr> </form> </table> </body> </html> I have a script that allows a User to create a new password as part of a password re-set flow. In my script, I store the $memberID in the Session so that when I redirect from "create_password.php" to "results.php" I still have the $memberID and can store it in the transaction log in my database. The problem is that even though I have unset() after the redirect, it is somehow erasing the value in $_SESSION['memberID'] before the redirect, and thus I get "0" in the database when "results.php" runs?! // Temp Password expires in 1 hour (3600 seconds). if ((time() - $tempResetOn)>10){ // Temp Password Expired. $_SESSION['resultsCode'] = 'PASSWORD_TEMP_PASSWORD_EXPIRED_2112'; // Set Error Source. $_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME']; // Redirect to Outcome Page. header("Location: " . BASE_URL . "/members/results.php"); unset($_SESSION['memberID']); // End script. exit(); }//End of CHECK FOR EXPIRED TEMP PASSWORD How do I unset the Session variable - in the "create_password.php" script above - AFTER I successfully redirect and store the $memberID in the database? Thanks, Debbie HI, I have a foreach loop but after some execution it begins to show me this:Invalid argument supplied for foreach() ... so I want to exit from it.how can I do that? Thanks hey all; I have a member.php page filled with html and some php, at the top the first thing it does is check for a session if it's not present it displays Sorry you must be logged in to view this page if it's there is says welcome blah blah blah problem is even if it's not present it's showing all the rest the content under the sorry you must be logged in to view this page.. tried adding an exit; did the same thing showed content and tried die; did the same thing showed content? Hi, I have been working on an application where when the user logs in, the status field in the database isset to 1 (online), and when logging off set to 0 (offline). I was wondering if there is a way, using PHP or otherwise, of accomodating for when the user closes the browser manually? I have been looking at other forums who say that it is possible to set a timer which automatically logs the user off after a set amount of time but I dont know how to actually do this or where to start; will the code go on every page of the site? Thanks in advance for any replies I am trying to protect my queries to check the user's ip address to make sure they are not banned... When I comment out the if statement in $db->query the error goes away... The checkIp function works in other instances, I am just trying to call it so nobody can inject things by trying to go around the actual pages... my db function class looks like this: Code: [Select] class dblib { function query($sql) { if ($this->checkIp($_SERVER['REMOTE_ADDR']) == true) { die("GH".$ip); // Used to see if I can get that far... $result = mysql_query($sql) or die("Database error: " . mysql_error() . "<br /><br /><h2>SQL</h2><p>$sql</p>"); return $result; } else { die("<h1>Banned</h1>"); } } /// .......some other functions function checkIp($ip) { $sql = "SELECT * FROM block WHERE ip='$ip' LIMIT 1 "; $result = $this->query($sql); if (mysql_num_rows($result) == 0) return true; else return false; } I have a db class that contains several db functions. The biggie is $db->query($sql) function. EVERYTHING that goes to the database goes through this function, and I want to add some security... I have a another function in the db class, checkIp($ip) that checks to see if the ip is in the block list or not. Whenever I update the code (from the simple $result = mysql_query()... and return $result to have the if..else statement, I get a signal Segmentation fault... Any ideas? Code: [Select] class dblib { function query($sql) { if ($this->checkIp($_SERVER['REMOTE_ADDR'])) { //die("GH"); // For testing... $result = mysql_query($sql) or die("Database error: " . mysql_error() . "<br /><br /><h2>SQL</h2><p>$sql</p>"); return $result; } else { die("<h1>Banned</h1>"); } } function checkIp($ip) { $sql = "SELECT * FROM block WHERE ip='$ip' LIMIT 1 "; $result = $this->query($sql); if (mysql_num_rows($result) == 0) return true; else return false; } }
Is there a shorthand for:
This obviously doesn't work (but I tried it anyway 😃 )
.... I also tried every permutation of: Maybe a stupid question... after typing it out, if($dog!='bark') exit('go away'); looks pretty short already. Hello all, I have some piece of code that is nested like this $variable = 'This is a global argument'; function parentFunction($variable) { function childFunction() { echo 'Argument of the parent function is '.$GLOBALS['variable']; } childFunction(); } parentFunction(5); What I want to know is - Is there a way to access a variable from the parent function without passing arguments to the child function? (Something like how classes have parent::?). I don't want to use $GLOBALS because it might cause some variable collision, and I didn't want to pass arguments because incase I decide to change the arguments in the parent function I'd have to do it in the child function aswell. From my searching around in the Internet it seems like this is not possible, but if theres a slight chance that there might be something out there, i'm willing to give it a shot . Thanks in advance Question 1) Is the only and proper way to call a parent function "parent::function()"? Are there other/better ways from within a child function? Question 2) What are the deciding factors for when to make a function or attribute static? How do you make that decision? Assuming 5.3... Thanks. I need to call usort from a class function, and I'm puzzled about how to define the comparison function. I've tried to define the comparison function in the same class, but I can't get usort to call it. I found one hint that it will work if I make the comparison function static, but I tried that, and it didn't work for me. If I define the comparison function outside the class, it won't have access to object properties that it needs to operate. The only solution I can think of is to define the comparison function outside the class and put the object properties it needs in globals. Is there a cleaner way to do this? I have this function completely written in my class file that I am working on. The point to this function is to be able to check the login of a user or administrator for either of the control panels associated with my site. It will check the session intime as well as the page / module referenced. Once it passes all those checks, it will check and ensure the emailaddress/password stored in the current session still holds true and the account is still active... if the account is still active it will update the lastActivity as well as update all of the session variables with what is currently in the database. What I am looking for is basically a look at the function, see if it looks good.. If there is any part to it that could create security holes for the site just off the login function itself... Usage: $q->validUser($_SESSION['user'], $_mod); <?php function validUser($sess, $p) { if ($sess['inTime'] == '' && $p != 'login' && $p != 'logout') { session_destroy(); $login = '0'; $_int = ''; return $login; } else if ($sess['inTime'] < time()-3600 && $p != 'login') { $sess['inTime'] = ''; session_destroy(); $this->check_login($sess, $p); } else { $this->user = $sess['emailAddress']; $this->pass = $sess['password']; $login = $this->sql_query("SELECT * FROM users WHERE emailAddress = '".$this->user."' AND password = '".$this->pass."' AND status = '1' LIMIT '1'"); if ($login = $this->sql_numrows($login) < 1) { $sess['inTime'] == ''; session_destroy(); $login = '0'; } else { // logged in, lets update the database for last_activity AND the session. $this->sql_query("UDATE users SET lastActivity = '".now()."' WHERE emailAddress = '".$this->user."'"); $login = $this->sql_query("SELECT * FROM users WHERE emailAddress = '".$this->user."' AND password = '".$this->pass."' AND status = '1' LIMIT '1'"); $login = mysql_fetch_assoc($login); foreach ($login as $key => $value) { $sess[$key] = $value; } $sess['inTime'] = time(); $login = '1'; } return $login; } } ?> That is the main function, sql_query and sql_numrows is: <?php function sql_query($query = "", $transaction = FALSE) { unset($this->query_result); if ($query != "") { $this->num_queries++; if ($transation == BEGIN_TRANSACTION && !$this->in_transation) { $result = mysql_query("BEGIN", $this->db_connect_id); if (!$result) { return false; } $this->in_transaction = TRUE; } $this->query_result = mysql_query($query, $this->db_connect_id); } else { if ($transaction == END_TRANSACTION && $this->in_transaction ) { $result = mysql_query("COMMIT", $this->db_connect_id); } } if ($this->query_result) { unset($this->row[$this->query_result]); unset($this->rowset[$this->query_result]); if ($transaction == END_TRANSACTION && $this->in_transaction ) { $this->in_transaction = FALSE; if (!mysql_query("COMMIT", $this->db_connect_id)) { mysql_query("ROLLBACK", $this->db_connect_id); return false; } } return $this->query_result; } else { if ($this->in_transaction ) { mysql_query("ROLLBACK", $this->db_connect_id); $this->in_transaction = FALSE; } return false; } } function sql_numrows($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } return ($query_id) ? mysql_num_rows($query_id) : false; } ?> Any insight that can help to benefit these functions would be appreciated. I want to define a function instead of repeating query in all my php pages. I call a function by passing an $id value and from that function i have to get all the info related to that id, like name, description and uom.
I am trying to do this, but i dont know how to get these values seperately.
here is my function
function items($item_id) { $details = array(); $result = mysql_query("select item_id, name, uom, description from items where item_id=".$item_id."") or die (mysql_error()); while($row = mysql_fetch_array($result)) { $details[] = array((stripslashes($row['name'])), (stripslashes($row['uom'])), (stripslashes($row['description']))); } return $details; }and i call my function like this $info = items($id);Can somebody guide me in this When I put this chunk of code into it's own function: function fetch_all ($dbc, $query) { include ('knuffix_list_func.php'); pagination_start ($dbc, $query); $offset = $pag_array[0]; $rows_per_page = $pag_array[1]; $query = $query . " LIMIT $offset, $rows_per_page"; echo "test query: " . $query; knuffix_list ($query, $dbc); pagination_end ($pag_array); } And when I echo out the query as you can see in the example, then I notice that the variables $offset and $rows_per_page never get appended. I set the variable $pag_array to a global inside the function pagination_start(). It usually works when I DON'T wrap a function around this chunk of code, but if I do wrap a function around everything then the global suddenly won't work anymore. Btw, this also won't work if I wrap a function around the function DECLARATIONS. Any ideas, how I could make it work? I've followed the PHP Freaks pagination tutorial which you can find here. And I also got it to work, the only problem is that the script won't work when I use the query outside of the function. Here's the function: <?php function knuffix_list ($query, $dbc) { // find out how many rows are in the table: $query_row = "SELECT COUNT(*) FROM con"; $query_run = mysqli_query ($dbc, $query_row); $row = mysqli_fetch_row($query_run); $num_rows = $row[0]; // number of rows to show per page $rows_per_page = 5; // find total pages -> ceil for rounding up $total_pages = ceil($num_rows / $rows_per_page); // get the current page or set a default if (isset($_GET['current_page']) && is_numeric($_GET['current_page'])) { // make it an INT if it isn't $current_page = (int) $_GET['current_page']; } else { // default page number $current_page = 1; } // if current page is greater than total pages then set current page to last page if ($current_page > $total_pages) { $current_page = $total_pages; } // if current page is less than first page then set current page to first page if ($current_page < 1) { $current_page = 1; } // the offset of the list, based on current page $offset = (($current_page - 1) * $rows_per_page); echo "test " . $query; // SCRIPT ONLY WORKS IF I INSERT QUERY HERE $query = "SELECT * FROM con, user WHERE con.user_id = user.user_id ORDER BY contributed_date DESC LIMIT $offset, $rows_per_page"; $data = mysqli_query ($dbc, $query) or die (mysqli_error ($dbc)); // Loop through the array of data while ($row = mysqli_fetch_array ($data)) { global $array; // Variables for the table $con_id = $row['con_id']; $likes_count = $row['likes']; $dislikes_count = $row['dislikes']; $dbuser_name = $row['nickname']; $dbuser_avatar = $row['avatar']; $user_id = $row['user_id']; // The TABLE echo "<table padding='0' margin='0' class='knuffixTable'>"; echo "<tr><td width='65px' height='64px' class='avatar_bg' rowspan='2' colpan='2'><img src='avatar/$dbuser_avatar' alt='avatar' /></td>"; echo "<td class='knuffix_username'><strong><a href='profile.php?user=$dbuser_name' title='Profile of $dbuser_name'>" . $dbuser_name . "</a> ___ " . $user_id . "____ <form action='' method='POST'><button type='submit' name='favorite' value='fav'>Favorite</button></form>"; echo "</strong><br />" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . "</td></tr><tr><td>"; echo "<form action='' method='post'> <button class='LikeButton' type='submit' name='likes' value='+1'>Likes</button> <button class='DislikeButton' type='submit' name='dislikes' value='-1'>Dislikes</button> <input type='hidden' name='hidden_con_id' value='" . $con_id . "' /> </form></td><td class='votes'>Y[" . $likes_count . "] | N[" . $dislikes_count . "]</td></tr>"; echo "<tr><td class='knuffix_name' colspan='3'><strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td colspan='2' class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "</table>"; // POST BUTTONS inside the table $likes = $_POST['likes']; $dislikes = $_POST['dislikes']; $con_id = $_POST['hidden_con_id']; $favorite = $_POST['favorite']; $array = array ($likes, $dislikes, $con_id, $user_id, $favorite); } /********* build the pagination links *********/ // BACKWARD // if not on page 1, show back links and show << link to go back to the very first page if ($current_page > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?current_page=1'><<</a> "; // get previous page number and show < link to go to previous $prev_page = $current_page - 1; echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$prev_page'><</a> "; } // CURRENT // range of number of links to show $range = 3; // loop to show links in the range of pages around current page for ($x = ($current_page - $range); $x < (($current_page + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $total_pages)) { // if we're on current page if ($x == $current_page) { // highlight it but don't make a link out of it echo "[<b>$x</b>]"; // if it's not the current page then make it a link } else { echo "<a href='{$_SERVER['PHP_SELF']}?current_page=$x'>$x</a>"; } } } // FORWARD // if not on the last page, show forward and last page links if ($current_page != $total_pages) { // get next page $next_page = $current_page + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$next_page'>></a> "; // echo forward link for last page echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$total_pages'>>></a> "; } /***** end building pagination links ****/ mysqli_close($dbc); } ?> As you can see above, the script will only work if I put the query right below the $offset variable and above the $data variable. I put the test echo above the query to see how the query looks like when I induce the query from the outside through the function parenthesis into the function, and this is what I get printed out: test SELECT * FROM con, user WHERE con.user_id = user.user_id ORDER BY contributed_date DESC LIMIT , Obviously the $offset and the $rows_per_page variables are not set, when I induce the query from the outside into the function. So in that sense my question is: How can I induce the query from the outside into the function SO THAT the $offset and the $rows_per_page variables are set as well and NOT empty? p.s. I need the query outside of the function because I'm using a sort by category functionality. Hi I have a table class and functions I want to call in another function but can't get it working. Some help will be very welcome. It seesm that the new table class is not working in this function if I pass the values to it, I have tested the class, it does get the post values I post to it so $_POST['id'] are being received as well as all the other $_POST's but the table class and find function is not working, it works fine if I don't put it in a function.. function edit() { if (isset($error)){ $error.="Please fix the error(s) above";} else { if ($_POST['id'] <> "") { $update =& new table($db, 'publisher'); $update->find($_POST['id']); $update->name = $_POST['name']; $update->url = $_POST['url']; $update->contact = $_POST['contact']; $update->address = $_POST['address']; $update->phone = $_POST['phone']; $update->email = $_POST['email']; $update->save(); $error = "The Publisher has been edited"; } } } im using a function which connects to a db called 'comments' and then inside that function i again called another function that will connect to the db 'main' to get avatars.... but as i put Code: [Select] mysql_select_db("main") or die(mysql_error()); on the new function, the original function stops to fetch rows. i tried to remove "mysql_select_db("main") or die(mysql_error());" and used the new function to return some text only and it worked, so i guess the connection to the db was the problem... i tried doing Code: [Select] mysql_query("SELECT * FROM main.avatar INNER JOIN main.list ON main.avatar.title=main.list.id WHERE main.avatar.page_id='$id'"); but it also didnt work |