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).
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 3 years ago.
Improve this question
I get this erro: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\PHP\tennis\ronde2-wijziging.php:59
// code van het knop wijzigen
if(isset($_POST['wijzig'])){
$id = $_POST['id'];
$speler1 = $_POST['speler1'];
$speler2 = $_POST['speler2'];
$uitslag1 = $_POST['uitslag1'];
$uitslag2 = $_POST['uitslag2'];
$datum = $_POST['datum'];
$veld = $_POST['veld'];
//UPDATE: gegevens in de form wijzigen.
$sql = "UPDATE ronde1 SET speler1 = :speler1, speler2 = :speler2, uitslag1 = :uitslag1,
uitslag2= :uitslag2, datum= :datum, veld= :veld WHERE id=:id";
$stmt = $pdoConnect->prepare($sql); //stuur naar mysql.
$stmt->bindParam(":id", $id );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":uitslag1", $uitslag1 );
$stmt->bindParam(":uitslag2", $uitslag2 );
$stmt->bindParam(":datum", $datum );
$stmt->bindParam(":veld", $veld );
$stmt->execute();
// $_SESSION['message'] = "Speler is gewijzigd";
// $_SESSION['msg_type'] = "warning";
header("location: #.php");
exit;
}
I want to update my data.strong text
My solution worked but didn't explain why it did go wrong in the first place. The user dpant explains in the comments why your code snippet was not working.
Credits go to him
dpant:
Most probably the problem with your original code was that you were binding the :speler1 parameter twice (the :speler2 parameter was never bound). This was just a typo in your code. Take a close look at it.
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 know I am doing something wrong but I really would like to know what it is. I can echo the
username of the session loggedin user using <?php echo $_SESSION['username']; ?>but I don't know why it doesn't work when I try to query database using the same technique. my codes below
I include this in the page
<?php
session_start();
$username=$_SESSION['username'];
?>
and here is the code that was suppose to display firstname and user_id of the sessions logged in user
<?php
$conn = new mysqli('localhost', 'root', 'browser', 'test');
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
$username = '$username';
$sql = "SELECT `user_id`, `firstname` FROM `members` WHERE `username`='$username'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<br /> user_id: '. $row['user_id']. ' - firstname: '. $row['firstname'];
}
}
else {
echo '0 results';
}
$conn->close();
?>
$username = '$username';
PHP variables inside single-quotes are not expanded. So now your variable is the literal string '$username', which undoubtedly won't match any user in your database.
You probably need to set $username = $_SESSION['username']; in your second PHP script.
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
EDIT/AWNSER: It was a bloody typo, dont mind me facedesking, thanks Sadikhasan
For some reason, the function mysqli_query in my code below, doesnt work, when i open the page, it returns an error.
Fatal error: Call to undefined function msqli_query() in
**/**/**/**/**db.php on line 16
I double checked the script, but couldnt find any typo's or ";" misplacements, the login part works, its purly the query that derps.
<?php
$sqlhost = '*****';
$sqlname = '*****';
$sqlpass = '*****';
$sqldbname = '*****';
$con=mysqli_connect($sqlhost,$sqlname,$sqlpass,$sqldbname);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo "connection successfull!";
}
$result = msqli_query($con,"SELECT * FROM PEOPLE");
while($row = mysqli_fetch_array($result)) {
echo $row['ID'] . "<br>";
echo $row['NAME'] . "<br>";
echo $row['AGE'] . "<br>";
echo $row['SEX'] . "<br>";
echo "<hr>";
}
mysqli_close($con);
?>
The names are in capitals in the database, i checked that too :)
thanks for the help in advance!
Correct spelling to mysqli in this line
$result = msqli_query($con,"SELECT * FROM PEOPLE");
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);
}
?>