This question already has answers here:
'fetch' in PDO gets only one result [duplicate]
(6 answers)
PDO::FETCH_ASSOC not fetching everything
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I have database with five projects added by username. When I want to get project by user returns me only one project.
<?php
require_once("db.php");
$db = DB();
$query = $db->prepare("SELECT * FROM projects WHERE username='$username'");
$query->execute();
$row = $query->fetch();
$name = $row['name'];
$project = $row['project'];
echo "<p>Project name: $name</p>
<p>Project: $project</p>
?>
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Why does this PDO statement silently fail?
(2 answers)
Closed 11 months ago.
This post was edited and submitted for review 11 months ago and failed to reopen the post:
Duplicate This question has been answered, is not unique, and doesn’t differentiate itself from another question.
I have this warning, how do I fix it?
Notice: Trying to access array offset on value of type bool in C:\Program Files\Ampps\www\NodeMCU\read tag user data.php on line 17
Code
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM tb_nodemcu where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
Database::disconnect();
$msg = null;
if (null==$data['name']) {
$msg = "The ID of your Card / KeyChain is not registered !!!";
$data['id']=$id;
$data['name']="--------";
$data['gender']="--------";
$data['email']="--------";
$data['mobile']="--------";
} else {
$msg = null;
}
This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
How can I with mysqli make a query with LIKE and get all results?
(2 answers)
Closed 2 years ago.
I have created a PHP and SQLi based search system. It is very basic and works how all of the ones I have found have. I just have one question. Can a very mean and angry person SQL inject my search system. The search is submitted through an HTML form in POST.
Search System Code
...
require 'includes/dbh.inc.php';
$search = $_POST['search'];
$mysqli = $conn;
$query = "SELECT * FROM listings WHERE listing_name LIKE '%".$search."%'";
echo '<b> <center class="listingstitle">Listings</center> </b> <br> <br>';
if ($result = $mysqli->query($query) and mysqli_num_rows($result) > 0) {
while ($row = $result->fetch_assoc()) {
$price = $row["listing_price"];
$name = $row["listing_name"];
$seller = $row["listing_seller"];
$picture = $row["listing_picture"];
...
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
<?php
$pdo = new PDO('mysql:host=localhost;dbname=leonzemaim', 'leonzemaim', 'leonzemaim');
$stmt = $pdo->prepare('SELECT * FROM Orders');
$stmt->execute();
?>
Hi. I try get my result in utf8 code?
Simply add ;charset=utf8 to your connection string.
$pdo = new PDO('mysql:host=localhost;dbname=leonzemaim;charset=utf8', 'leonzemaim', 'leonzemaim');
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
How can I prevent SQL injection in PHP?
(27 answers)
Closed 4 years ago.
Having trouble getting the data to insert into Maria DB. While attempting this project I have used about every source I can think of and I'm resorting to posting a question online. Below is my code and the error it produces is "Fatal error: Call to undefined method mysqli::mysqli_prepare() in C:\xampp\htdocs\scripts\insert.php on line 12". Been mulling over this for a couple days and so far I have found nothing at all on youtube or stackoverflow.
<?php
//Set up credentials
$servername = "localhost";
$username = "root";
$password = "";
$database = "test";
$db = new PDO("mysql:host=localhost;dbname=test;","$username","$password");
// Create connection
$link = new mysqli($servername,$username,$password,$database) or die($mysqli->error);
$a = $_POST["a"];
$sql = "INSERT INTO ass (asdf) VALUES('$a')";
$result = $link->mysqli_prepare($sql);
$stmt = $database->mysqli_prepare($sql);
$stmt->execute(array($_POST['a']));
$stmt->close();
?>
This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
Closed 5 years ago.
here my code called data.php
<?php
sql = db->query('SELECT* FROM tb_karyawan order by kar_id desc');
while($data = $sql->fetch(PDO::FETCH_ASSOC)){
} ?>
nilai.php?hal=tambah&kd=
and my nilai.php
<?php
$sql = $db->query('SELECT * FROM tb_karyawan WHERE kar_id=$_GET["kar_id"]) .');
$data = $sql->fetch(PDO::FETCH_ASSOC);
?>
how to get kar_id from previous page to next page by $_GET METHOD using PDO i am new for PDO
THANKS
<?php
while($data = $sql->fetch(PDO::FETCH_ASSOC)){ ?>
Link
<?php }
?>
nilai.php:
$kar_id = $_GET["kar_id"];
$sql = $db->prepare('SELECT * FROM tb_karyawan WHERE kar_id=:kar_id');
$sql->bindValue(':kar_id', $kar_id , PDO::PARAM_INT);
$sql->execute();