Jump to content

funbinod

Members
  • Posts

    501
  • Joined

  • Last visited

Everything posted by funbinod

  1. oh i did it. thank u for the company. i changed this-- if ($password == $dbPass && $type == "1") { error_log("Welcome {$username}!"); return true;}else { error_log("Wrong password!"); return false; } to-- if ($password != $dbPass) { error_log("Wrong password!"); return false; } and its done. but i need one more help. this successful login redirects to admin.php (as i've defined on login-precess file). but i want to change the page to redirect to different pages according to user types. how can i do that? please guide...
  2. sorry i couldnt understand what u suggested but below the authentication function there is session start function like this --- private function _setSession() { if (session_id() == '') { session_start(); } $_SESSION['uid'] = $this->uid; $_SESSION['name'] = $this->name; $_SESSION['address'] = $this->address; $_SESSION['phone'] = $this->phone; $_SESSION['username'] = $this->username; $_SESSION['password'] = $this->password; $_SESSION['type'] = $this->type; $_SESSION['isLoggedIn'] = $this->isLoggedIn; } // end function setSession and init user function like this private function _initUser() { $this->uid = $_SESSION['uid']; $this->name = $_SESSION['name']; $this->address = $_SESSION['address']; $this->phone = $_SESSION['phone']; $this->username = $_SESSION['username']; $this->password = $_SESSION['password']; $this->type = $_SESSION['type']; $this->isLoggedIn = $_SESSION['isLoggedIn']; } // end function initUser
  3. uhh! i've not thought about that. but after setting session start also there is same problem.....
  4. thank u i made it done with something different // start authentication $username = $_POST['username']; $password = $_POST['password']; $query = "SELECT * FROM user WHERE username = '{$username}'"; $result = mysqli_query($mysqli, $query); if (!$result) { error_log("Cannot retrieve account record for {$username}"); return false; } // no while loop for single row $row = mysqli_fetch_array($result); $dbPass = $row['password']; $type = $row['type']; $count = mysqli_num_rows($result); if ($password == $dbPass && $type == "1") { error_log("Welcome {$username}!"); return true; } else { error_log("Wrong password!"); return false; } $this->uid = $row['uid']; $this->name = $row['name']; $this->username = $row['username']; $this->password = $row['password']; $this->type = $row['type']; $this->isLoggedIn = true; $this->_setSession(); return true; } but session couldn't be started. it failed load authenticated page when i added this line to top of it.... <?phprequire_once('functions.php');$user = new User;if (!$user->isLoggedIn) { die(header("location: login.php"));}?> and went back to login page.
  5. i got problem somewhere while trying to authenticate users while loging in. what i wrote to authenticate in classuser file is this-- // start authentication $safeUser = $mysqli->real_escape_string($username); $incomingPass = $mysqli->real_escape_string($password); $query = "SELECT * FROM user WHERE username = '{$safeUser}'"; if (!$result = $mysqli->query($query)) { error_log("Cannot retrieve account record for {$username}"); return false; } // no while loop for single row $row = $result->fetch_assoc(); $dbPass = $row['password']; if (crypt($incomingPass, $dbPass) != $dbPass) { error_log("Wrong Password for {$username}!"); return false; } i've mysql table 'user' and columns 'username' & 'password'. while trying loging in with valid username & password also it gives username & password related error. both username & password are recorded in CHAR(10) type.....
  6. yes i'm working with 2 pages. 'install.php' & 'installprocess.php'. and yes both pages have session_start()...........
  7. but what i faced the problem is not that. even after changing to !empty the problem remained same.... Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21
  8. yes i did it. above is the code what i used for that.....
  9. i want to make a install script. for this complete database should be installed at a time & in a single process file i have to do this. and i succeeded in it like this.... <?phpdate_default_timezone_set('Asia/Kathmandu');// set mysql variables$db_host = 'localhost';$db_dbase = 'mimosa_cashier';$db_user = 'root';$db_pass = '[Removed for safety]';// connect$connect = mysqli_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysqli_error($connect));// create database$sql = ("CREATE DATABASE IF NOT EXISTS mimosa_cashier");mysqli_query($connect, $sql) or die ("Error creating database: " . mysqli_error($connect));echo "Database created successfully<br />";mysqli_close($connect);$connect1 = mysqli_connect($db_host, $db_user, $db_pass, $db_dbase);if (!$connect1) die("Unable to connect to database: " . mysqli_error($connect1));// create tables$sql2 = "CREATE TABLE IF NOT EXISTS info(company CHAR(50), address CHAR(50), email CHAR(50), phone CHAR(15), user CHAR(10), pass CHAR(10))";mysqli_query($connect1, $sql2) or die ("Error creating table 'info': " . mysqli_error($connect1));echo "info created successfully<br />";// echo success text die("<h2>Mimosa Cashier - Basic registered successfully for <span style=color:#F00;text-decoration:underline;>" . $_POST['company']. "</span>!"); die(header("location: admin.php?"));mysqli_close($connect1);
  10. i've thought of trying it differently. to create a connect string without database. and after the query of database creation, create another connect string with the database and use create table query. but i've to fix my error reporting problem for form validation that i've asked for support here- http://w3schools.invisionzone.com/index.php?showtopic=50146 do u have solution for this either...????
  11. following is the line from action script if (isset($_SESSION['error'])) { unset($_SESSION['error']);}$_SESSION['error'] = array();$required = array("company", "address", "user", "pass", "conpass");// check required fieldforeach ($required as $requiredField) { if (!isset($_POST[$requiredField]) || $_POST[$requiredField] == "") { $_SESSION['error'][] = $requiredField . "is required."; }}
  12. no! there is not my answer. i've read this throughly. and i know how to create DATABASE and TABLE. i'm trying these two queries to be done with single SUBMIT and i failed $sql = ("CREATE DATABASE mimosa_cashier");mysqli_query($connect, $sql) or die ("Error creating database: " . mysqli_error($connect));// create tables$sql2 = ("CREATE TABLE info(company CHAR(50), address CHAR(50), email CHAR(50), phone CHAR(15), user CHAR(10), pass CHAR(10))");mysqli_query($connect, $sql2) or die ("Error creating table 'info': " . mysqli_error($connect));
  13. i'm trying to make a install script. for that i wish to CREATE a DATABASE and at the same time CREATE some TABLEs for it with a single form submit? for this can DATABASE be selected within the "CREATE TABLE" query? if yes how? or there is any other idea?
  14. while trying another method for from validation i encountered error if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) { unset($_SESSION['formAttempt']); print "Error(s):<br />n"; foreach ($_SESSION['error'] as $error) { print $error . "<br />n"; } } it returned error: Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21 what could be this error! or it could be from action script!?
  15. funbinod

    mysql to mysqli

    it works fine with "mysql". it didnt work converting to "mysqli". nothing else are changed. opening and closing tags of SELECT are before and after this PHP. like -- <select name="vname" id="vname"><option></option><?php// code goes here?></select> value of $rows is list of names from 'vname' column and yes the column name is correct..
  16. funbinod

    mysql to mysqli

    i read the topics & documents on w3schools and php.net. but i got difficulty on understanding mysqli_result or i dunno i did this <?php// select table$query = "SELECT * FROM vender";$result = mysqli_query($connect, $query);if (!$result) die("Unable to select database: " . mysqli_error());// fetch data$rows = mysqli_num_rows($result);for ($n = 0 ; $n < $rows ; ++$n){ echo "<option>" . mysqli_result($result, $n, 'vname') . "</option>" ;}?> but malfunctioned.
  17. funbinod

    mysql to mysqli

    got difficulty on converting mysql to mysqli to these line <?php// select table$query = "SELECT * FROM vender";$result = mysql_query($query);if (!$result) die("Unable to select database: " . mysqli_error());// fetch data$rows = mysql_num_rows($result);for ($n = 0 ; $n < $rows ; ++$n){ echo "<option>" . mysql_result($result,$n,'vname') . "</option>" ;}?> please guide....
  18. thank u all again. and i found the problem now. it was mistake on column name of database. but thank u for helping me understand basics of mysqli. now am trying to write everything on mysqli.
  19. thank u all. i got the point and i edited that and made it work. but at another point got another problem $payment = mysqli_query($connect, "SELECT sum(amt) FROM payment WHERE vid='$row[vid]'") or die(mysqli_errno()); and got this message-- Warning: mysqli_errno() expects exactly 1 parameter, 0 given in E:xampphtdocsacpandavvregister.php on line 109 but the same line on another page doesnt show any warning and works properly..
  20. the following line-- mysqli_query($connect, $sql) or die('Error: ' . mysql_error()); works for $connect = mysql_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysql_error());$sql = ("INSERT INTO customer (cname, cadd, cemail, cphone, cperson, cmob, cob)VALUES ('$_POST[cname]', '$_POST[cadd]', '$_POST[cemail]', '$_POST[cphone]', '$_POST[cperson]', '$_POST[cmob]', '$_POST[cob]')"); but doesnot work for $connect = mysql_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysql_error());$sql = ("INSERT INTO vender (vname, vadd, vemail, vphone, vperson, vmob, vob)VALUES ('$_POST[vname]', '$_POST[vadd]', '$_POST[vemail]', '$_POST[vphone]', '$_POST[vperson]', '$_POST[vmob]', '$_POST[vob]'"); & gives error message --- Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in E:xampphtdocsacpandavvregisterpost.php on line 63 i couldnt understand why!
  21. besides this, can u guide me how to insert amount to the database with 00,000.00 format?
  22. wow! i made it done $balance = $TotalOb['sum(cob)'] + $TotalSales['sum(amt)'] - $TotalReceipt['sum(amt)'];
  23. yes i tried that. both '$TotalSales' & '$TotalReceipt' give the perfect value. but while using math between them is not working..
  24. funbinod

    edit a record

    sorry! i think failed to make u understand my problem! let it be!
  25. i tried this $TotalSales = mysql_fetch_array($sales);$TotalReceipts = mysql_fetch_array($receipt);$TotalBalance = $TotalSales - $TotalReceipts;echo $TotalBalance; what is the problem????
×
×
  • Create New...