squiblo Posted August 20, 2009 Share Posted August 20, 2009 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* Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/ Share on other sites More sharing options...
oni-kun Posted August 20, 2009 Share Posted August 20, 2009 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!"; } } Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902253 Share on other sites More sharing options...
squiblo Posted August 20, 2009 Author Share Posted August 20, 2009 i just get taken to a blank page on checklogin.php Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902258 Share on other sites More sharing options...
gergy008 Posted August 20, 2009 Share Posted August 20, 2009 Use include("File_Path.php") to add all of another scripts variables and fucntions into another script Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902259 Share on other sites More sharing options...
squiblo Posted August 20, 2009 Author Share Posted August 20, 2009 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902269 Share on other sites More sharing options...
squiblo Posted August 20, 2009 Author Share Posted August 20, 2009 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902278 Share on other sites More sharing options...
Zoofu Posted August 20, 2009 Share Posted August 20, 2009 Try putting near the top of the script: include "./theotherscript.php"; Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-902330 Share on other sites More sharing options...
gergy008 Posted August 21, 2009 Share Posted August 21, 2009 Try putting near the top of the script: include "./theotherscript.php"; Yes, He obviously missed my post... If you do that it joins two scripts together better than what you did it like. Quote Link to comment https://forums.phpfreaks.com/topic/171084-getting-variable-from-another-script/#findComment-903017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.