I'm doing both SELECT and UPDATE queries using named placeholders. But course data from the database doesn't populate form, as expected. The database table row records don't populate, each time I try to edit a course in the browser. I connect to the database usining PDO. And I do SELECT and UPDATE queries using named placeholders. The following is my "modify-course.php": <?php // configuration require("../includes/config.php"); //select a particular admin by id $admin_id = isset($_GET["admin_id"]) ? $_GET["admin_id"] : ''; $stmt = $pdo->prepare("SELECT * FROM admin WHERE admin_id=:admin_id"); $stmt->execute(['admin_id' => $admin_id]); $admin = $stmt->fetch(); # get admin data if (!$admin) { header("Location: …

Member Avatar
+0 forum 0

I'm trying to upgrade my script from PHP 5.5 to PHP 7.2. And that came with the script not able to modify a selected table row as before. The records don't even populate whenever I try to edit a course in the browser. Please, note that I'm connecting to the database via PDO. The following is my script: <?php // configuration require("../includes/config.php"); // query admin table to retrieve current admin's profile $admin = query("SELECT * FROM admin WHERE admin_id = ?", $_SESSION["admin_id"]); if (!$admin) { redirect("login.php"); } // query users table to retrieve admin homepage's contents // $users = query("SELECT …

Member Avatar
Member Avatar
+0 forum 3

Hi, I don't know if this is possible or a really stupid question. I was wondering if after a select query has been executed can the results be filtered for specific values, and not just a single value but 7 different values. with what i want to accomplish its either im making it difficult for myself or the solution is pretty simple. okay for example i have a select query like so: $stmt = $conn->prepare("SELECT id, name, price, type, img FROM table"); $stmt->execute(); $result = $stmt->fetchAll(); now i have a page that has buttons which represent different types of "type". …

Member Avatar
Member Avatar
+0 forum 3

Hello, I am trying to insert a registration form with password using `password_hash()` but I am not sure what is wrong with whatever i am doing because the password doesn't get inserted into the database although all the other values do and no errors. database : password | varchar(255) php: $res = $conn->prepare("INSERT INTO table(id, name, pass) VALUES(:id, :name, :pass)"); $id = $_POST['id']; $name = $_POST['name']; $password = $_POST['password']; $password = password_hash($password, PASSWORD_DEFAULT); $res->bindParam(':id', $id, PDO::PARAM_STR); $res->bindParam(':name', $name, PDO::PARAM_STR); $res->bindParam(':pass', $password, PDO::PARAM_STR); $res->execute(); html: `<input name="password" type="password" placeholder="Password"` thanks in advance.

Member Avatar
Member Avatar
+0 forum 3

I have a little issue I can't figgure out. I can't seem to figure out how to add dots to my pagination so I don't have more pagination numbers than mysql results in the page XD . This is my code: $query = "SELECT id, ....."; $records_per_page=10; $crud->paginglink($query,$records_per_page); public function paginglink($query,$records_per_page) { $self = $_SERVER['PHP_SELF']; $stmt = $this->db->prepare($query); $stmt->execute(); $total_no_of_records = $stmt->rowCount(); if($total_no_of_records > 0) { ?><ul class="pagination"><?php $total_no_of_pages=ceil($total_no_of_records/$records_per_page); $current_page=1; if(isset($_GET["page_no"])) { $current_page=$_GET["page_no"]; } if($current_page!=1) { $previous =$current_page-1; echo "<li><a href='".$self."?page_no=1'>Inceput</a></li>"; echo "<li><a href='".$self."?page_no=".$previous."' aria-label='Inapoi'><span aria-hidden='true'>&laquo;</span></a></li>"; } for($i=1;$i<=$total_no_of_pages;$i++) { if($i==$current_page) { echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>"; } else { echo "<li><a …

Member Avatar
Member Avatar
+0 forum 5

I'm trying to find a way to output whatever BLOB files are inserted into a silly database. In my code when I query the CV column I get all sorts of weird symbols. Can you guys please help me fix my code? $crud->dataview($query); }else{ $query = "SELECT id, from_unixtime(cheie_wp) as datetime, nume, prenume, email, telefon, oras, denumiri_job, cv FROM jobselection_data_old ORDER BY id DESC"; $records_per_page=10; $newquery = $crud->paging($query,$records_per_page); $crud->dataview($newquery); public function dataview($query) { $stmt = $this->db->prepare($query); $stmt->execute(); if($stmt->rowCount()>0) { while($row=$stmt->fetch(PDO::FETCH_ASSOC)) { $date_in = $row['datetime']; $date_out = explode(' ', $date_in); ?> <tr> <td><?php echo $date_out[0]; ?></td> <td><?php print($row['nume']); ?></td> <td><?php print($row['prenume']); …

Member Avatar
Member Avatar
+0 forum 8

please help me cause I am totally lost on this one. I am trying to fetch the results from a database that has the data inserted in a weird way. The IDs are not unique, thus I have multiple values with the same ID in the ID column. I am trying to group these IDs and output the Values for those IDs on a single Row. Right now my code outputs the values aligned in a column associated with their ID. The database was generated by this by one of the client's scripts and it is a huge (limited only …

Member Avatar
Member Avatar
+0 forum 2

Hello, Recently I am starting to code my scripts in PDO method to manage the information in a mysql database. In this case I am having an issue how to use the best practice conditions when dealing with a POST **int** value. With the posted values I am making a select query, a short version of it is as follows if( isset($_POST['gjendja_id']) ){ $gjendja_id = intval($_POST['gjendja_id']); if( $gjendja_id > 0 ){ $gjendja_id = $_POST['gjendja_id']; }else{ $gjendja_id = 'IS NOT NULL'; } }else{ $gjendja_id = 'IS NOT NULL'; } The query that would be executed try { $counter = 1; $response …

Member Avatar
Member Avatar
+0 forum 7

This question is similar to this [one](https://www.daniweb.com/programming/web-development/threads/371092/notice-undefined-index-id-on-line-26) However, my insert does not involve a form but a direct mysql query that looks like this $query2 = "insert into table(author,title,abstract) values(:author,:title,:abstract) "; $stm=$con->prepare($query2); $stm->bindValue(':author', $author, PDO::PARAM_STR); $stm->bindValue(':title', $title, PDO::PARAM_STR); $stm->bindValue(':abstract', $abstract, PDO::PARAM_STR); $stm->execute(); echo "$author &nbsp $title &nbsp $abstract <br>" In this scenario, 'id' is an auto increment. How can i get $id value when the insertion was not made via a form input?

Member Avatar
Member Avatar
+0 forum 2

I have this code session_start(); $username = $_SESSION['username']; function getUserRole($username, $roleid){ $con=dbConnect(); $query="select * from user inner join userrole on user.id = userrole.userid inner join role on role.id = userrole.roleid where username = $username"; $sql=$con->prepare($query); $sql->bindValue(':username',$username); $sql->bindValue(':roleid',$roleid); $sql->execute(); $row = $sql->fetch(); $username = $row['username']; $roleid = $row['roleid']; if($row > 0){ return $username; } else{ return false; } } My pain is that when i query the database where the username = $username, the query returns nothing but when i use the text for username i get results. Do session variables work inside functions? What can i be possibly be doing …

Member Avatar
Member Avatar
+0 forum 7

Apparently I don’t know how to insert a row into a MySQL data base using PDP and I would like to know what I am missing This PHP PDO script does not insert data into a database. I would like to know why. It does not error out but the data base is not populated and the return value is apparently undefined. Below is the table: CREATE TABLE animals ( Id INT(11) NOT NULL AUTO_INCREMENT, animal_type VARCHAR(32) DEFAULT NULL, animal_name VARCHAR(32) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=MYISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; Below is the PHP script: <?php /* mysql hostname …

Member Avatar
Member Avatar
+0 forum 5

Im working on a small website and im a little confused on one step. I'm following a very simple mvc pattern, ive currently got one controller that creates a session array that holds all the posted data IF the form has been submitted, This data is coming from several different dropdown boxes which all have different Ids: if(isset($_POST['btn-calcCon'])){ $_SESSION['post-data'] = $_POST; $_SESSION['post-data']['heatingType']; $_SESSION['post-data']['meterType']; $_SESSION['post-data']['noBedrooms']; $_SESSION['post-data']['houseType']; $_SESSION['post-data']['houseAge']; } I have a select statement in my Model class that uses these session variables in a WHERE clause as below: <?php session_start(); require_once('../Config/config.php'); class ConCalc { public $dbconn; public function __construct() { $database …

Member Avatar
Member Avatar
+0 forum 2

SEEMS AS IF MY ARTICLE HAS BEEN SUBMITTED TWICE. I DO APOLOGISE FOR THAT Hi guys, I'm working on a small website and I'm currently stuck on a small issue. Ive got a set of dropdown boxes created and populated in HTML, for example: <select name="heatingType" id="heatingType" required> <option value="" disabled selected>Select Your Option</option> <option value = "Gas">Gas</option> <option value = "Electricity">Electricity</option> <option value = "Other">Other</option> </select> I'm able to store the values in a variable once the form has been posted/submitted, These are stored in my Controller Class eg: $newCalc = new ConCalc(); // instantiate drawing tool $draw = …

Member Avatar
Member Avatar
+0 forum 2

i have following code first insert is working properly and data in to database but second insert query which depends on last_insert_id() fails.I have tried to find out mistake but failed to do so? <?php namespace Solutions\File; class AddUserData { function __construct($DB_con) { $this->db = $DB_con; } public function insert_detail($productDetails){ var_dump($productDetails); try { $stmt = $this->db->prepare("INSERT INTO product_master(reg_id,category_id,sub_cat_id,product_name) VALUES(:reg_id,:category_id,:sub_cat_id,:product_name)"); $query=$this->db->prepare("INSERT INTO gy_product_detail(product_id,product_detail," . "product_image_back,product_image_left,product_image_name,product_image_right," . "product_rate,product_discount) VALUES (last_insert_id(),:product_details," . ":product_image1,:product_image2,:product_image3,:product_image4," . ":rate,:discount"); $stmt->execute(array(':reg_id'=>$productDetails['registration_id'], ':category_id'=>$productDetails['catagory_id'], ':sub_cat_id'=>$productDetails['sub_cat_id'], ':product_name'=>$productDetails['product_name'])); $query->execute(array( ':product_details'=>$productDetails['product_details'], ':product_image1'=>$productDetails['image1']['name'], ':product_image2'=>$productDetails['image2']['name'], ':product_image3'=>$productDetails['image3']['name'], ':product_image4'=>$productDetails['image4']['name'], ':rate'=>$productDetails['product_cost'], ':discount'=>$productDetails['product_discount'])); return $stmt; } catch(PDOException $e) { echo $e->getMessage(); } } } can anyone guide where i …

Member Avatar
Member Avatar
+0 forum 10

Hello, This tutorial is the next of “[A simple Data Layer for OOP PHP Applications](https://www.daniweb.com/programming/web-development/tutorials/500118/a-simple-data-layer-for-oop-php-applications)” so having read it and made your own tests is needed to understanding what we are doing. So far we have a Db object (child of PDO that standardize and simplifies its use) , a Db factory object (because our web app may need more than one DB object) and Data Workers (for working with data from DB) (there are in the tutorial mentioned above) . We are going to do it in such way that can be implemented without the use of any framework …

Member Avatar
Member Avatar
+4 forum 1

A simple Data Layer for OOP PHP Applications Hello, first of all to understand this tutorial would be best if you have some knowledges about OOP ( https://www.daniweb.com/programming/web-development/tutorials/437592/introduction-to-phps-object-orientation by priteas ) and DB usage (MySQL in this case) with PHP https://www.daniweb.com/programming/web-development/threads/499320/common-issues-with-mysql-and-php by diafol ). What we will try to achieve is a consistent usage of the DB (we will use MySQL but you can use what ever DB you like). We will not map query results in objects / lists of objects in this tutorial (there will be another one that will contain that) , but just retrieve the results …

Member Avatar
Member Avatar
+4 forum 1

Hi I am trying to create a update function. But it not updating in the database. Please help me to fix. **Test-2.php** $whereString = ''; $bind = NULL; if(isset($_POST['Submit'])) { if($_POST) { $SCYQ64UKID = $_GET['SCYQ64UKID']; $SCYQ64AVGP = $_POST['SCYQ64AVGP']*100; $searchFields = array('SCYQ64EMAL'=>$_POST['SCYQ64EMAL'],'SCYQ64EV01'=>$_POST['SCYQ64EV01'],'SCYQ64EV02'=>$_POST['SCYQ64EV02'],'SCYQ64EV03'=>$_POST['SCYQ64EV03'],'SCYQ64EV04'=>$_POST['SCYQ64EV04'],'SCYQ64EV05'=>$_POST['SCYQ64EV05'],'SCYQ64EV06'=>$_POST['SCYQ64EV06'],'SCUSER'=>$_POST['SCUSER'],'SCYQ64AVGP'=>$SCYQ64AVGP,'SCYQ64TZ'=>$_POST['SCYQ64TZ'],'SCJOBN'=>gethostname(),'SCPID'=>'SSWEB','SCUPMJ'=>$_POST['SCUPMJ'],'SCUPMT'=>$_POST['SCUPMT']); if($post = array_filter($_POST)) { if($fields = array_intersect_key($searchFields, $post)) { $where = array(); $bind = array(); foreach($fields as $key=>$field) { $where[] = "$key LIKE '%$field%'"; $bind[":$key"] = $_POST[$key]; $gwhere[] = "$key=$field"; $gbind[":$key"] = $_POST[$key]; } //$whereString = ' WHERE ' . implode(' AND ', $where); $gwhereString = implode(',', $gwhere); } $Users = new Users($db); $query = $Users->smipleUpdate('FQ64000',$gwhereString,'SCYQ64UKID='.$SCYQ64UKID); } } } …

Member Avatar
Member Avatar
+0 forum 12

Hi I am trying to display count of a row using function with get values. Please help me to fix the issue **class** class Users { private $conn; private $db_name= "DATABASE"; public function __construct($db) { $this->conn = $db; } /*Join Two Tables with where condition and order by*/ public function getJoinRows($tablen1,$tablen2,$where,$order_by){ $query = $this->conn->prepare("select * FROM $this->db_name.$tablen1,$this->db_name.$tablen2 where $where ORDER BY $order_by DESC"); try { $query->execute(); return $query; }catch(PDOException $e) { die($e->getMessage()); } } /**/ public function transCount($tablen,$whereCondition) { $query = $this->conn->prepare("select count(*) from $this->db_name.$tablen where $whereCondition"); try{ $query->execute(); return $row_count = $query->fetchAll(); }catch(PDOException $e) { die($e->getMessage()); } } } …

Member Avatar
Member Avatar
+0 forum 5

I have created a function. if i provide correct username and password. i am getting a error message as **Sorry, that username / password is invalid !** can any one please help me to fix the issue. **login.php** <?php require 'include/init.php'; $general->logged_in_protect(); if(empty($_POST) === false) { $username = trim($_POST['username']); $password = trim($_POST['password']); if(empty($username)===true || empty($password)=== true) { $errors[] = 'Sorry, But we need your username and passowrd.'; } else { $login = $users->login($username, $password); if($login === false) { $errors[] = 'Sorry, that username / password is invalid'; } else { $_SESSION['user_'] = $login; header('Location: dashboard.php'); exit(); } } } ?> …

Member Avatar
Member Avatar
+0 forum 3

Hi I am trying to connection my database ODBC using function. I am getting an error **Connection error: could not find driver** **mycode is** <?php class Database{ // specify your own database credentials private $host = "servername"; private $db_name = "databsename.schemaname"; private $username = "username"; private $password = "password"; public $conn; // get the database connection public function getConnection(){ $this->conn = null; try{ $this->conn = new PDO("odbc:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); }catch(PDOException $exception){ echo "Connection error: " . $exception->getMessage(); } return $this->conn; } } ?> Please help me to fix the issue.

Member Avatar
Member Avatar
+0 forum 12

Hi there, I have a login form.which contains two input parameters. login_id and password. login_id may be mobile or email. user may use mobile no or email as login id. my table structure is uid email mobile password status when i login through mobile no it is validating and showing error messages. but if i login through email it is not checking email column. directly shows outputs to the client. below is my script: sorry for my terrible english Check Login: if($db->check_loginid($login_id)) { if($db->checkLogin($login_id, $password)) { $status = 1; if($db->checkLoginStatus($login_id, $password, $status)) { $updateapi = $db->updateApikey($login_id); $user = $db->getUsersalldetails($login_id); if($user …

Member Avatar
Member Avatar
+0 forum 1

Hi Friends I am facing an issue in update query using PDO Prepare method. Please help me to fix the issue. $consql = "UPDATE $database.$constant_application SET SCYQ64EMAL=:SCYQ64EMAL, SCYQ64EV01=:SCYQ64EV01, SCYQ64EV02=:SCYQ64EV02, SCYQ64EV03=:SCYQ64EV03,SCYQ64EV04=:SCYQ64EV04, SCYQ64EV05=:SCYQ64EV05, SCYQ64EV06=:SCYQ64EV06, SCUSER=:SCUSER, SCJOBN=:SCJOBN, SCPID=:SCPID, SCYQ64AVGP=:SCYQ64AVGP, SCYQ64TZ=:SCYQ64TZ, SCUPMJ=:SCUPMJ, SCUPMT=:SCUPMT where SCYQ64CID=:SCYQ64CID"; $row = $dbh->prepare($consql); $row->bindParam(":SCYQ64EMAL",$SCYQ64EMAL); $row->bindParam(":SCYQ64EV01",$SCYQ64EV01); $row->bindParam(":SCYQ64EV02",$SCYQ64EV02); $row->bindParam(":SCYQ64EV03",$SCYQ64EV03); $row->bindParam(":SCYQ64EV04",$SCYQ64EV04); $row->bindParam(":SCYQ64EV05",$SCYQ64EV05); $row->bindParam(":SCYQ64EV06",$SCYQ64EV06); $row->bindParam(":SCUSER",$SCUSER); $row->bindParam(":SCJOBN",$SCJOBN); $row->bindParam(":SCPID",$SCPID); $row->bindParam(":SCYQ64AVGP",$SCYQ64AVGP); $row->bindParam(":SCYQ64TZ",$SCYQ64TZ); $row->bindParam(":SCUPMJ",$SCUPMJ); $row->bindParam(":SCUPMT",$SCUPMT); $row->bindParam(":SCYQ64CID",$SCYQ64CID);

Member Avatar
Member Avatar
+0 forum 3

I've been playing with PDO and got quite a shock, so I thought I'd run this past you all. I love PDO, and I thought that the "prepare once, execute many" idea behind prepared statements was beautiful. Now previous to using prepared statements, I used to build up a long SQL 'VALUES' clause by looping through an array of "records" to insert, instead of running an INSERT query on every 'record' in the array. Sensible enough. So should I now dump that for "multiple executes" in my array loop? Well I tried. Here's my experience... I'm using a simple 'members' …

Member Avatar
Member Avatar
+4 forum 7

how to put `where clause variable $didno` in following code: $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM misscall WHERE did_no = ?"; $q = $pdo->query($sql); $mobile1 = array(); while ($mobi1 = $q->fetchColumn()) { $mobile1[] = $mobi1; } $mobile1list = join(",", $mobile1); Database::disconnect(); thanks in advance

Member Avatar
Member Avatar
+0 forum 3

Below is my database structure: PostUUID subid pricing Name Poscode abc1 1 100 userA 56000 abc2 2 100 userA 56000 abc3 1 100 userB 56000 abc4 2 100 userB 56000 abc5 1 100 userC 56000 abc6 2 100 userC 56000 Now I want to perform search on this table called 'posts'. Say I want look for PostUUID(field) where the details are as below: **-subid =1,2 -postcode=56000 -pricing-100** In the above database image, there are 3 users meeting these criteria, namely vani,kalni and nair. So the result should return 6 rows with unique PostUUID. My query: $a=$data['sub']; foreach($a as $v=>$k) { …

Member Avatar
Member Avatar
+0 forum 2

I am trying to save 2 photos to my MySQL database. I can only see one of the 2 photos in the database (i.e. its name) but I see the 2 photos in the folder I store my photos. ( A picture of how the database looks like is attached.) When I try to display the 2 photos, I only see that one photo that I saw in the database. What is the problem here? Html Code to upload photo <input type="file" id="_photo" name="_photo[]" multiple="multiple"> <input type="button" id="add_more" class="" value="Add More Files"/> Code to save photos in database and folder …

Member Avatar
Member Avatar
+0 forum 2

Hello. I want to create a database on my pc localhost and then want to use PDO to connect with that database to creating table and so on... What should i do?

Member Avatar
Member Avatar
+0 forum 8

Hello. I'm new to PHP, i've started it yesterday. I want to creat a simple CMS with (PHP and PDO), what should i do? I'm going to start with creating the CMS core. I want to create sth like a simple wordpress. What should i do? Where should i start from? Any reference for creating CMS with PHP and PDO?

Member Avatar
Member Avatar
+0 forum 9

Hi, Please help me to resolve my Script Redirection problem. Actually i have developing simple crm application php using pdo->prepare. this is working fine in localhost. but what is my problem means redirection is not working, when i uploaded to server. for refernce i hereby attached . please help me anyone. <?php session_start(); $errmsg_arr = array(); $errflag = false; // configuration include("config/db-config.php"); // new data $user = $_POST['uname']; $password = $_POST['pword']; if($user == '') { $errmsg_arr[] = 'You must enter your Username'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'You must enter your Password'; $errflag = true; …

Member Avatar
Member Avatar
+0 forum 3

Hi guys, I'm trying to connect my new project with PDO, and for simple reason witch i don't know and i've no idea i'm getting connection failedSQLSTATE[28000] [1045] Access denied for user 'www-data'@'localhost' (using password: NO) I tried everything was in my mind, i tried log to mySql by terminal, i can log properly,and with some credencial work for another connection, native mysql, and i checked if PDO driver is enabled, and is connected, so bellow my pdo settins are: config.php <?php define('DB_NAME', 'dbname'); define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PASS', 'pass'); ?> class.database.php <?php /* * To change this license header, …

Member Avatar
Member Avatar
+0 forum 2

The End.