Jump to content

[SOLVED] php sql problem


ded

Recommended Posts

Even when I put in a correct Username/Password, I receive the followin:

Username/Password Combination Invalid. Click the back button on your browser and re-enter

 

Here is the code

 

index.php

<form method=post action="post.php" enctype="multipart/form-data">
  <table border="0" align="center" style="width: 40%; border: 1px solid #000099;background-color: #d0cfb4" >
    <tr>
      <td style="font-weight: bold; color: #000099; font-size: 100%; text-align: right;background-color: #d0cfb4;">User Name</td>
      <td style="background-color: #d0cfb4;"><input name="username" type="text" maxsize="25" style="width: 150px; font-size: 90%;">
    <tr>
      <td style="font-weight: bold; color: #000099; font-size: 100%; text-align: right;background-color: #d0cfb4;">Password</td>
      <td style="background-color: #d0cfb4;"><input name="password" type="password"  style="width: 150px; font-size: 90%;"></td>
    </tr>
    <tr>
      <td colspan="2" style="text-align: center;background-color: #d0cfb4;"><input type="submit"  name="Login" value="Sign-In" style="color: #000099;"></td>
    </tr>
  </table>
</form>

 

post.php

<?php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$username = $_POST['username'];
$password = $_POST['password'];

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");
$query = "SELECT * FROM `table` WHERE `username` = $username and `password` = $password";
$result = mysql_query($query,$dbh) or die("Username/Password Combination Invalid.  Click the back button on your browser and re-enter");
..............

 

Can anyone see what i am missing?

 

Thanks in advance,

DED

Link to comment
Share on other sites

your use of or die() doesn't make sense in this context.  It'll still return a result, only with 0 rows, if the query is built correctly.  But your query needs to look like this:

 

$query = "SELECT * FROM table WHERE username = '$username' and password = '$password'";
$result = mysql_query($query,$dbh) or die(mysql_error());

Link to comment
Share on other sites

I see what you mean.....

 

I am running into another problem.

 

Notice: Undefined index: area in /home1/public_html/webpage/post.php on line 14

 

 

php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$username = $_POST['username'];
$password = $_POST['password'];

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");
$query = "SELECT * FROM table WHERE username = '$username' and password = '$password'";
$result = mysql_query($query,$dbh) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
    $area = $_GET['area'];

 

Area is a field name in Table

Link to comment
Share on other sites

php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$username = $_POST['username'];
$password = $_POST['password'];

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");
$query = "SELECT * FROM table WHERE username = '$username' and password = '$password'";
$result = mysql_query($query,$dbh) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
    $area = $row['area'];

 

$_GET is typically used for variables in a query string at the end of a page.  index.php?do=foo would assign $_GET['do'] = "foo";

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.