Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Trying to signup with new username and password and get this output - "Undefined variable: password"
<?php
require_once "lib/user_class.php";
$user = User::getObject();
if (isset($_POST["reg"])) {
$login = $_POST["login"];
$login = $_POST["password"];
$reg_success = $user->regUser($login, $password);
}
?>
There's no password variable defined, that's why it says $password is undefined.
Perhaps you meant $login = $_POST["password"]; as $password = $_POST["password"];? I'm no mind-reader, but I don't think you wanted to create duplicate variables.
The variable password is not defined..
i have edited your code.
<?php
require_once "lib/user_class.php";
$user = User::getObject();
if (isset($_POST["reg"])) {
$login= $_POST["login"];
$password= $_POST["password"];
$reg_success = $user->regUser($login, $password);
}
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am facing a problem when i am try to check user and password from database while login it keep
reply an error message :
Notice: Trying to get property 'num_row' of non-object in /Applications/XAMPP/xamppfiles/htdocs/studyact/login.php on line 27
User name or Password is incorrect, please check and try again.
i type user and password correct! enter image description here
php file :
<?php
//html
$user_staff = $_POST["user_staff"];
$pass_staff = $_POST["pass_staff"];
// Create connection
$servername = "localhost";
$username = "root";
$password = "";
$db ="studyact";
$con = new mysqli($servername, $username, $password,$db);
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}else{
$stmt =$con-> prepare("select * from loginstaff where user_staff = ?");
$stmt->bind_param("s",$user_staff);
$stmt->execute();
$stmtresult = $stmt->get_result();
if($stmtresult-> num_row > 0){
$data = $stmtresult-> fetch_assoc();
if($data["pass_staff"] === $pass_staff){
echo "<h2>Login Successfully</h2>";
}
else{
echo "<h2> Sorry User name or Password is incorrect.</h2>";
}
}else{
echo "<h2> User name or Password is incorrect, please check and try again.</h2>";
}
}
?>
You've got a typo on line 27
if($stmtresult->num_rows > 0)
mysqli_stmt::$num_rows — Returns the number of rows fetched from the server
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What's wrong with this code:
<?php
session_start();
if(!isset($_SESSION['username']) && isset($_COOKIE['username'], $_COOKIE['password']))
{
$checkQuery = "SELECT password, id FROM accounts WHERE username='".$db->real_escape_string($_COOKIE['username'])."'";
$checkResult = mysqli_query($db, $checkQuery);
$check = mysqli_fetch_array($checkResult);
if($check['password'] == $_COOKIE['password'] && mysqli_num_rows($checkQuery)>0)
{
$_SESSION['username'] = $_COOKIE['username'];
$_SESSION['userid'] = $check['id'];
}
}
?>
It shows this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
string given...
Looks like you should change
mysqli_num_rows($checkQuery)
to
mysqli_num_rows($checkResult)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have looked all over the web, checked the php syntax but I can't understand why this code is not working.
// Create connection
$con=mysqli_connect("localhost","task_user","task","tasks");
// Check connection
if (mysqli_connect_errno()) {
echo "No se puede conectar a la base de datos: " . mysqli_connect_error();
}
else{
//Verificación de la información de logeo
$username = $_POST["user"];
$username = stripslashes($username);
$password = $_POST["passwd"];
$username = $mysqli_real_escape_string($con,$username);
//$password = $mysqli_real_escape_string($password);
//$sqlquery = "SELECT username,password FROM users WHERE username ='$username' AND password='$password'";
}
echo '<script type = "text/javascript"> restoreValues("' . $_POST["user"] . '","' . $_POST["passwd"] . '"); </script>';
echo "ALL OK";
If I comment the mysqli_real_escape_string then it works (ALL OK is printed), if I don't it doesn't work. What am I doing wrong??
you are using $ sign before function mysqli_real_escape_string
make it
$username = mysqli_real_escape_string($con,$username);
instead of
$username = $mysqli_real_escape_string($con,$username);
^ remove this
You have a $ before mysql_real_escap_string, which is wrong. If you remove the $, it should work. Your version would call a function with the name defined in the variable $mysqli_real_escape_string (which does not exist in your case).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
database.php
function insert($sql){
mysqli_query($this->objDbConn, $sql);
if(mysqli_errno($this->objDbConn)){
die("Failed Query: $sql".$this->objDBConn->error);
return false;
}else{
return true;
}
}
update.php
if(isset($_POST["submit"])){
$address= $_POST['address'];
$mail= $_POST['mail'];
$user= $_POST['user'];
$password= $_POST['password'];
$sql= "UPDATE Member(Address, Mail, UserName, Password)VALUES
('$address', '$mail', '$user', '$password')";
$objdatabase->insert($sql);
echo "Update successful";
echo "<META http-equiv='refresh' content='0;URL='>";
}
that show on the url:
Notice: Trying to get property of non-object
and
Notice: Undefined property: database::$objDBConn
There is a typo, property name is case sensitive, $this->objDBConn should be $this->objDbConn.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm new at PHP and just learning.
<?php
// database connection
$dbhost = "localhost";
$dbname = "pdo";
$dbuser = "root";
$dbpass = "7777777";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
// echo from database
$select = $conn->query('SELECT username FROM users');
while($row = $select->fetch(PDO::FETCH_ASSOC))
{
$username = $_GET['username'];
echo $username;
}
?>
This gives error:
Parse error: syntax error, unexpected T_PUBLIC in line : $select = $conn->query('SELECT username FROM users');
The connection needs to be changed
From:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
To:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
The connection is missing a ;