Jump to content

My query is not working


jukie

Recommended Posts

Hi

I posted this in another forum but this might be better in here, I just cant seem to get my login to check the username and password to let the user enter the webpage

I get no errors, just that the index pages keeps reloading on submit.

 

This is my MySQL code

<?php

$host        =    '';
$user        =    '';
$password    =    '';
$database    =    '';

 
$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct');
mysql_select_db($database,$conn) or die('Database Information is not correct');
 
// Inialize session
 session_start();

// Include database connection settings


// Retrieve username and password from database according to user's input
 $login = mysql_query("SELECT * FROM gotusers WHERE (Username = '" . mysql_real_escape_string($_POST['Username']) . "') and (Password = '" . mysql_real_escape_string(md5($_POST['Password'])) . "')");

// Check username and password match
 if (mysql_num_rows($login) == 1) {
 // Set username session variable
 $_SESSION['Username'] = $_POST['Username'];
 // Jump to secured page
 header('Location: sucess.php');
 }
 else {
 // Jump to login page
 header('Location: index.php');
 }

  
 
  


?>
Link to comment
Share on other sites

Then you are either finding no match or more than 1 match.

Always put the query string into a variable so you can echo it if required.

$sql = "SELECT foo FROM bar";
$result = mysql_query($sql);

In cases like this you can now echo $sql then copy and paste the actual query into phpMyAdmin (or similar) and see what the results are

Link to comment
Share on other sites

Thanks, I got the login in by changing the query. What is annoying me is that I had all this working in local, the register page is not even working either, or  the sessions, now uploaded it to web and none of it working. Seems there no point in working locally if the codes don't work when uploaded to a web hosting. How can I avoid this in future, create identical environments

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.