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 6 years ago.
I'm doing project and it needs android-PHP-MySQL connection.
I programmed PHP code, but it doesn't work. The error code says 'Undefined index: userId...'
I don't know how to solve it. I googled for get some solutions but I couldn't find the right answer. Other PHP code with another android project is working. Why..?
Following is My PHP code.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require "init.php";
$userId = $_POST["userId"];
$username = $_POST["username"];
$userphone = $_POST["userphone"];
$usermail = $_POST["usermail"];
$userpw = $_POST["userpw"];
$sql = "INSERT INTO register_info VALUES ('$userId', '$username', '$userphone', '$usermail', '$userpw' );";
if(mysqli_query($con, $sql))
{
var_dump($userId,$username,$userphone,$usermail, $userpw );
}
?>
And this is the error code.
Notice: Undefined index: userId in /var/www/html/website/web/webapp/insertUser.php on line 9
Notice: Undefined index: username in /var/www/html/website/web/webapp/insertUser.php on line 10
Notice: Undefined index: userphone in /var/www/html/website/web/webapp/insertUser.php on line 11
Notice: Undefined index: usermail in /var/www/html/website/web/webapp/insertUser.php on line 12
Notice: Undefined index: userpw in /var/www/html/website/web/webapp/insertUser.php on line 13
string(0) "" string(0) "" string(0) "" string(0) "" string(0) ""
Query mysql have solution.
try
$sql = "INSERT INTO register_info (userId, username, userphone, usermail, userpw) VALUES ('$userId', '$username', '$userphone', '$usermail', '$userpw' );";
or see
https://www.w3schools.com/php/php_mysql_insert.asp
Related
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);
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
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.
I've got this error. I thought it's on misplaced of ' the $_POST, but if I do that (eg $_POST['regno']) it will give T_ESCAPED error.
How I can fix this?
Here is the code of line 33:
$sql = "SELECT * FROM students WHERE RegNo='$_POST[regno]' AND
password='$_POST[password]' AND Status='Enabled'";
I'm using Wamp as my localhost.
Thanks!
You need to check the post value like this
$reg_no = isset($_POST['regno']) ? $_POST['regno'] : '';
$sql = "SELECT * FROM students WHERE RegNo='".$reg_no."' AND password='".$_POST['password']."' AND Status='Enabled'";
First be sure that your variables exists before trying to save them :
<?php
if(isset($_POST['regno']) && !empty($_POST['regno'])){
$regno =$_POST['regno'];
}
if(isset($_POST['password']) && !empty($_POST['password'])){
$password =$_POST['password'];
}
if(isset($password) && isset($regno)){
$sql = "SELECT * FROM students WHERE RegNo='$regno' AND password='$password' AND Status='Enabled'";
}
?>
Also keep in mind that using POST var like this is very exposed to SQL injections.
try this :
$sql = "SELECT * FROM students WHERE RegNo='".$_POST['regno']."' AND password='".$_POST['password']."' AND Status='Enabled'";
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.
Here is the php connectivity code:
<?php
$con=mysql_connect("127.0.0.1", "root", "");
mysql_select_db("society");
if(!$con)
{
echo "Failed to Connect to MySql".mysqli_connect_error();
}
else
{
echo"success";
}
$query="INSERT INTO users (fname, lname, email, password)
VALUES('".$_POST['fname']."','".$_POST['lname']."','".$_POST['email']."','".$_POST['password']."')";
mysql_query($query,$con);
?>
This is the error. Tried, but I am not able to solve the error:
Notice: Undefined index: fname in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\scripts\html\connect.php on line 13
Notice: Undefined index: lname in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\scripts\html\connect.php on line 13
Notice: Undefined index: email in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\scripts\html\connect.php on line 13
Notice: Undefined index: password in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\scripts\html\connect.php on line 13
Try this
<?php
$con=mysql_connect("127.0.0.1", "root", "");
mysql_select_db("society");
if(!$con)
{
echo "Failed to Connect to MySql".mysql_connect_error();
}
else
{
echo"success";
}
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email'])) {
$query="INSERT INTO users (fname, lname, email, password)
VALUES('".$_POST['fname']."','".$_POST['lname']."','".$_POST['email']."','".$_POST['password']."')";
mysql_query($query,$con);
}
?>
Check if there is values for the POST your using in the query. If it is returning undefined_index is because the variables of the post that you are using isn't set. They don't even exist at the moment.
For instance:
If you debug $_POST['fname'] it will return false or empty. Try it.
Resolution:
Right now I think you're running this code without validating if the form has been submited or not.
So, to start you should do this:
if(isset($_POST) && count($_POST) > 0){
$con=mysql_connect("127.0.0.1", "root", "");
mysql_select_db("society");
if(!$con)
{
echo "Failed to Connect to MySql".mysqli_connect_error();
}
else
{
echo"success";
}
$query="INSERT INTO users (fname, lname, email, password) VALUES('".$_POST['fname']."','".$_POST['lname']."','".$_POST['email']."','".$_POST['password']."')";
mysql_query($query,$con);
}
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