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
https://forums.phpfreaks.com/topic/142839-solved-php-sql-problem/
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());

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

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.