need some help with simple login script

Discussion in 'PHP' started by dougvcd, Apr 17, 2009.

  1. #1
    ok i have this login script
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form name="form1" method="post" action="select.php">
    <td>
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td colspan="3"><strong>Poster </strong></td>
    </tr>
    <tr>
    <td width="78">name</td>
    <td width="6">:</td>
    <td width="294"><input name="myname" type="text" id="myname"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Poster"></td>
    </tr>
    </table>
    
    PHP:
    you enter your name and goes to next page which shows records of that name
    but i need an error page if name is not in database

    <?php
      // Connects to your Database 
    
    $dbh=mysql_connect("localhost", "cavcd", "57") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("pets");
    
    $myname=$_POST['myname'];
    
    //Retrieves data from MySQL
    
     $data = mysql_query("SELECT * FROM register where name='$myname'") or die(mysql_error());
    
    //Puts it into an array 
    while($info = mysql_fetch_array( $data )) 
    { 
    //Outputs the image and other data
    Echo "<img src=http://www.mouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"center\" width=\"150px\" height=\"150px\" hspace=\"10px\" vspace=\"8px\"> <br>";
    Echo "<b>State:</b> ".$info['state'] . " <br>";
    Echo "<b>Type:</b> ".$info['type'] . " <br>";
    Echo "<b>Area:</b> ".$info['area'] . " <br>";
    Echo "<b>Description:</b> ".$info['desc'] . " <br>";
    Echo "<b>If Seen Please Tel:</b> ".$info['tel'] . " <br>";
    } 
    mysql_close();
    
    ?>
    
    PHP:
    cheers
    Doug
     
    dougvcd, Apr 17, 2009 IP
  2. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #2
    why not try something like
    
    
    <?php  
    // Connects to your Database 
    $dbh=mysql_connect("localhost", "cavcd", "57") or die('I cannot connect to database because: ' .mysql_error()) ;
     mysql_select_db("pets");$myname=$_POST['myname'];
    //Retrieves data from MySQL 
    $data = mysql_query("SELECT * FROM register where name='$myname'") or die(mysql_error());
    $countrows =  mysql_num_rows($data);
    if($countrows == 0){
    
    ERROR STUFF HERE
    
    } ELSE {
    //Puts it into an array 
    while($info = mysql_fetch_array( $data )) { 
    //Outputs the image and other data
    Echo "<img src=http://www.mouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"center\" width=\"150px\" height=\"150px\" hspace=\"10px\" vspace=\"8px\"> <br>";
    Echo "<b>State:</b> ".$info['state'] . " <br>";
    Echo "<b>Type:</b> ".$info['type'] . " <br>";
    Echo "<b>Area:</b> ".$info['area'] . " <br>";
    Echo "<b>Description:</b> ".$info['desc'] . " <br>";
    Echo "<b>If Seen Please Tel:</b> ".$info['tel'] . " <br>";} 
    mysql_close();?>
    
    }
    
    
    
    PHP:
    hope it helps. If you need some more help, feel free to PM me
     
    Grit., Apr 17, 2009 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    <?php
    $data = mysql_query("SELECT * FROM register where name='$myname'");
    if ( mysql_num_rows($data) == 0 ) {
    	header("Location: error_page.php");
    	exit();
    } else {
    	// Continue
    }
    ?>
    PHP:
     
    ActiveFrost, Apr 17, 2009 IP
  4. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks to all
    now working ok
    cheers
    Doug
     
    dougvcd, Apr 18, 2009 IP