Search the Community
Showing results for tags 'php pdo'.
-
Hi guys! I've tried to insert data inside an input's value but the input goes like it is hidden, When I inspect the page it shows that there is no input inside my form. I've tried to move the code to the top of page but nothing is changed always a hidden input while it is not hidden at all as you can see below: <div class="mb-3"> <?php //Checking if submit button is clicked if (isset($_POST['submit'])) { //database cn $db = new PDO("mysql:host=localhost;dbname=centrify","root",""); $username = $_POST['user']; $stmt = $db->prepare("SELECT * FROM agencies_data WHERE agency_user = ".$username.""); $stmt->execute(); ?> <input class="form-control" type="text" name="oid" value="<?php while($item = $stmt->fetch()) { echo $item['agency_user']; } ?>"> <?php } ?> </div> I've tested a lot of placements but it doesnt work for me.
-
hi, guys im actually trying to figure what is wrong here in my code as it var dumps in google chrome but not in firefox or opera, its quite confusing as php is a server side scripting language but is behaving like a client side script. it outputs fine in chrome but not in firefox as it gives "bool(false)" for the same script. can any one help me on this. the code to dbconfig is here: <?php session_start(); $host="localhost"; $dbName="project"; $dbUname="root"; $dbPass=""; try { $conn=new PDO("mysql: host=$host;dbname=$dbName;charset=utf8", $dbUname, $dbPass); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $e->getMessage(); } require_once 'classes.inc.php'; $project= new projecteg($conn); the code to class's method is here: public function viewProtectedArea($uname,$pass) { $active=1; $stmth= $this->_db->prepare("select * from user where uname=:uname and pass=:pass and activated={$active}"); $stmth->bindparam(":uname",$uname); $stmth->bindparam(":pass",$pass); $stmth->execute(); return $stmth->fetch(PDO::FETCH_ASSOC); } and the code to login page is here: include_once 'dbconfig.inc.php'; if (isset($_POST['submit-login'])) { $uname= htmlentities($_POST['unamel']); $unamel= stripslashes($uname); $pass= htmlentities($_POST['passl']); $pass1= stripslashes($pass); $passl= md5($pass1); $user = $project->viewProtectedArea($unamel,$passl); var_dump($user); exit(); if ($user) { $_SESSION['id']=$user['user_id']; $_SESSION['fname']=$user['fname']; $_SESSION['lname']=$user['lname']; $_SESSION['uname']=$user['uname']; $_SESSION['email']=$user['email']; $_SESSION['phone']=$user['phone']; $_SESSION['app']=TRUE; $user_ok=TRUE; header("location: ../home.php?u={$_SESSION['uname']}"); } else { header("location: ../index.php?nosession"); } } please help me out.
-
Hi, Im using OOP and PDO prepared statement. Will it be possible to construct a class and shorten the following 3 lines of code, the array portion of the code. A lot of repetition. $parms = array(); $parms[] = array(':id',$idnr,PDO::PARAM_INT); $parms[] = array(':name',$name1,PDO::PARAM_STR); Code Sample $idnr = 123; $name1 = "tom"; $parms = array(); $parms[] = array(':id',$idnr,PDO::PARAM_INT); $parms[] = array(':name',$name1,PDO::PARAM_STR); // then use the $parms array as the second parameter in your query calling statement - $users = DB::getInstance()->query("SELECT * FROM users WHERE id = :id AND name = :name",$parms);
-
in php, pdo, the code does not output any error messages when table is not found. try { $stmt = $dbh->prepare("SELECT * FROM 1234"); $stmt->execute(); $row = $stmt->fetch(); } catch (PDOException $e) { echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine(); } the code only seems to work when the following code is placed just under the "try {" $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); the above code is used just below the connection to the database code. how to get the try - catch code to work without using the setAttribute code every time for prepared statements?
-
I am trying to query tab delimited first and last names from a file against a table in mysql. I can see my data coming in from the file and test SQL works fine on the mysql command line, but I get zero results from my code. <?php require_once('auth.php'); $conn = new PDO("mysql:hostname=localhost;dbname=$dbname", $username, $pw); $file = fopen('nameList1.txt','r'); //change to whatever name it is $firstname = ''; $lastname = ''; $index = -1; $id = -1; $tab = ' '; //change this to the delimiter, of course while ($line = fgets($file)) { $index = strrpos($line, $tab); $firstname = substr($line, 0, $index); //var_dump($firstname); $lastname = substr($line, $index + strlen($tab)); //var_dump($lastname); $stmt = $conn->prepare("SELECT id FROM dbname WHERE FName = $firstname AND LName = $lastname"); $stmt->execute(); $result = $stmt->fetchAll(); var_dump($result); } fclose($file); ?> ****************************************************************** +-----------------------+--------------+------+-----+---------+----------------+ | id | mediumint(9) | NO | PRI | NULL | auto_increment | | StateVoterID | int(10) | YES | | NULL | | | CountyVoterID | int(10) | YES | | NULL | | | Title | char(30) | YES | | NULL | | | FName | char(30) | YES | | NULL | | | MName | char(30) | YES | | NULL | | | LName | char(30) | YES | | NULL | | | NameSuffix | char(30) | YES | | NULL | | | Birthdate | int(10) | YES | | NULL | | | Gender | char(30) | YES | | NULL | | | RegStNum | char(30) | YES | | NULL | | | RegStFrac | char(30) | YES | | NULL | | | RegStName | char(30) | YES | | NULL | | | RegStType | char(30) | YES | | NULL | | | RegUnitType | char(30) | YES | | NULL | | | RegStPreDirection | char(30) | YES | | NULL | | | RegStPostDirection | char(30) | YES | | NULL | | | RegUnitNum | int(10) | YES | | NULL | | | RegCity | char(30) | YES | | NULL | | | RegState | char(30) | YES | | NULL | | | RegZipCode | int(10) | YES | | NULL | | | CountyCode | int(10) | YES | | NULL | | | PrecinctCode | char(10) | YES | | NULL | | | PrecinctPart | char(30) | YES | | NULL | | | LegislativeDistrict | char(30) | YES | | NULL | | | CongressionalDistrict | char(30) | YES | | NULL | | | Mail1 | char(30) | YES | | NULL | | | Mail2 | char(30) | YES | | NULL | | | Mail3 | char(30) | YES | | NULL | | | Mail4 | char(30) | YES | | NULL | | | MailCity | char(30) | YES | | NULL | | | MailZip | char(30) | YES | | NULL | | | MailCountry | char(30) | YES | | NULL | | | Registrationdate | char(30) | YES | | NULL | | | AbsenteeType | char(30) | YES | | NULL | | | LastVoted | char(30) | YES | | NULL | | | StatusCode | char(30) | YES | | NULL | | +-----------------------+--------------+------+-----+---------+----------------+ 37 rows in set (0.00 sec) ********************************** test SQL *************************************************** mysql> SELECT * FROM list WHERE FName='TARA' AND LName='AABELLERA'; +----+--------------+---------------+-------+-------+-------+-----------+------------+-----------+--------+----------+-----------+-----------+-----------+-------------+-------------------+--------------------+------------+------------+----------+------------+------------+--------------+--------------+---------------------+-----------------------+-------+-------+-------+-------+----------+---------+-------------+------------------+--------------+------------+------------+ | id | StateVoterID | CountyVoterID | Title | FName | MName | LName | NameSuffix | Birthdate | Gender | RegStNum | RegStFrac | RegStName | RegStType | RegUnitType | RegStPreDirection | RegStPostDirection | RegUnitNum | RegCity | RegState | RegZipCode | CountyCode | PrecinctCode | PrecinctPart | LegislativeDistrict | CongressionalDistrict | Mail1 | Mail2 | Mail3 | Mail4 | MailCity | MailZip | MailCountry | Registrationdate | AbsenteeType | LastVoted | StatusCode | +----+--------------+---------------+-------+-------+-------+-----------+------------+-----------+--------+----------+-----------+-----------+-----------+-------------+-------------------+--------------------+------------+------------+----------+------------+------------+--------------+--------------+---------------------+-----------------------+-------+-------+-------+-------+----------+---------+-------------+------------------+--------------+------------+------------+ | 9 | 0 | 458198 | | TARA | L | AABELLERA | | 2 | F | 5804 | | 141ST | PL | | | NE | 0 | MARYSVILLE | WA | 98271 | 0 | 101231 | 0 | 39 | 2 | | | | | | | | 05/05/2004 | P | 11/08/2011 | A | +----+--------------+---------------+-------+-------+-------+-----------+------------+-----------+--------+----------+-----------+-----------+-----------+-------------+-------------------+--------------------+------------+------------+----------+------------+------------+--------------+--------------+---------------------+-----------------------+-------+-------+-------+-------+----------+---------+-------------+------------------+--------------+------------+------------+ 1 row in set (27.22 sec) *********************** var_dump() ************************************************* array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0) { } array(0)
-
Hi I am new in php. Below code works fine. But If I change Select Command Like this: $sql = "SELECT login_id,password FROM user_right WHERE login_id = '$username' and password = '$password'"; It shows error recorde not found. Also I need to show the role of select user. Pls Help me <?php include_once'../inc/header.php'; if (isset($_POST['submit']) && $_POST['submit'] != "" ) { if(empty($_POST['username'])) { $handleError = "User is empty!"; $_SESSION["errormsg"] = $handleError; header("Location:../notification/errormsg.php"); //echo $handleError; return false; } if(empty($_POST['password'])) { $handleError = "Password is empty!"; $_SESSION["errormsg"] = $handleError; header("Location:../notification/errormsg.php"); //echo $handleError; return false; } $username = trim($_POST['username']); $password = trim($_POST['password']); try { $sql = "SELECT * FROM user_right WHERE login_id = '$username' and password = '$password'"; $stmt = $dbh->prepare($sql); $stmt->setFetchMode(PDO::FETCH_ASSOC); if ($stmt = $dbh->query($sql)) { if ($stmt->fetchColumn() > 0) { $_SESSION["username"] = $username; $_SESSION["password"] = $password; header("Location:../admin/"); exit(); } else { $handleError="user name or password is wrong"; $_SESSION["errormsg"] = $handleError; header("Location:../notification/errormsg.php"); exit(); }; } } catch (PDOException $e) { echo $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); } } include '../inc/footer.php';
-
How To Resolve “Notice: Array To String Conversion In”
copperspeed posted a topic in PHP Coding Help
I can't figure out why I am receiving the following error Notice: Array to String conversion in 'path' line 462. Below is the code for line 462. public function fetchOneBrg(array $conditions){ $db = Core::getInstance(); $sql = "SELECT * FROM ".USERS_BRG." WHERE "; $params = array(); $i=0; foreach ($conditions as $column => $value) { if (preg_match('/^[a-z-.-_]+$/', $column)) { if($i !=0){ $sql .= " AND "; } $sql .= "$column = ?"; $params[] = $value; $i++; } } $res = $db->dbh->prepare($sql); Line 462: $res->execute(array_values($params)); return $res->fetch(PDO::FETCH_ASSOC); $ststres = $db->dbh->prepare("SELECT * FROM ".USERS_STATS." WHERE user_id = :uID ORDER BY id DESC LIMIT :zero, :forty"); $ststres->bindParam(':uID',$udata['id'],PDO::PARAM_INT); $ststres->bindValue(':zero',0,PDO::PARAM_INT); $ststres->bindValue(':forty',40,PDO::PARAM_INT); $ststres->execute(); $ststres=$ststres->fetchAll(PDO::FETCH_ASSOC); I suspect it is the code above being passed in as a string to during the call array(['id'=>$ststres[ststval].to_id] below in Smarty. Doing a var_dump returns strings in array. How to resolve this and why is the string conversion happening on the ID's? Example of var_dump: string(4) "1066" string(4) "1066" string(4) "1066" This is the call to the function: {assign var='brgdatas' value=$brgObj->fetchOneBrg(array(['id'=>$ststres[ststval].to_id]))} Thank you for your help.