Click here to Skip to main content
15,898,374 members
Everything / PDO

PDO

PDO

Great Reads

by Member 4206974
A PHP class that uses PDO for creating a table from JSON Objects

Latest Articles

by Member 4206974
A PHP class that uses PDO for creating a table from JSON Objects

All Articles

Sort by Score

PDO 

29 Jan 2024 by Peter_in_2780
Your array_fill() is the culprit. Take a look at what you are putting after VALUES ( implode(',',array_fill(0,count($col),implode(',', $input))) It's effectively evaluated right to left because of the nested function calls, so take the first...
7 Sep 2018 by Richard Deeming
Look at the documentation for the password_verify function: PHP: password_verify[^] You need to pass in the entered password and the stored hash of the original password. You are passing in the entered password and the computed hash of the entered password. You are totally ignoring the stored...
27 Dec 2018 by Chris Copeland
Remember that when binding parameters like this, the database adaptor will escape whatever values have been placed in the query. In this example, you're attempting to bind $searchQuery, $columnName and $columnSortOrder as actual SQL values. This won't work, as the binding will escape them (in...
22 Apr 2019 by Christian Graus
Don't leave your homework to the last minute. Your example doesn't work because you don't run the query, which it seems is done by this code: $conn = mysqli_connect($host_name, $username, $password, $database) or die("Could not connect."); $result = mysqli_query($conn, $sql1) or...
4 Jul 2020 by Luc Pattyn
I see two issues: 1. You have a typo (missing '=') in Session_Year:Session_Year 2. you shouldn't have a variable directly in your SQL statement ($pNo at the end). You probably did try with one more parameter, but if you were using the same...
17 Sep 2020 by Sandeep Mewara
Seems there is a mismatch of the variables that you have added in your query (54) compared to the count you have binded (52). A simple debugging should be able to tell you that. Given it's way too many variables, would leave this on you to...
15 Oct 2020 by Luc Pattyn
lastInsertId() is a method that applies to a PDO object, not a connection... check the documentation! :)
27 Oct 2020 by W Balboos, GHB
There's a technique you should use in this type of thing - assuming you know how to write SQL queries: 1 - create a SELECT query and see what it finds. 2 - modify the SELECT until it behaves the way you want 3 - change the SELECT query to an...
27 Oct 2020 by Patrice T
First of all , I see obvious syntax errors, you need to remove them. $sql = ("UPDATE member_registration SET ... dob=:dob; ... passport=:passport, where phn=$phn"); // remove semi here ^ remove comma here ^ ...
21 Jan 2021 by Christian Graus
$stmt->bindParam(":password", $param_password, PDO::PARAM_STR); The param in your code is :new_password. It does not match
7 Feb 2021 by Luc Pattyn
Hi, in the decision phase you select on code and selector, whereas in the deletion phase you select on code and email, possibly deleting more than you intended. Also your nesting levels are off: the second $stmt->execute() gets called even...
9 Feb 2021 by Richard MacCutchan
In your PHP code you have $order_ID=$_POST['ORDERID']; And in the HTML you have
15 Jul 2016 by Zhe Yong
Hi everyone, I'm new to PHP, so I need help from your.Currently I have 2 table for database Customer and Login.Table Customer (CustID, CustName, Phone) CustID primary key, auto increment.Table Login (Email, Password, CustID) Email Primary key, CustID Foreign key to table...
15 Jul 2016 by Richard Deeming
You have a typo in your parameter array:";password" => $password,The parameter name should start with a colon (:), but it currently starts with a semi-colon (;).However, you shouldn't be storing passwords in plain text. You should only ever store a salted hash of the user's password,...
15 Jul 2016 by saeed rajabi
you forgot the password parameter in your connection string,PHP Prepared Statements[^]
30 Nov 2016 by Peter Leow
Look into these three points:1. What is$a = r1,r2,r3,r4;? Do you mean$a = "r1,r2,r3,r4";?2. The $xyz is assigned the tag:$xyz = "".$abc.""; which got included into the field name."CREATE TABLE $table_name". '(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY...
13 Dec 2017 by Jochen Arndt
username is a reserved SQL keyword. You should avoid using such as table or column name. To avoid the error you must quote the name or (for column names) prepend the table name: $resultX = $conn->prepare("SELECT profile_pic FROM admin_credentials WHERE admin_credentials.username=$currentuser");
18 Apr 2018 by Member 13783252
please see the below code this works fine with mysqli method but prone to sql injection so i want to use prepare but for LIKE i cant use it $t=strtolower($_POST['e']); $search_exploded = explode ( " ", $t ); $construct = ''; foreach( $search_exploded as...
11 Sep 2020 by Ameer111
I have three Tables in database. table 1 projects PK ProjectID table 2 students PK RegNo FK ProjectID table 3 progress FK RegNo Now the thing i want to perform a delete operation when i delete record from project it should be deleted from students, as students primary key is also present...
7 Jun 2018 by Richard Deeming
Option 1: Set the foreign key to cascade on delete: MySQL ON DELETE CASCADE: Deleting Data From Multiple Tables[^] Option 2: Delete the data from all related tables manually: DELETE FROM progress FROM progress INNER JOIN students ON progress.RegNo = students.RegNo WHERE students.ProjectID =...
7 Jun 2018 by Patrice T
$query = " DELETE students, progress from students inner join progress on progress.RegNo=students.RegNo where students.ProjectID='$id'; DELETE FROM projects where projects.ProjectID='$id'; "; Not a solution to your question, but another problem you have. Never build an SQL...
8 Jun 2018 by Jochen Arndt
To verify what went wrong just print the $sql string and check if it is a valid SQL command. The error is probably sourced by the missing space before the WHERE keyword. So change that to $sql ="Update ".$table." SET ".$values." WHERE id=:id"; // Insert space here ^ Other...
17 Sep 2018 by Kenjiro Aikawa
Hi! I'm trying to retrieve data from database using two datetimepicker but when set date rage to the datetimepicker and I click button all the data are displaying. Below are my whole codes. Please help me. Thank you so much in advance. What I have tried: index.php ...
21 Dec 2018 by Member 14093672
Hi Everyone, Just wondering if I am doing it right or the PHP pdo code below can be optimized? Forgot to mentioned i used stripslashes and bind param now.. is it safe now from sql injection? please feel free to comment for any better optimization. What I have tried: // Secure and sanitize...
20 Dec 2018 by Patrice T
/ Prepare Limit Clause from start to end$sqlAll=("SELECT * FROM user_details ORDER BY user_id DESC LIMIT $start, $end "); ... // Select results $data = $db_con->query("SELECT * FROM user_details ORDER BY user_id DESC LIMIT $start, $end ")->fetchAll(); Not necessary a solution to your question,...
20 Dec 2018 by MadMyche
Possibly. Unless you absolutely need to SELECT *, it is better to call only the needed columns. Example: SELECT TableID, Column1, Column2 FROM ... Besides eliminating the extra load of bundling the data together, there is less network usage and will use less memory in your calling application. ...
21 Dec 2018 by Member 14093672
Thank you MadMyche, the only thing left is now to transfer the query with PDO param substitution? Anyone around to advise how to use PARAM binding in the above query please. Here what i got and definately it would be helpful for others. please vote if BINDING below is helpful to you. $stmt =...
27 Dec 2018 by Member 14093672
Hi Everone, my PDO script not retrieving any result neither showing any errors. Please can someone guide me as to what the mistake I am doing here? My DB Connection file, no errors at all?
27 Dec 2018 by Member 14093672
issue resolved by changing - using developer tools and changing the value as follows: "emp_no"=>$row['emp_name'], to "emp_no"=>$row['emp_no'], Any suggestions in improving the above code would be grateful.
27 Dec 2018 by Patrice T
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone. A single quote in a name and your program crash. If a user input a name like...
27 Dec 2018 by Member 14093672
Hi Everyone, To my next question, PDO bindparam is showing an error: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use...
9 Jan 2019 by Member 14093672
Hi Everyone, Any suggestion to improve the class below? Note: it works fine but need some expert advise to make is free from sql injection. What I have tried:
9 Jan 2019 by CPallini
I guess someone had already asked that: mysql - How can I prevent SQL injection in PHP? - Stack Overflow[^].
9 Jan 2019 by Member 14093672
Hi, Is anyone around, to give some information in regards to the difference between the two queries, pdo connection class and which is better and why? What I have tried: PDO Database Connection Class 1 class DB extends PDO { protected $db_name = "yog"; protected $db_user = "root";...
10 Jan 2019 by Mohibur Rashid
Walaikum Salam. It seems, you have removed extension from the second class. Now Second class look ok. Which one you will use depends on your approach. But second class has a variable $db; which is not private. Can be modified out side of the class, and at the beginning of the class you are...
28 Jan 2019 by TheBigBearNow
Hello all, I have a working mysql database with my PHP code. I can create a new row and delete a row BUT when I click the btn delete the page just continually keeps loading and never goes to my header(). For my create btn the page does the same thing just keeps Is PDO one of the best phps to...
30 Jan 2019 by Member 14093672
Hi Everyone, Just wondering if anyone can shed some light and direction to make this pdo class works and sanitize data. The first part of the code works fine DB extend PDO, but the delete function doesnt work and i would like the delete function to sanitize the data before it performs the...
27 Jun 2019 by Member 14513655
I'm setting up a directory page that displays different workouts depending on what is searched through a text field(which works) and/or checkboxes(Doesn't work) I don't know if it's possible without a submit button but I would like it to search for items as well as letting it search for...
27 Jun 2019 by Wonderlawn Artificial Grass
PDO statement seems correct. Are the fields correct in your MySQL DB?
19 Aug 2019 by Member 14529192
I have a problem. why do I get this error. others are running but last 2 is not. First is working but last is not working. I did ctrl+c and ctrl+v. if(isset($_POST['apiayarkaydet'])){ $apiayarkaydet =$db->prepare("UPDATE ayar SET ayar_recapctha =:recapctha,...
19 Aug 2019 by rinave
You need to declared first for :facebook things create your function if using class like public function bind($param, $value, $type = null){ if (is_null($type)) { switch (true) { case is_int($value): $type = PDO::PARAM_INT; ...
28 Dec 2019 by Jassim Rahma
Hi, I am getting General Error but can't find the reason. The error I am getting is: PDOException: SQLSTATE[HY000]: General error in /home/domain.com/api/signin.php:40 Stack trace: #0 /home/domain.com/api/signin.php(40): PDOStatement->fetch() #1 {main}Connection failed: SQLSTATE[HY000]:...
5 Apr 2020 by MohammedZr
i'm using pdo to insert images from a database to a bootstrap carousel by that i mean ( loading The image path ) but the problem is when i use fetchall(); or fetch i get all rows value like this :- What I have tried: require_once...
21 Jul 2020 by xion360
I have a set of guns in my database Gun_1, Gun_2, Gun_3, Gun_4, Gun5, Gun_6, Gun_7 & I also have a followers table in my database of Fol_1, Fol_2, Fol_3, Fol_4, Fol_5 I'm trying to set up an attack script where it goes thru finds the highest gun...
9 Aug 2020 by OriginalGriff
Repost: deleted. Reposting the same thing over and over doesn't help you get more answers - it annoys people and that reduces the chances. Look at the responses you have so far instead.
17 Sep 2020 by danalej veinte
Soy nuevo en php, estoy tratando de agregar datos através de un formulario en Modal en php cuando le guardo me aparece este error Google translate: I am new to php, I am trying to add data through a form in Modal in php when I save it I get this...
15 Oct 2020 by nyt1972
Hello, I have a problem, that my code runs correctly, insert data to database, but the success message after lastInsertId is not working. Please help. What I have tried: if(isset($_POST['submit'])) { $class=$_POST['class'];...
15 Oct 2020 by Richard MacCutchan
Your insert most likely failed, quite possibly for the reason stated in Why do I get a "Parameter is not valid." exception when I read an image from my database?[^].
23 Jan 2021 by InnaTS
Hi guys! Thanks a lot to both of you for your help! I've used both inputs as a solution. I set parameters before binding them and it fixed everything! So strange, but everything works now. :) if(empty($new_password_err) &&...
7 Feb 2021 by InnaTS
Hello guys! I would like this form to have 3 validation levels, 2 with the codes, and one with the expiry date. I would like to delete the entry only if the token is expired. But currently it deletes the token even if it's not expired. Any...
9 Feb 2021 by Member 14649908
I am getting 0 value in below variables :- " $order_ID , $user_ID , $course_ID . When I try to debug, I always get null in these above variables. I have also started session, but still I get zero value in these variable. What I have tried: ...
28 Feb 2021 by Member 14649908
I have tried the following code but I get syntax error specially during concatination of PHP code and that of HTML markup inside the body of foreach loop.The following code snippet processes product filtering.Please help me .... What I have...
24 Apr 2021 by OriginalGriff
Not like that! There are two big problems here: 1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized...
28 Dec 2021 by Kumar Raj 2021
Hi, I need your help with this code please. I have tried a couple of things but none seem to work. I need to check that the client name from amcname input does not exist in the db. Please assist....
28 Dec 2021 by Luc Pattyn
Hmm. You switched :amcname and :amccode :)
30 Dec 2021 by Daniel Stan
$result = $stmt->fetchAll(PDO::FETCH_COLUMN); if($result) return get_item_name(explode(' ','-1','0', $result[0])); else { return 'Empty'; } Warning: explode() expects at most 3 parameters, 4 given in vault.php...
30 Dec 2021 by 0x01AA
Quote: Warning: explode() expects at most 3 parameters, 4 given in vault.php on line 43 Your code, 4 parameters: explode(' ','-1','0', $result[0]) vs. PHP: explode - Manual[^] 3 parameters explode(string $separator, string $string, int $limit...
5 Jan 2022 by Daniel Stan
hello, i have 2 functions, 1 is getting all numbers from a COLUMN and other function will transform numbers from COLUMN to NAME The problem is, i have to Explode COLUMN because inside i have like that SELECT NUMBERS FROM ITEMS WHERE...
5 Jan 2022 by _Asif_
There could be two approachs over your problem. First approach is to modify your flawed approach to the solution. Correct steps would be like. 1. Read Number columns from DB 2. Split Number column using space separator and put it into an array...
17 Jan 2022 by Kumar Raj 2021
I have the following code which for some reason does not seem to insert the data into the database. Please help: Index.php $("#insert").click(function(e) { $.ajax({ url: ["./required/orderaction.php"], type: "POST",...
11 Feb 2022 by M Imran Ansari
Look at the documentation which have necessaries files, extension and all the steps necessary for the installation of the PHP 7.3 with all extension and packages: Installing PHP 7.3 - Linux - Scriptcase Manual[^]
28 Mar 2022 by Richard MacCutchan
See PHP: SQLite3 - Manual[^] for details of using SQLite with PHP.
18 Apr 2022 by Sujan Dangol
$query2 = $dbh -> prepare("UPDATE tblpayment SET Status= 1 WHERE id='".$order['id']."'"); $query2->execute(); What I have tried: $status="1" $query2 = $dbh -> prepare("UPDATE tblpayment SET Status=:status WHERE id='".$order['id']."'");...
18 Apr 2022 by Luc Pattyn
Assuming your id field is numeric: SQL isn't HTML numeric literals don't take quotes. PS: you wouldn't have ran into this problem if you had used a parameterized query!
15 Feb 2023 by OriginalGriff
This is the same question you posted yesterday: Reutring incorrect data from database[^] and the answer hasn't changed: you need to use the debugger to find out exactly what is in the DB and how that differs from what your code expects. So I...
12 Mar 2023 by Gcobani Mkontwana
Hi Team I need some help, my record is not updating any new entries and this is a problem for me because the user details not submitted and saved. I need some help with my code below What I have tried: require_once 'db_conn.php'; // Start a...
31 Mar 2023 by Member 4206974
A PHP class that uses PDO for creating a table from JSON Objects
21 Jul 2020 by Richard MacCutchan
Yes, you need loops, conditional tests, classes, objects etc. But this is the Quick Answers forum, there is not the space or time to teach you all those subjects. Get hold of a book, or try the PHP Tutorial[^]
5 Sep 2018 by ZurdoDev
Parser errors means you have typed something wrong. In the first case you were missing closing parentheses. Now you are getting another error and it's for the same reason. Please take the time to review your code carefully and pay attention to what the compiler is telling you. It is...
10 Jul 2020 by lenniscata
In a nutshell, I do this by converting the image file into a base64 string, then retrieve the string and convert it from base64 to a file.
9 Aug 2020 by Richard MacCutchan
This is the same question as I want to retrieve an image from my database using PDO[^], and you still have not explained what the problem is.
8 Nov 2021 by Rellinxe Fyoni
I am building an MVC cart system. I have the MERCHANTS table and the PRODUCTS table. A merchant (store) can have one or more products, everything works fine but what I want is to display products by store, I mean to say that once a user adds, for...
5 Sep 2018 by Kenjiro Aikawa
Hi! Please help me to solve this error: Parse error: syntax error, unexpected '{' What's wrong with my code: prepare($sql); $result = $stmt->execute([$_POST['username']]); $un = $result->fetchAll(); ...
22 Apr 2019 by Member 14197794
Hey, last week me and one of my professors created a code to do an insert, giving an option for the user chose where to insert, and I want to use this code for the rest of the functions... I don't have much time, please help. CODE:
11 Feb 2022 by Member 14362033
Recently I installed php 7.3 on my linux server. Now I need to install php-odbc, php-pdo, php-xml, php-cli, php-gd, php-ldap, php-mbstring, php-myscript, php-pear-norch, Now I don't know which versions of these packages support php 7.3. How can...
1 Dec 2016 by Member 12880505
Sir,please tell how to create table using below codeWhat I have tried:$table_name = "test";$a ="r1,r2,r3,r4";$abc = (explode(",",$a));foreach($abc as $x){echo $x;$query = "CREATE TABLE $table_name". '(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, '.$x.'...
1 Dec 2016 by Member 12880505
$table_name = "test";$a ="r1,r2,r3,r4"; i want to explode this $products = (explode(",",$a));after exploding i will get the answer asforeach($a as $x){ echo $x;}$x through these variable i want to create column in table in database.i wrote the query as...
13 Dec 2017 by Member 13573818
Hello, I am having trouble getting my script to function properly. I have written a script that is supposed to go out to the database and retrieve a profile picture based on the username of the current user. I keep getting an error. Here is the full error report from my domain host: Fatal...
8 Jun 2018 by Member 13864537
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' on line 25 any one can help please? function update($table,$data,$id){ global $conn; $resultstr = array(); foreach ($data as $keys => $value) { ...
17 Sep 2018 by Kenjiro Aikawa
I'm trying to login using hash password that save to my database but It won't redirect to my main page which is the main.php even though I input the correct password. Please help me, I'm stock here for two days. Below is my code:
7 Sep 2018 by Kenjiro Aikawa
Hi! I have created a login form with hashing but when I try to login it always return true even I input a wrong password. Below is my code.
17 Sep 2018 by Kenjiro Aikawa
?php //error_reporting(0); session_start(); require "{$_SERVER['DOCUMENT_ROOT']}/php/connection/db_connection.php"; $userid = $_POST['userid']; $password = $_POST['password']; $stmt = $db->prepare("SELECT * FROM tbl_user WHERE userid=:userid LIMIT 1"); $stmt->bindValue(':userid', $userid,...
4 Jul 2020 by Ibrahim Hassan 1234
prepare("UPDATE tb set fname=:fname, sname=:sname, lname=:lname, pNo=:pNo, mNo=:mNo, Entry=:Entry, Faculty=:Faculty, Department=:Department, Session_Year:Session_Year, mstatus=:mstatus, gender=:gender, dob=:dob, State=:State, lga=:lga,...
9 Aug 2020 by Ibrahim Hassan 1234
prepare("SELECT * from tb where pNo=:pNo"); $stm->bindParam('pNo',$pNo); $stm->execute(); $stm->fetch(PDO::FETCH_ASSOC); while ($row = $stm->fetch() ){ echo ""; } What I have tried: im try to display my image that i already save...
9 Aug 2020 by Ibrahim Hassan 1234
Notice: Undefined index: img in C:\wamp\www\Criminal Record System\officer_reg.php on line 16 /////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\ var_dump Information Bellow:: array 'img' => string 'my passport.jpg' (length=15) ...
9 Aug 2020 by Ibrahim Hassan 1234
$sql = "select * from oficers_tbl"; $stmt = $con->prepare($sql); $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_ASSOC); while ($row = $stmt->fetch()){ echo""; What I have tried: i want to retrieve an image from...
16 Oct 2020 by Member 11241887
why did my image column in phpmyadmin database is not inserting the filename of the image i inserted but instead it displays [BLOB - 10 B]? and when i'm trying to retrieve or display the inserted image, it displays a blank square box and not the...
27 Oct 2020 by Ibrahim Hassan 1234
$sql = ("UPDATE member_registration SET...
23 Jan 2021 by InnaTS
Hi everyone. I've run into a problem with updating of my table. I keep getting Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in on the line, where I try...
24 Apr 2021 by mael_baslote
What I want is when a new teacher is added, it will create a table in the database with the name $param_subject1. It does create the table but I also want to insert the information of the new teacher in that created table. try{ ...
13 Oct 2021 by Ibrahim Hassan 1234
Notice: Undefined index: passpor in C:\wamp64\www\MSSN PORTAL\MemregisterExec.php on line 22 BELLOW IS THE VARDUMP RESULT 'passpor' => string '58.jpg' (length=6) 'fname' => string '' (length=0) 'sname' => string '' (length=0) 'oname' =>...
8 Nov 2021 by Rellinxe Fyoni
UPDATES After some days of brainstorming, this is what I have come out with but doesn't display well HTML ouput function buildUserCartDisplay($itemsInCart) { // Here's how you track if you need the header $lastMerchantID = -3 ; $html = '';...
28 Mar 2022 by NOOR HOMAD
hi ,I am beginner in programming and I need a code to do the php and sqlite connection and sign up and log in page please . any help? thank you What I have tried: lots of different things but I haven't reached any success
9 Dec 2021 by User-15261030
This is my database table | id| category| parent_id| |:---- |:------:| -----:| | 1| category1| | | 2| category2| | | 3| category3| | | 4| subcategory4| 2 | | 5| subcategory5| 1 | | 6| subcategory6| 3 | | 7| subcategory7| 1 | My expected...
29 Jan 2024 by Nicholas Lombardi
I have a form where I expect many blank input text boxes (standard html) I need to insert records, with the INSERT statement ignoring those fields which do not have input values. For context, I take the POST variables in the usual way: if...