Jump to content

funbinod

Members
  • Posts

    501
  • Joined

  • Last visited

Posts posted by funbinod

  1. I tried to validate if a form input is within a php array or not using jquery.

     

    I tried the following

    <script>$('#date').blur(function(e) {	var dt = $('#date').val();	var dtarr = <?php echo json_encode($edate); ?>;	if(!($.inArray(dt, drarr))) {		alert('NOT in range');		$('#date').focus();	}});</script>

    is what I did is right or not? or I must use ajax? please suggest...

     

     

  2. I noticed you have defined the FROM and SUBJECT already. you are not choosing it from user input value.

     

    like ----

     

    $subject = "Message from my website";

    $from = "Message from my website";

     

    you should change it to ---

     

    $from = '$_POST['subject'];

    $subject = $_POST['email'];

     

    and of course you should process through validation as suggested by justsomeguy ...............

  3. i'm trying to get some result from a table with some conditions

    SELECT item FROM stock WHERE icode='$code' or bcode='$code' AND cid='$cid'

    I intended to get result if any of two fields (icode or bcode) matched the entered value($code) for cid='$cid'. I was trying $cid=2 but it is giving result from $cid=1. but if I removed second OR condition (bcode='$code') then it gives the correct result.

     

    its confusing. can u please guide if my code is good enough or not?????

  4. sorry guys if I posted it on wrong forum. because i'm confused which is the best forum to post this question, I posted this in general discussion forum....

     

    is there any possibility to keep a default setting in internet explorer for a default printer. the condition is that the specified default printer for ie should not change the default printer of windows....

     

    like if there are 2 printers, I wish one is default for all other applications and another is default for ie....

     

    is it possible....?????

     

    thanks in advance....

  5. I wish to load some external pages to the page with document load function. I mean when page loads I want them to be loaded to the page to respective ids without any click or anything. I tried the following--

    $(document).ready(function(e) {	$(document).load(function(e) {		$("#suncr").load("suncr.php?m=8");		$("#sundr").load("suncr.php?m=9");		$("#cnb").load("suncr.php?m=6");		$("#cstock").load("cstock.php?");    });});

    why this code is not working? can anyone guide....

  6. hi guys!

    I loaded data from another page using click function by d following code..

    <script>$(document).ready(function(e) {	$("#suncrlink").click(function(e) {		$("#suncr").load("ajax/suncr.php?m=8");	});</script>

    I worked. but I wish if I could unload (or hide) the loaded data when I click the same link again or not!

     

    can anyone guide...

  7. this is logout function

    	public function logout() {		$this->isLoggedIn = false;		if (session_id() == '') {			session_start();		}		$_SESSION['isLoggedIn'] = false;		foreach ($_SESSION as $key => $value) {			$_SESSION['$key'] = "";			unset($_SESSION[$key]);		}		$_SESSION = array();		if (ini_get("session.use_cookies")) {			$cookieParameters = session_get_cookie_params();			setcookie(session_name(), '', time() - 1200, $cookieParameters['path'],$cookieParameters['domain'],$cookieParameters['secure'],$cookieParameters['httponly']);		}		session_destroy();	}
  8. hi guys!

     

    this is somewhat related to my previous post about automatic session timeout.

     

    I calculated timeout time from sessions table and forced the user logout if (s)he exceeded the timeout limit. it did exactly what I expected from the following code

    $slaquery = mysqli_query($connect, "SELECT lastActive FROM session WHERE cid='$cid' AND uid='$uid'") or die ("Error: ".mysqli_error($connect));$slarow = mysqli_fetch_object($slaquery);$lastActive = $slarow->lastActive;$time = time();if ($time - $lastActive > 1200) {	echo"<script>alert('Timeout!');</script>";	mysqli_query($connect, "DELETE FROM session WHERE cid='$cid' AND uid='$uid'") or die("Error: ".mysqli_error($connect));	$user->logout();	die(header("location: login.php"));}

    but it did not alert (or echo) the Timeout! as written on line 25. if I changed the code to create error session like this --

    session_start();$_session['error'] = 'Timeout!';die(header('location: login.php');

    using this, it prints other error sessions at login.php but doesn't print the 'Timeout!'.

     

    what could be the mistake.....

  9. i'm trying to change the submit button's value and style on certain condition using the following code

    <script>$(document).ready(function() {	$("#conpass").keyup(function() {		if ($("#uok").val()=="ok" && $("#compok").val()=="ok" && $("#passok").val()=="ok" && $("#cpok").val()=="ok") {			$("#register").removeAttr('disabled');			$("#register").addClass('enabled');			$("#register").removeAttr('value');			$("#register").addAttr('value', 'Register');			$("#register").removeClass('disabled');		}	})});</script>

    everything is working fine but addAttr('value', 'Register') is not working. after removing the default value, it changes it to 'Submit'. but I wish to change it to 'Register'.

     

    please guide what I did wrong.........

  10. confused about what u expected exactly but I think mean the following.....

    <select name="ud_Borrwd_Rsn">    <option><?php echo $row['ud_Borrwd_Rsn']; ?></option>    <option>Borrowed</option>    <option>Repair</option>    <option>Replacement</option>    <option>Other</option></select>

    and yes u don't have value inside option tag. what u use inside opening and closing of option is itself a value..

  11. this means each time any user uses any page, the sessions are destroyed if the last active time is greater than d specified time? if so is it good to deal with other users' session?

     

    again,

    does using php sessions expire every time d browser closes and IF SYSTEM CRASHES also???

  12. I want to setup my session to expire automatically if any user is inactive for certain period.

    for that I've tried this---

    $laquery = mysqli_query($connect, "SELECT lastActive FROM user WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));$larow = mysqli_fetch_object($laquery);$lastActive = $larow->lastActive;$now = date('Y-m-d H:i:s');//echo strtotime($now) - strtotime($lastActive);if (strtotime($now) - strtotime($lastActive) > 1200) {	mysqli_query($connect, "UPDATE user SET isloggedin='N' WHERE cid=$cid AND uid=$uid") or die("Error: ".mysqli_error($connect));	$user->logout();	session_start();	$_SESSION['error'] = "Timeout!";	die(header("location: login.php"));} else if (strtotime($now) - strtotime($lastActive) < 1200) {	mysqli_query($connect, "UPDATE user SET lastActive = '$now' WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));}

    it worked fine until the browser is closed unexpectedly like system crash, direct close, etc..

    but if the browser is closed without logging out, then the user is remained logged in.

    is there any better way of setting automatic session expiry time??

  13. on my login page, if error happened, I'm trying to create error session on loginprocess file and I want it to display on login page. but after any error, it prevents logging in but doesn't display the error msg stored on session...

     

    here are the both files

    // login page<?phpdate_default_timezone_set("Asia/Kathmandu");require_once("mysql.php");echo '<p class="errordiv">';if (isset($_SESSION['error'])) {	unset($_SESSION['formAttempt']);	print "Errors:<br />n";	echo $_SESSION['error'];	unset($_SESSION['error']);} // end ifelse if (isset($_SESSION['timeout'])) {	echo $_SESSION['timeout'];	unset($_SESSION['timeout']);}if (isset($_SESSION['loggedin'])) {	echo $_SESSION['loggedin'];	unset($_SESSION['loggedin']);}echo '</p>';?><h2><u>Please LOGIN to continue</u></h2><br /><br /><form name="login" action="testloginprocess.php?" method="POST"><table style="width:700px; border:1;" align="center">	<tr>		<td style="width:180px;">Username:</td>        <td><input type="text" name="username" id="username" onkeypress="return tabE(this,event)" autocomplete="off" /></td>    </tr>    <tr>    	<td>Password:</td>        <td><input type="password" name="password" id="password" onkeypress="return tabE(this,event)" autocomplete="off" /></td>    </tr>    <tr>    	<td><input type="hidden" value="<?php echo $hash; ?>" name="hash"></td>        <td><input type="submit" name="login" value="LOGIN" id="login" /></td>    </tr></table></form>
    // login process file<?phpdate_default_timezone_set("Asia/Kathmandu");require_once("mysql.php");$now = date('Y-m-d H:i:s');//			$_SESSION['formAttempt'] = true;			// check required field			if (!isset($_POST['username']) || $_POST['username'] == "") {				session_start();				$_SESSION['error'] = "Please input <span style='color:#F00;'>username</span>";				die(header("location: testlogin.php?"));			} else if (!isset($_POST['password']) || $_POST['password'] == "") {				session_start();				$_SESSION['error'] = "Please input <span style='color:#F00;'>password</span>";				die(header("location: testlogin.php?"));			}			$username = mysqli_real_escape_string($connect, $_POST['username']);			$password = mysqli_real_escape_string($connect, $_POST['password']);			$sql = "SELECT isloggedin, type FROM user WHERE username='$username'";			$result = mysqli_query($connect, $sql);			$row = mysqli_fetch_assoc($result);			if ($row['isloggedin'] == "Y") {				session_start();				$_session['loggedin'] = '<h1 style="color:#F00;text-align:center;">This user is already logged in!</h1>';				die(header("location: testlogin.php?"));			} else {				$type = $row['type'];				if (count($_SESSION['error']) > 0) {					session_start();				die(header("location: testlogin.php?"));				} else {					$user = new User;					if ($user->authenticate($username,$password)) {						unset($_SESSION['formAttempt']);						$server = ip2long($_SERVER['REMOTE_ADDR']);						mysqli_query($connect, "UPDATE user SET lastlogin='$now', lastActive='$now', isloggedin='Y', loggedinfrom='$server' WHERE cid='$_SESSION[cid]' AND uid='$_SESSION[uid]'") or die("Error: ".mysqli_error($connect));						mysqli_query($connect, "UPDATE clients SET lastlogin='$now' WHERE cid='$_SESSION[cid]'") or die("Error: ".mysqli_error($connect));						die(header("location: chkactivation.php?"));					} else {						session_start();						$_SESSION['error'] = "Problem with your username or password!";				die(header("location: testlogin.php?"));					}				}			}?>

    will u please help me to find out the problem.....

  14. back with a self try. please suggest if it gives d exact result as the above code gives..

    <?php$totqty = 0;$totamt = 0;$querysss = "SELECT qty, amt FROM fifo WHERE sid=$sid AND cid=$cid ORDER BY date DESC";if ($stmt = mysqli_prepare($connect, $querysss)) {//if (mysqli_stmt_bind_param($stmt, 'i', $sid)){	mysqli_stmt_execute($stmt) or die("Errorsssss: " . mysqli_error($connect));	mysqli_stmt_bind_result($stmt, $qty, $amt);	while (mysqli_stmt_fetch($stmt)) {		if ( !is_null($qty) ){			if ($qty>0 && $qty+$totqty > $cqty){				$diff = $cqty - $totqty;				$totqty = $cqty;				$totamt += $diff*$amt/$qty;			// now you must record the remain count = $row->remain-$diff			} else if ($qty>0) {				$totqty += $qty;				$totamt += $qty*$amt/$qty;			// now you must record the remain=0			}		} else if ($qty+$totqty > $cqty){			$diff = $cqty-$totqty;			$totqty = $cqty;			$totamt += $diff*$amt/$qty;		// now you must record the remain count = $row->qty-$diff		} else {			$totqty += $qty;			$totamt += $amt;		// now you must record the remain=0		}	}	if ($cqty != $totqty) {		echo "error: recorded totqty={$totqty} purchased is insufficient to match cqty={$cqty}";	}} else {	echo 'error: could not bind';}$totamtarr[ $sid ] = $totamt;$runSum = 0;foreach($totamtarr as $clamt) {	$runSum += $clamt;	$total[] = $runSum;}mysqli_stmt_close($stmt);?>

    I changed the code by getting idea from <php.net/manual/en/mysqli-stmt.bind-result.php>

×
×
  • Create New...