Jump to content

Recommended Posts

Hi

 

My login form wont work for some reason, any ideas?

 


<form name="authenticate" method="post" action="wk9ex2.php">
<input name="login id" type="text" value="loginid" size="20"/><br >
<input name="password" type="text" value="password" size="20"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>

<?php

//Database Information

$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql="SELECT loginid FROM week9 WHERE loginid='".$loginid.”’ and password=’”.$password.”’”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
echo loggedin.php
//proceed to perform website’s functionality – e.g. present information to the user
}
?>


Link to comment
https://forums.phpfreaks.com/topic/82957-solved-login-not-working/
Share on other sites

HOPE THATS NOT YOUR ACTUAL USER AND PASS!!!!?

 

you haven't defined $loginid and $password

 

try this

 

<form name="authenticate" method="post" action="wk9ex2.php">
<input name="login id" type="text" value="loginid" size="20"/><br >
<input name="password" type="text" value="password" size="20"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>

<?php

//Database Information

$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$loginid=mysql_real_escape_string($_POST['login id']);
$password=mysql_real_escape_string($_POST['password']);

$sql="SELECT loginid FROM week9 WHERE loginid='".$loginid.”’ and password=’”.$password.”’”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
echo loggedin.php
//proceed to perform website’s functionality – e.g. present information to the user
}
?>

 

 

Regards

Liam

Below is my code atm, it still inst working though, when I click to send the information it just refreshes the page instead of going to the logged in page

 

 

Any ideas?

 


<form name="authenticate" method="post" action="wk9ex2.php">
<input name="login id" type="text" value="loginid" size="20"/><br >
<input name="password" type="text" value="password" size="20"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>

<?php

//Database Information


//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$loginid=mysql_real_escape_string($_POST['login id']);
$password=mysql_real_escape_string($_POST['password']);

$sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
echo loggedin.php;
//proceed to perform website’s functionality – e.g. present information to the user
}
?>

Below is my code atm, it still inst working though, when I click to send the information it just refreshes the page instead of going to the logged in page

 

 

Any ideas?

 


<form name="authenticate" method="post" action="wk9ex2.php">
<input name="login id" type="text" value="loginid" size="20"/><br >
<input name="password" type="text" value="password" size="20"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>

<?php

//Database Information


//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$loginid=mysql_real_escape_string($_POST['login id']);
$password=mysql_real_escape_string($_POST['password']);

$sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
echo loggedin.php;
//proceed to perform website’s functionality – e.g. present information to the user
}
?>

 

this section of your code might be causing a problem:

 

echo loggedin.php;

 

try:

 

include("loggedin.php");

 

does your code work after you made the alteration? to the bit i pointed out

use this

 

<?php

//Database Information


//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$loginid=mysql_real_escape_string($_POST['login id']);
$password=mysql_real_escape_string($_POST['password']);

$sql="SELECT username FROM week9 WHERE username='".$loginid."' and password='".$password."'";
$r = mysql_query($sql);
if(!$r) {
  $err=mysql_error();
  print $err;
  exit();
}
if(mysql_num_rows($r)==0){
  print "no such login in the system. please try again.";
?>
<form name="authenticate" method="post" action="wk9ex2.php">
<input name="login id" type="text" value="loginid" size="20"/><br >
<input name="password" type="text" value="password" size="20"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>
<?php
} else {
  include('loggedin.php');
//proceed to perform website&#8217;s functionality &#8211; e.g. present information to the user
}
?>

 

I have made it so your form will show when not validated and when validated you will include the loggedin.php file. I changed mysql_affected_rows() to mysql_num_rows($row) as mysql_affected_rows is only used after updating a table, this will always be 0 when selecting from a table.

 

Regards

Liam

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.