Uncaught Error: Call to a member function bind_param() on null
please help me out with this error
Call to a member function bind_param() on null
anytime i try to run it on my localhost it says
Warning: Undefined variable $stm in C:\xampp\htdocs\pmlc\cryptedlogin\login.php on line 11
and also says
Fatal error: Uncaught Error: Call to a member function bind_param() on null in C:\xampp\htdocs\pmlc\cryptedlogin\login.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\pmlc\cryptedlogin\login.php on line 11
my code is
<?php
$username = $_POST['username'];
$password = $_POST['password'];
//database connection here
$con = new mysqli("localhost","root","","demo");
if($con->connect_error){
die("faild to connect: ".$con->connect_error);
}else {
$stmt = $con->prepare("select *from loginform where username =?");
$stm->bind_param("s", $username);
$stmt->execute();
$stmt_result = $stmt->get_result();
if($stmt_result->num_row > 0){
$data = $stmt_result->fetch_assoc();
if ($data['password']=== $password) {
echo "<h2>Login successfully</h2>";
}else {
echo "<h2>invalid email or password</h2>";
}
}else {
echo "<h2>invalid email or password</h2>";
}
}
?>
do you know?
how many words do you know
See also questions close to this topic
-
How to upload a video using ACF in WordPress?
I am still at learning phase in WordPress. I cannot figure out in ACF which field type should I choose to upload a video file and which code should I write to show it at the front-end. Please look into the below code. I am using the_field('') but it isn't working. Can anyone help
<video width="954" height="535" controls class="tm-mb-40"> <source src="video/wheat-field.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
-
delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear'); return redirect('/');
});
. i also try public function dd()
{ Schema::drop('table_name'); }
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
table_name
)no foreign key for the table . what should i do ?
thanks in advance!
-
Creating Sticky Navbar with Drop Down Menu HTML
I am creating a HTML web page which contains a sticky navbar with drop down menu. However, when I created one, the dropdown menu does not works in the sticky navbar and so goes vise versa. below is the screenshot of both the result of the two codes.
*image with dropdown menu but without sticky navbar
*image with sticky navbar but without dropdown menu
below is the code for "image with dropdown menu but without sticky navbar"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body {margin:0;font-family:Arial} .topnav { overflow: hidden; background-color: #333; } .topnav a { list-style-type: none; float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; position: sticky; } .active { background-color: #04AA6D; color: white; } .topnav .icon { display: none; } .dropdown { float: left; overflow: hidden; } .dropdown .dropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: inherit; font-family: inherit; margin: 0; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { float: none; color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .topnav a:hover, .dropdown:hover .dropbtn { background-color: #555; color: white; } .dropdown-content a:hover { background-color: #ddd; color: black; } .dropdown:hover .dropdown-content { display: block; } @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } .topnav.responsive .dropdown {float: none;} .topnav.responsive .dropdown-content {position: relative;} .topnav.responsive .dropdown .dropbtn { display: block; width: 100%; text-align: left; } } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <div class="topnav" id="myTopnav"> <a href="#home" class="active">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <div class="dropdown"> <button class="dropbtn">Dropdown <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <a href="#about">About</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a> </div> <div style="padding-left:16px"> <h2>Responsive Topnav with Dropdown</h2> <p>Resize the browser window to see how it works.</p> <p>Hover over the dropdown button to open the dropdown menu.</p> </div> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <script> function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } </script> </body> </html>
below is the code for "image with sticky navbar but without dropdown menu"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body { font-size: 20px; } body {margin:0;} ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; position: -webkit-sticky; /* Safari */ position: sticky; top: 0; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 16px 20px; text-decoration: none; } li a:hover { background-color: #111; } /*======================================================================*/ body { background-color:white; } ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #38444d; } li { float: left; } li a, .dropbtn { display: inline-block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover, .dropdown:hover .dropbtn { background-color: red; } li.dropdown { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover {background-color: #f1f1f1;} .dropdown:hover .dropdown-content { display: block; } footer { text-align: center; padding: 3px; background-color: DarkSalmon; color: white; } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <ul> <li><a href="#home">Home</a></li> <li><a href="#news">News</a></li> <li class="dropdown"> <a href="javascript:void(1)" class="dropbtn">Dropdown</a> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </li> </ul> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <footer> <p>Author: Hege Refsnes<br> <a href="mailto:hege@example.com">hege@example.com</a></p> </footer> </body> </html>
Please i need some help with this as i am new to html and css.
-
Cannot get the database to connect with PHP code
Below is my code for a DB connection using XAMPP:
"CONNECTOR.PHP"
<?php require_once 'includes/database.php'; ?> <html> <body> <?php $query="SELECT * FROM users"; $result=mysqli_query($conn,$query); $allRows=mysqli_num_rows($result); if($allRows>0) { while($row=mysqli_fetch_assoc($result)) { echo $row['username'].<"br>"; } } else { echo "Table is empty"; } ?> </body> </html>
DATABASE.PHP
<?php $dbHost="localhost"; $dbUser="root"; $dbPass=""; $dbName="phpclass"; $conn=mysqli_connect($dbHost,$dbUser,$dbPass,$dbName); if($conn) { } else { die("Could not connect to the DB"); } ?>
The server and MySQL are running according to the XAMPP manager, but CONNECTOR.PHP won't show anything on Chrome. Chrome says "The page isn't working". The name of the database and table are correct in the source code. Don't know if I'm doing something wrong or I have change something on my MAC OSX.
Thanks.
- PHP Strategy Game Map World help php, mysql
-
Whenever I try to add email on mysql server. My page is not responding. why?
I am a little bit confused. see the code below.
$('#submit').click(function() { $('#showdata').html($('#senddata').serialize()); /*Print all data that passed from form.*/ $.ajax({ url: "save.php", /* Here data store on mysql server without email and response to welcome.php. */ type: "POST", /* if i want to add proper email format then data store in mysql but not response on welcome.php. */ data: $('#senddata').serialize(), success: function(r) { alert("ok"); $('#senddata').trigger('reset'); window.location = 'welcome.php'; /*This is welcome page*/ } }) })
I want to submit a form using the ajax post method. If I write any name instead of email then data is stored on the server and responding welcome.php. Whenever I write any name email then data is stored on the server but responding welcome.php. Here is 'save.php' code.
<?php include('./config.php'); print_r($_POST); $name=$_POST['name']; $email=mysqli_real_escape_string($con,$_POST['email']); $pwd=$_POST['password']; $vill=$_POST['address'].$_POST['city'].$_POST['state'].$_POST['zip']; $insertdata="INSERT INTO `persons`(`name`,`email`,`pwd`,`vill`)VALUE('$name','$email','$pwd','$vill')"; print_r($insertdata); if(mysqli_query($con,$insertdata)){ echo "data added"; }else{ echo "not added"; } ?>
Note: if I put my button
<button class="btn btn-primary" id="submit">sign up</button>
outside form then everting is right. -
Binding a single PHP variable to multiple PDOStatements?
Has anyone bound a single PHP variable to multiple PDOStatements objects?
Thought I would ask here before setting up a proof of concept test.
I have three queries and two of the queries that share the same value. Simplified version of what I'm trying to do. The three queries are required for the specific implementation (for my work).
$sql1 = 'SELECT PersonId FROM LogTable'; $sql2 = 'SELECT PersonIdMerge FROM MergeTable WHERE PersonId = :PersonId'; $sql3 = 'UPDATE LogTable SET PersonId = :PersonIdMerge WHERE PersonId = :PersonId'; $PersonId = null; $PersonIdMerge = null; $stmt1 = $dbh->prepare($sql1); $stmt2 = $dbh->prepare($sql2); $stmt3 = $dbh->prepare($sql3); $stmt2->bindParam(':PersonId', $PersonId, PDO::PARAM_INT); $stmt3->bindParam(':PersonId', $PersonId, PDO::PARAM_INT); $stmt3->bindParam(':PersonIdMerge', $PersonId, PDO::PARAM_INT); $stmt1->execute(); while (($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) !== false) { $PersonId = $row1['PatientId']; $stmt2->execute(); while (($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) !== false { $PersonIdMerge = $row2['PersonIdMerge']; $stmt3->execute(); } }
Can the $PersonId variable be bound to the two individual PDOStatements simultaneously?
-
UPDATE table SET column=? WHERE username=?, incorrect amount of parameters in bind_param
So I have a form with an input named "group" and an action.php which goes like so:
if (!empty($_POST['group'])) { //just checking if the form was submitted with a value or not $group = $_POST['group']; $sql3 = "UPDATE spring2022 SET notification_group=? where username=?"; $stmt3 = $conn->prepare($sql); $stmt3 -> bind_param("ss", $group, $name); // line 49 $stmt3 -> execute(); $stmt3 -> store_result(); echo $group; // this is to make sure group is defined }
The SQL table has a column named notification_group which may or may not be set already, but the username is definitely on table - it had been previously checked and made sure it was there. So basically the table would look like:
spring 2022
username notification_group user1 user2 group1 It seems to be some sort of error in the sql statement or the bind_param, but I'm not sure.
UPDATE spring2022 SET notification_group=? where username=?
and
$stmt3 -> bind_param("ss", $group, $name);
The full error:
Uncaught ArgumentCountError: The number of variables must match the number of parameters in the prepared statement in action.php:49 Stack trace: #0 action.php(49): mysqli_stmt->bind_param('ss', 'group2', 'user1') #1 {main} thrown in action.php on line 49
Of note: I am using MariaDB, the phpmyadmin for my sql server.