mysqli

PHP login form returning error

时光总嘲笑我的痴心妄想 提交于 2019-12-31 07:41:49
问题 I have created a login script below, however I have been told to use prepared statements <?php require '../php/connect.php'; if(isset($_POST['login'])){ $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); $select_user = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; $run_user = mysqli_query($con, $select_user); $check_user = mysqli_num_rows($run_user); if($check_user>0){ header(

PHP login form returning error

风流意气都作罢 提交于 2019-12-31 07:41:25
问题 I have created a login script below, however I have been told to use prepared statements <?php require '../php/connect.php'; if(isset($_POST['login'])){ $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); $select_user = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; $run_user = mysqli_query($con, $select_user); $check_user = mysqli_num_rows($run_user); if($check_user>0){ header(

mysqli_select_db() expects parameter 1 to be mysqli on line 8

自古美人都是妖i 提交于 2019-12-31 07:39:22
问题 I Don't know what actually I should do and if there is something wrong somebody please correct it and give it thanks in advance <?php $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_name = 'cms'; $conn = mysqli_connect($db_host,$db_user,$db_pass) or die(mysql_error()); mysqli_select_db($db_name,$conn); ?> 回答1: Use this: $con = mysqli_connect($hostname,$user,$password,$database); You don't need: mysqli_select_db Your code will be: $db_host = 'localhost'; $db_user = 'root'; $db

PHP, MySQL: can't explain this undefined index error

冷暖自知 提交于 2019-12-31 06:37:27
问题 I'm getting an undefined index error with this code: // Select all bookings $sql = "SELECT * FROM booking"; $result = mysqli_query($con,$sql); echo "<p>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { // echo $row['custName'] . " - " . $row['roomNb'] . " - " . $row['date']; echo $row['custName']; } Error: Notice: Undefined index: custName in C:\xampp\htdocs\alxbook\index.php on line 40 I'm selecting all columns from my table. I have no problem with $row['roomNb'] and $row['date']

PHP, MySQL: can't explain this undefined index error

吃可爱长大的小学妹 提交于 2019-12-31 06:37:20
问题 I'm getting an undefined index error with this code: // Select all bookings $sql = "SELECT * FROM booking"; $result = mysqli_query($con,$sql); echo "<p>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { // echo $row['custName'] . " - " . $row['roomNb'] . " - " . $row['date']; echo $row['custName']; } Error: Notice: Undefined index: custName in C:\xampp\htdocs\alxbook\index.php on line 40 I'm selecting all columns from my table. I have no problem with $row['roomNb'] and $row['date']

PHP, MySQL: can't explain this undefined index error

隐身守侯 提交于 2019-12-31 06:37:09
问题 I'm getting an undefined index error with this code: // Select all bookings $sql = "SELECT * FROM booking"; $result = mysqli_query($con,$sql); echo "<p>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { // echo $row['custName'] . " - " . $row['roomNb'] . " - " . $row['date']; echo $row['custName']; } Error: Notice: Undefined index: custName in C:\xampp\htdocs\alxbook\index.php on line 40 I'm selecting all columns from my table. I have no problem with $row['roomNb'] and $row['date']

PHP is not working on server

南笙酒味 提交于 2019-12-31 06:04:53
问题 I bought hosting service tomorrow and from yesterday I am trying to solve problems. Problem is that PHP is not working on this server I don't know what is wrong first I used this code to connect to database <?php Create connection $con=mysqli_connect("localhost","user","pass","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { echo "Connected"; } ?> It show me blank page when I upload it to server using ftp if I

Ajax call with PHP / MySQLi query returning wrong results [duplicate]

邮差的信 提交于 2019-12-31 05:50:29
问题 This question already has an answer here : PHP $stmt->num_rows doesnt work by prepared statements [duplicate] (1 answer) Closed 2 months ago . I am trying to check if an input value already exists in my database. So far I got the following but this always returns me "Invalid" (even if I enter a matching value) so my guess is I have an error in the part after my SELECT query or in my If Else logic. Can someone tell me how to do this right? My JS: $('#btnCheck').click(function() { var username

PHP, SQL limit query by php variable

自闭症网瘾萝莉.ら 提交于 2019-12-31 05:38:16
问题 PHP code defining variable sqlshowvalue $sqlshowvalue = 5; if(isset($_POST['showmore'])) { $sqlshowvalue += 5; } So I connect to my database and then when I run this SQL query below using the variable that I just defined above, $result = mysqli_query($conn,"SELECT * FROM comments ORDER BY id DESC limit '$sqlshowvalue'"); So I am using mysqli as the method to connect to my DB and it gives me the following error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean

Why do I get “Only variables should be passed by reference” in a prepared statement

那年仲夏 提交于 2019-12-31 05:29:06
问题 I am getting the error "Only variables should be passed by reference" if my code is like this. $query = "SELECT COUNT(`user_id`) FROM `test` WHERE `username` = ? AND `active` = ?"; $stmt = $this->db->prepare($query); $stmt->bind_param('si',$username,$active=1); $stmt->execute(); $stmt->bind_result($count); if($stmt->fetch()){} return ($count == 1) ? true : false; However if I do it this way $query = "SELECT COUNT(`user_id`) FROM `test` WHERE `username` = ? AND `active` = ?"; $active=1 $stmt =