php echo json command [duplicate] - php

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
when i try to Sign up echo json commands for existing email i get this error
Use of undefined constant Email_Error - assumed 'Email_Error' (this will throw an Error in a future version of PHP) in C:\xamppnew\htdocs\android\signup.php on line 16
{"SIGNUP":"Email_Error"}
and when there is no error i get this error
Notice: Undefined variable: arr in C:\xamppnew\htdocs\android\signup.php on line 23
null
php code
<?php
include "conn.php";
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$Email = $_POST['Email'];
$Password = $_POST['Password'];
$sql_verify = "SELECT * FROM users WHERE Email = :EMAIL";
$stmt = $PDO->prepare($sql_verify);
$stmt->bindParam(':EMAIL', $Email);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$arr = array( 'SIGNUP' => Email_Error);
}else{
echo "Signup compelete";
}
echo json_encode($arr);
?>
note im following php manual for json

Related

How to solve this error Undefined index: password in on line [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed last year.
Undefined index: password in on line
: Cannot modify header information - headers already sent by (output started at /storage/ssd4/628/18415628/public_html/Kunj/admin/index.php:8) in on line
: Cannot modify header information - headers already sent by (output started at /storage/ssd4/628/18415628/public_html/Kunj/admin/index.php:8) in on line
Not Access!
This error comes from this code
<?php
session_start();
require_once('functions.php');
require_once('dbconnection.php');
require_once('includes/init.php');
$password = $_SESSION['password'];
$admin_data = get_admin($conn, $password);
if ($password != $admin_data['password']) {
header('location: login.php');
Change this line
$password = $_SESSION['password'];
to
if(isset($_SESSION['password'])){
$password = $_SESSION['password'];
}else{
$password = '';
}

How can I fix an undefined index? [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 3 years ago.
I am connected to my local host and am trying to use a GET method on line $. I am getting the Notice: Undefined index: deleteid in C:\xampp\htdocs\webd153\delete.php on line 4.
<?php
include 'connection.php';
$deleteid = $_GET['deleteid'];
if (isset($deleteid)) {
$deletesql = $dbh->prepare("DELETE FROM users WHERE id = '$deleteid'");
$deletesql->execure();
echo "record has been deleted!<br>";
I am trying to delete names that I have entered in my databases using a form that is connected from my local host to myphpadmin database.
Right way is:
<?php
include 'connection.php';
if(isset($_GET['deleteid']) {
$deleteid = $_GET['deleteid'];
$deletesql = $dbh->prepare("DELETE FROM users WHERE id = '$deleteid'");
$deletesql->execute();
echo "record has been deleted!<br>";
}
But this is VERY INSECURE! When I send request with URL ending ?deleteid=1'+OR+1=1+OR+id=', your database will be deleted all rows. I suggest to change query building as:
$deletesql = $dbh->prepare("DELETE FROM users WHERE id = (?)");
$deletesql->bind_param('i', $deleteid);

Notice: Undefined index: namaunit [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
I'm new in programming, and i don't know why it doesn't work. I use the same code for my other input form, and that code work just fine. But, for this form, it's not. The form is pretty much same, so, that's why i totally do not understand why it's not working.
This is the php code where the message error come from. I wish you can help me. Thank you so much.
<?php
session_start();
require 'db.php';
$kodeunit = $_SESSION["KodeUnit"];
$namaunit = $_POST['namaunit'];
$alamat = $_POST['alamat'];
$pimpinanunit = $_POST['pimpinanunit'];
$kuasaanggaran = $_POST['kuasaanggaran'];
$pembuatkomitmen = $_POST['pembuatkomitmen'];
$penanggungjawab = $_POST['penanggungjawab'];
$sql = "UPDATE unit_organisasi SET Nama_Unit = '$namaunit', Pimpinan_Unit = '$pimpinanunit', Alamat = '$alamat', Kuasa_Anggaran = '$kuasaanggaran', Pembuat_Komitment = '$pembuatkomitmen', Penanggungjawab = '$penanggungjawab' WHERE Kode_Unit = '$kodeunit'";
if((!strlen(trim($namaunit))) || (!strlen(trim($alamat))) || (!strlen(trim($pimpinanunit))) || (!strlen(trim($kuasaanggaran))) || (!strlen(trim($pembuatkomitmen))) || (!strlen(trim($penanggungjawab)))){
echo "<script>alert('Data Belum Lengkap!')</script>";
header ('Location:inpudataunit.php');
}
else{
$result = $conn->query($sql);
if($result === TRUE){
echo "Berhasil diinput";
}
}
?>
Seems like your form has no input field named namaunit . Check your form input name.

Return SQL query errors in PHP file [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
UPD: CLOSED. Duplicate found and typos in my original question
I am using this code and I want to get a message if there is an error with my SQL query :
$Db = mysqli_init();
$Db->options(MYSQLI_OPT_LOCAL_INFILE, true);
$Db->real_connect($servername, $username, $password, $dbname, 3306);
// Creation of first SQL query
$sql = ('select sum('.$metric1.') as t1metric from '.$table1.' WHERE '.$date1.' between "'.$start_date.'" AND "'.$end_date.'"');
$query = $Db->query($sql);
if ($Db->error)
{
printf("Errormessage: %s\n", $Db->error);
}
and I receive this error when I run the php file :
Call to a member function query() on a non-object
use the following
$Db->query($sql);
instead of
$mysqli->query($query);
$mysqli->query($query);
Replace with:
$Db->query($query);

Notice: Undefined index: $username [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
Hello i'm new to php and i wanted to create a admin panel and i got an error with my register page.
This is the error :
Notice: Undefined index: username in C:\wamp\www\Website2 - Copy\register.php on line 18
if (isset($_POST['submit'])){
$username = $_POST['username']; // error here
$password = md5($_POST['password']);
if(empty($username)or empty($password)){
echo"There is an empty space";
}else{
mysql_query("INSERT INTO users VALUES('', '$username', '$password')");
}
}
This happens because the empty function checks if the variables $username and $password has no value or set equal to zero. (0, null, false,''). As the empty function does not check if the variable exists, php throws this error.
In this case it would be correct to use the isset function of php.
http://br1.php.net/isset

Categories