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;
}
Related
This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 3 years ago.
I can't insert the registration form data into my localhost database.
I am using xampp server, running mysql 5, php 7 and apache2. I've provided the code that can insert the form data into the database. The database is connected. I have also restarted the xampp server but it shows the same problem.
<?php
$active='Account';
include("includes/header.php");
?>
//html form with correct name values
<?php
if(isset($_POST['register'])){
$c_name = $_POST['c_name'];
$c_email = $_POST['c_email'];
$c_pass = $_POST['c_pass'];
$c_country = $_POST['c_country'];
$c_city = $_POST['c_city'];
$c_contact = $_POST['c_contact'];
$c_address = $_POST['c_address'];
$c_image = $_FILES['c_image']['name'];
$c_image_tmp = $_FILES['c_image']['tmp_name'];
move_uploaded_file($c_image_tmp,"customer/customer_images/$c_image");
$insert_customer = "insert into customers (customer_name,customer_email,customer_pass,customer_country,customer_city,customer_contact,customer_address,customer_image,customer_ip) values ('$c_name','$c_email','$c_pass','$c_country','$c_city','$c_contact','$c_address','$c_image','$c_ip')";
$result = mysqli_query($con,$insert_customer);
$sel_cart = "select * from cart where ip_add='$c_ip'";
$run_cart = mysqli_query($con,$sel_cart);
$check_cart = mysqli_num_rows($run_cart);
if($check_cart>0){
$_SESSION['customer_email']=$c_email;
echo "<script>alert('User is already present');</script>";
echo "<script>window.open('checkout.php','_self')</script>";
}else{
$_SESSION['customer_email']=$c_email;
echo "<script>alert('You have been Registered Sucessfully')</script>";
echo "<script>window.open('index.php','_self')</script>";
}
}
?>
The data should be inserted into the db when I refresh the phpmyadmin page.
Check $con variable where you define. Connection variable should be define on page and call with mysqli function.
$result = mysqli_query($con,$insert_customer);
This question already has answers here:
php warning: mysqli_close() expects parameter 1 to be mysqli
(2 answers)
Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?
(3 answers)
Closed 5 years ago.
I am working on android app project and in this project, i need to connect my android app with PHP and MySQL everything is fine but I am getting an error in my user registration .php file error like this
Warning: mysqli_close() expects parameter 1 to be myself, null given
in C:\xampp\htdocs\panel\UserRegistration.php on line 35
I have tried many things but the error is still there.
Here is what I have tried:
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$id_name = $_POST['id'];
$U_name = $_POST['username'];
$password = $_POST['password'];
$cnic = $_POST['cnic'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$CheckSQL = "SELECT * FROM Users WHERE email='$email'";
$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
if(isset($check)){
echo 'Email Already Exist';
}
else{
$Sql_Query = "INSERT INTO Users (id,username,email,password_cnic,phone) values ('$id','$U_name','$email','$password','$cnic','$phone')";
if(mysqli_query($con,$Sql_Query))
{
echo 'Registration Successfully';
}
}
?>
https://secure.php.net/manual/fr/mysqli.close.php
You must do : mysqli_close($con);
:)
Pass Connection object in mysqli_close() function.
Like :
mysqli_close($con);
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>
?>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 6 years ago.
my code is
$query1 = "SELECT `user_id` FROM `it_user` WHERE (user_email_address = ? AND user_mobile_number_verified = NULL)";
$stmt1 = $mysqli->prepare($query1);
$stmt1->bind_param("s",$email);
$stmt1->execute();
if ($stmt1->affected_rows == 1) {
//set registration flag to 1 stating that the users mobile number is already verified
echo '<meta http-equiv="refresh" content="0; URL=\'../signin/\'"/>';
}
else
{
$registration_flag = 2;
//redirect user to error page
//echo '<meta http-equiv="refresh" content="0; URL=\'../error/\'"/>';
}
i am getting this error ::
Call to a member function bind_param() on a non-object in ***** on line 62
where as my email variable is working corrrect and also the query.
Use NULL safe operator and write code as below:-
$mobile = NULL; // NOTE: no quotes - using php NULL
$query1 = "SELECT `user_id` FROM `it_user` WHERE user_email_address = ? AND user_mobile_number_verified <=> ?";
$stmt1 = $mysqli->prepare($query1);
$stmt1->bind_param("s",$email);
$stmt1->bind_param($mobile);
$stmt1->execute();
Hope it will help you :-)
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 8 years ago.
I am trying redirect user when login successfully but I am getting error on entering wrong username and password and also redirection not working. If I insert valid username and password works great.
Error:
Notice: Undefined offset: 0 in /var/sites/l/example.com/public_html/demo/sitename/application/models/loginmodel.php on line 70
Notice: Trying to get property of non-object in /var/sites/l/example.com/public_html/demo/sitename/application/models/loginmodel.php on line 70
Warning: Cannot modify header information - headers already sent by (output started at /var/sites/l/example.com/public_html/demo/sitename/application/models/loginmodel.php:70) in /var/sites/l/example.com/public_html/demo/sitename/application/models/loginmodel.php on line 82
My Code:
session_start();
$username = strip_tags($username);
$password = strip_tags($password);
$sql = "SELECT id FROM users WHERE name='$username' and password='$password'";
$query = $this->db->prepare($sql);
$query->execute();
$records = $query->fetchAll();
$ck_userID = $records[0]->id;
//$active=$row['active'];
// echo "<pre>";
// print_r($ck_userID);
// echo "</pre>";
// die;
if ( count($ck_userID) > 0 ){
$_SESSION['login_user']=$username;
header('location: ' . URL . 'admin');
}else{
header('location: ' . URL . 'login?invalid');
}
Change
$ck_userID = $records[0]->id;
to
$ck_userID = isset($records[0]) && is_object($records[0]) ? $records[0]->id : null;
Explanation:
You have to check whethe $records[0] does exist and you should check whether it's an object (so it's not false or null).
Also care for SQL injection. You are using some kind of prepare method, but you don't prepare anything.
Another bad practice is header sending location change but no exit following.
Header start with a capital letter, location: -> Location:.
change
$records = $query->fetchAll();
$ck_userID = $records[0]->id;
if ( count($ck_userID) > 0 ){
to
$records = $query->fetchAll();
if ( count($records) > 0 ){
NOTE: your code is vulnerable to sql injections