Jump to content

Recommended Posts

what i am trying to do is, echo an error message "wrong username or password" if the user inputs the wrong login details, but i do not know how to get the variables form the checklogin.php without putting the to scripts into one..

 

this is to echo the error message... (dont know if that will even work, im new to php)

<?php 
if (isset($_POST['Login'])){
	if($count!==1){
echo "Wrong username or password";
}
}
?>

 

this is getting the data info...

<?php
$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
$tbl_name="***"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
session_register("myusername");
session_register("mypassword"); 
header("location:profile.php");
}
}
?>

 

and finally this is my form...

<form name='form1' method='POST' action='checklogin.php'>
<input type='submit' id='Login' name='Login' value='Log in'>
</form>

 

*note* that isnt the full form, i could not be bothered copying little parts lots of times from the table *note*

 

 

Link to comment
https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/
Share on other sites

I'm not sure quite what you're doing in your code, but you'd do this.

if (isset($_POST['Login'])){
   $pass = $_POST['Login'];
   if ($pass != $user['pass']) {  //some way to pull the pass outta SQL
      echo "You have entered the wrong password!";
   }
}

ok, i ended up putting the two scripts together but im still getting some problems...

 

<form name="form1" method="POST" action="">
<table width="30%" border="0" cellspacing="5" cellpadding="0" class="signform" align="left">
<tr>
<td>

<?php 
// If result matched $myusername and $mypassword, table row must be 1 row
    if($count!==1){
   echo "Wrong username or password";
   }
   else
   {
   session_register("myusername");
   session_register("mypassword");
   header("location:profile.php");
   }
   ?>
</td>
</tr>
<tr>
<td width="80px" align="right"> Username</td>
<td><input type="text" id="myusername"      name="myusername"  style="width:165px;font-size:15px;"></td>
</tr>
<tr>
<td align="right">Company</td>
<td><input type="text" id="mycompany"       name="mycompany"     style="width:165px;font-size:15px;"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" id="mypassword"  name="mypassword"    style="width:165px;font-size:15px;"></td>
</tr>
<tr>
<td align="right"></td>
<td  align="left">Remember Me <input type="checkbox" id="Checkbox1" name="rememberbox" value="on";><br>Forgot your password?<br><br> <input type="submit" id="Login" name="Login" value="Log in" style="height:35px;width:86px;";></td>
</tr>
</table>
</form>

 

<?php
$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
$tbl_name="***"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$_SESSION['myusername']=$dbusername;

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

}

?>

i am getting this error...what does it mean?

Notice: Undefined variable: error_login in /customers/squiblo.com/squiblo.com/httpd.www/login.php on line 290

 

line 282-294...

if($count==1){
session_register("myusername");
session_register("mypassword");
session_register("mycompany"); 
header("location:index.php");
}
else
{
$count = $error_login;
$error_login = "Wrong username or password";
}
}
?>

 

and this is where i want the error echoed

<?php 
// If result matched $myusername and $mypassword, table row must be 1 row
    if($count = $error_message){
   echo $error_message;
   }
   ?>

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.