Current location: Hot Scripts Forums » Programming Languages » PHP » Problem displaying another page without using a link


Problem displaying another page without using a link

Reply
  #1 (permalink)  
Old 11-02-07, 10:36 AM
bakarre bakarre is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Trophee Problem displaying another page without using a link

Good day, the code below in "loginn.php" is to query the databse for a valid userid and password, if it exists, I want to view another page "sespage.php" if the query is successful, without using a link, if not successful, I want it to display another page - wrong userid/password.

I dont want "loginn.php" page to appear for either the query is successful or not.



Please see the code "loginn.php"( it can query database sucessfully but I can display what I want without using a link)

PHP Code:

<?php 
 session_start
();
 
$db mysql_connect("localhost","root","******") or die(mysql_error()); 
mysql_select_db("fdp",$db) or die(mysql_error()); 

if(isset(
$_POST['userid']) && isset($_POST['passwd']))
$userid $_POST['userid'];
$passwd $_POST['passwd'];
if(isset(
$_POST['fdplog']))

{

    
$sql "SELECT * FROM fdp_luser WHERE userid = '$userid' and passwd = '$passwd'";
    
$result mysql_query($sql);
    
mysql_query($sql) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
    
$myrow mysql_fetch_array($result);
    if(
$myrow) {
    
$_SESSION['valid_user'] = $userid;
    echo 
'You are logged in as : '.$_SESSION['valid_user'].' <br>';
    echo 
'<a href= "sespage.php"> Sespage </a><br />';
}
else{
echo 
'Wrong UserName or Password'
}    
}
?>
<html>
<body>

<style type="text/css">
<!--
body {
    margin-left: 20%;
    margin-top: 10%;
    
}

-->
</style>
<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>
    <label>SIGN IN <br>
    </label>
  <table width="760" height="27" border="5">
    <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
    </tr>
  </table>
    <label for="textfield"><br>
    <br>
    <br>
   
     <br>
   User Name :
  <input name="userid" type="Text" class="anytg15" value="<?php echo $userid ?>">
  <br>
   Password :
  <input name="passwd" type="password" class="any14" value="<?php echo $passwd ?>">
 
  <p>&nbsp;</p>
  <table width="760" height="27" border="5">
    <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
    </tr>
  </table>
  <p align="center">
    <label for="Submit"></label>
    <input type="Submit" name="fdplog" value="Sign In" id="Submit">
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>
Thank

Bakare

Last edited by Nico; 11-02-07 at 05:07 PM.
Reply With Quote
  #2 (permalink)  
Old 11-02-07, 03:23 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<?php 
 session_start
();
 
$db mysql_connect("localhost","root","****") or die(mysql_error()); 
mysql_select_db("fdp",$db) or die(mysql_error()); 

if(isset(
$_POST['userid']) && isset($_POST['passwd']))
$userid $_POST['userid'];
$passwd $_POST['passwd'];
if(isset(
$_POST['fdplog']))

{

    
$sql "SELECT * FROM fdp_luser WHERE userid = '$userid' and passwd = '$passwd'";
    
$result mysql_query($sql);
    
mysql_query($sql) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
    
$myrow mysql_fetch_array($result);
    if(
$myrow) {
    
$_SESSION['valid_user'] = $userid;
    
header("Location: sespage.php");
}
else{
header("Location: error.php");
}    
}
?>
<html>
<body>

<style type="text/css">
<!--
body {
    margin-left: 20%;
    margin-top: 10%;
    
}

-->
</style>
<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>
    <label>SIGN IN <br>
    </label>
  <table width="760" height="27" border="5">
    <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
    </tr>
  </table>
    <label for="textfield"><br>
    <br>
    <br>
   
     <br>
   User Name :
  <input name="userid" type="Text" class="anytg15" value="<?php echo $userid ?>">
  <br>
   Password :
  <input name="passwd" type="password" class="any14" value="<?php echo $passwd ?>">
 
  <p>&nbsp;</p>
  <table width="760" height="27" border="5">
    <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
    </tr>
  </table>
  <p align="center">
    <label for="Submit"></label>
    <input type="Submit" name="fdplog" value="Sign In" id="Submit">
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>
Try that

I would also suggest you learn about making your login code more secure. A great place to start is http://www.ilovejackdaniels.com/php/writing-secure-php/

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName

Last edited by Nico; 11-02-07 at 05:08 PM. Reason: Removed password.
Reply With Quote
  #3 (permalink)  
Old 11-02-07, 11:53 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Here is another way.

You can keep everything on one page using a SWITCH.
PHP Code:

<?php session_start(); ?>
<html>
<head>
<style type="text/css">
<!--
body {margin-left: 20%;margin-top: 10%;}
-->
</style>
</head>
<body>
<?php
$sw 
"";
if(isset(
$_POST['fdplog']))
{
 
$userid $_POST['userid'] != "" $_POST['userid'] : "";
 
$passwd $_POST['passwd'] != "" $_POST['passwd'] : "";
 if(
$userid && $passwd)
 {
  
$db mysql_connect("localhost","root","******") or die(mysql_error());
  
mysql_select_db("fdp",$db) or die(mysql_error());
  
$sql "SELECT * FROM fdp_luser WHERE userid = '$userid' and passwd = '$passwd'";
  
$result mysql_query($sql);
  
mysql_query($sql) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
  
$myrow mysql_fetch_array($result);
  if(
$myrow){$_SESSION['valid_user'] = $userid;$sw 1;}
  else{
$sw 2;}
  }
 if(!
$sw){echo "<span style='font-size:20px;text-decoration:underline;color:#ff0000;'>Please enter the required information.</span>";}
 }
SWITCH(
$sw)
{
 case 
1:
  echo 
"<span style='font-size:20px;text-decoration:underline;color:#000000;'>You are logged in as : ".$_SESSION['valid_user']."</span><br>";
  require 
"sespage.php";
  break;
 case 
2:
  echo 
"<span style='font-size:20px;text-decoration:underline;color:#000000;'>Wrong UserName or Password !!!</span>";
  break;
 default:
?>
 <form name="form1" method="post" action="" style="margin:0px;">
   <p>
    <label>SIGN IN <br>
    </label>
   <table width="760" height="27" border="5">
    <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
    </tr>
   </table>
    <label for="textfield"><br>
    <br>
    <br>
    <br>
     User Name :
     <input name="userid" type="Text" class="anytg15" value="<?php echo $userid ?>">
    <br>
     Password :
     <input name="passwd" type="password" class="any14" value="<?php echo $passwd ?>">
    <p>&nbsp;</p>
    <table width="760" height="27" border="5">
     <tr>
      <td width="714" bgcolor="#009966" scope="row">&nbsp;</td>
     </tr>
    </table>
    <p align="center">
    <label for="Submit"></label>
     <input type="Submit" name="fdplog" value="Sign In" id="Submit">
    </p>
  </form>
<?php
  
break;
  }
?>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 11-02-07 at 11:59 PM.
Reply With Quote
  #4 (permalink)  
Old 11-05-07, 07:18 AM
bakarre bakarre is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks alot, it works.
You can buy experience.

Bakarre
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
random link problem doogi PHP 18 03-04-09 01:00 AM
[turnkey] Lyrics site - $149 (LEGAL) rightinpoint General Advertisements 0 10-22-06 04:33 AM
P4 main page link - NO PR NEEDED - just need to be indexed wariental Traffic Exchange 1 05-11-06 04:22 PM
Free Link Exchange Program JC3 General Advertisements 0 09-30-05 12:02 PM
hotscripts main page...links problem kvnband HotScripts Site Bug Reports 2 09-26-04 07:49 PM


All times are GMT -5. The time now is 07:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.