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.
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)
The 3 different equals
(5 answers)
Closed 2 years ago.
I have this code in my login.hmtl in s section with ajax method:
$.ajax ({
type:'post',
url:'Controladores/login.php',
data:{do_login:"do_login", nick:nick, pass:pass },
success:function(response) {
alert($.trim(response));
if ($.trim(response) ==='Correcto'){
window.location.href="intranet.php?ruta=inicio";
return false;
}
else{
alert('Datos incorrectos. Volver a intentar.');
}
}
});
This redirects me to login.php where I connect to the database and then check if the username and password are correct. If they are, they return an answer Correct or Incorrect.
Here is the main part where I start my session, and also if username and password match, set the username 'NICK' to the session.
session_start();
$db = new Conexion();
$conn = $db->connect( '00.00.00.00', 'Seguridad');
$param = [$nick, $pass];
$query = "exec Seguridad.dbo.autenticacion ?, ?";
$result= $db->rows($conn, $query, $param);
$obj = json_decode($result);
//echo $obj[0]->resultado;
if( $obj[0]->resultado ='Correcto' ){
$_SESSION['nick']= $nick;
$_SESSION['nombreusuario'] = $obj[0]->nombreusuario;
$_SESSION['agencia'] = $obj[0]->CodigoAgencia;
echo ("Correcto");
}else{
if ($obj[0]->resultado =='Incorrecto'){
echo ("Incorrecto");
}
}
Then, In my home page called inicio.php I called again the session but the message is:
Notice: Undefined index: nick in C:\xampp\htdocs\intranetv3\Vistas\modulos\inicio.php on line 3
<?php
session_start();
$userName = $_SESSION['nick'];
echo "$userName";
?>
I have read other article but have not found anything.
I checked if the answer Correct or Incorrect returns the answer and it returns.
I printed the user name and password. It worked.
I also printed the $_SESSION['nick'], I see it has the username.
Apparently when I go to my inicio.hmtl the session just unssets or something, I have no idea what might be wrong. Please HELP!!
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 5 years ago.
login code
<?php
include("koneksi.php");
$email=$_POST['email'];
$password=md5($_POST['password']);
$q="SELECT * FROM `user` WHERE `user`.`email`='$email' AND `user`.`password`='$password'";
$qe=mysql_query($q);
while ($de=mysql_fetch_array($qe)) {
$id_user=$de['id_user'];
}
if (mysql_num_rows($qe)>0) {
session_start();
$_SESSION['x']=$id_users;
header('location:home.php');
exit;
} else{
header('location:login_user.php');
exit;
}
?>
after login i wanna show or echo the username with this code
<?php
session_start();
$id_user=$_SESSION['x'];
$q="SELECT * FROM `user` WHERE `user`.`id_user`='$id_user'";
$qe=mysql_query($q);
$de=mysql_fetch_array($qe);
$username=$de['username'];
echo "
<li>$username</li>
";
?>
and the problem is the username doesn't show..
whats wrong.. help me ..
You have a typo in your login search query. Change to $_SESSION['x'] = $id_user;
Not $id_users
A piece of advice, use an IDE such as netbeans or eclipse or phpstorm. They help in identifying unused variables and other minor syntax errors.
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'";