Help with this login php code nowwwwwwwww pleaseeeeeeeee

<?php $connection =mysqli_connect("localhost","root","","reggy"); $Uname=$_POST["Uname"]; $password=$_POST["password"]; $sql= "SELECT * FROM applicant WHERE Uname ='$Uname' AND password ='$password'"; $result= mysqli_query($connection,$sql); $row= mysqli_fetch_array($result); if($row){ header('location:viewcoz.php'); exit(); } else { echo "invalid login"; } ?>

I’m not sure, but there may be a better channel to ask in than HTML-CSS :man_shrugging: .

This isn’t enough information to help you.

You’ll need to post more information about the environment you are using. How are you running PHP and MySQL. What is the HTML for the login form? Is this a personal project or a tutorial that you could link to?

I don’t want to discourage you from posting here, but if you are using a PHP framework you’ll probably have better luck asking questions in the forums/slack for that community.

that code is a php code pleaseee

Yes it’s obvious that this is PHP. But as already said, this is not enough information to help you. Please describe

  • what is your code supposed to to
  • what is not working
  • do you get any errors
  • what have you tried so far to debug
  • are you sure your DB connection is working

Welcome there,

Do you have a question?

If so, please edit your post to include it in the body of your post .

Learning to describe problems is an important part of learning how to code.

The more information you give us, the more likely we are to be able to help.

Also, please change your thread title to describe your problem more clearly. Descriptive titles, such as “Why does my function return undefined?”, are more likely to elicit helpful responses than generic titles, such as “Help please”.

the code is to login a user and link the user to display his/her courses(viewcoz.php) registered in the form.
the problem is ,it gives out “invalid login” output as indicated on the code.
I am currently using notepad++ for coding

My PHP is more than rusty, but I’ll try…

First of all I’d check if the connection is working:

$connection = mysqli_connect("localhost","root","","reggy");

if (!$connection) {
    echo 'connection error: ' . mysqli_connect_error();

Then I’d check if $Uname and $password are correctly stored in $_POST.

Next, I’d check if the $sql is correct. I remember I once had some hassle making it work with variables. Here’s an alternative that might be worth a try:

$sql= "SELECT * FROM applicant WHERE Uname ='".$Uname."' AND password ='".$password."'"

Hope that helps…

Otherwise, please note that this forum is focussed on the MERN stack, so support/knowledge concerning PHP is a bit limited.

okay ,thanks for the help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.