how can i make an admin insert

Discussion in 'PHP' started by dougvcd, May 21, 2007.

  1. #1
    not sure if i have said it right but what i want to do is when peeps log in to my site there usernames and passwords are in database and gets checked
    can i put some thing like admin in and that will let me add to database
    hope you understand what i mean
    this is the code to log in
    cheers
    Doug
    or is there a better way

    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Login</title>
    <script language="JavaScript">
    <!--
    function FP_preloadImgs() {//v1.0
     var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
     for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
    }
    
    function FP_swapImg() {//v1.0
     var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
     n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
     elm.$src=elm.src; elm.src=args[n+1]; } }
    }
    
    function FP_getObjectByID(id,o) {//v1.0
     var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
     else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
     if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
     for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
     f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
     for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
     return null;
    }
    // -->
    </script>
    </head>
    
    <body onLoad="FP_preloadImgs(/*url*/'images/button2.jpg',/*url*/'images/button3.jpg',/*url*/'images/button5.jpg',/*url*/'images/button6.jpg',/*url*/'images/button8.jpg',/*url*/'images/button9.jpg',/*url*/'images/buttonB.jpg',/*url*/'images/buttonC.jpg',/*url*/'images/buttonE.jpg',/*url*/'images/buttonF.jpg')" bgcolor="#00FFFF">
    
    <p align="center">
    <img border="0" src="images/cooltext55242781.jpg" width="516" height="46"></p>
    <p align="center">
    <a href="index.php">
    <img border="0" id="img1" src="images/button1.jpg" height="33" width="100" alt="Home" onMouseOver="FP_swapImg(1,0,/*id*/'img1',/*url*/'images/button2.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img1',/*url*/'images/button1.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img1',/*url*/'images/button3.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img1',/*url*/'images/button2.jpg')" fp-style="fp-btn: Metal Tab 1; fp-font-style: Bold" fp-title="Home"></a>&nbsp;
    <a href="browse.php">
    <img border="0" id="img2" src="images/button4.jpg" height="33" width="100" alt="Browse" onMouseOver="FP_swapImg(1,0,/*id*/'img2',/*url*/'images/button5.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img2',/*url*/'images/button4.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img2',/*url*/'images/button6.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img2',/*url*/'images/button5.jpg')" fp-style="fp-btn: Metal Tab 1; fp-font-style: Bold" fp-title="Browse"></a>&nbsp;
    <a href="register.php">
    <img border="0" id="img3" src="images/button7.jpg" height="33" width="100" alt="Register" onMouseOver="FP_swapImg(1,0,/*id*/'img3',/*url*/'images/button8.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img3',/*url*/'images/button7.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img3',/*url*/'images/button9.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img3',/*url*/'images/button8.jpg')" fp-style="fp-btn: Metal Tab 1; fp-font-style: Bold" fp-title="Register"></a>&nbsp;
    <a href="login.php">
    <img border="0" id="img4" src="images/buttonA.jpg" height="33" width="100" alt="Log In" onMouseOver="FP_swapImg(1,0,/*id*/'img4',/*url*/'images/buttonB.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img4',/*url*/'images/buttonA.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img4',/*url*/'images/buttonC.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img4',/*url*/'images/buttonB.jpg')" fp-style="fp-btn: Metal Tab 1; fp-font-style: Bold" fp-title="Log In"></a>&nbsp;
    <a href="contact.php">
    <img border="0" id="img5" src="images/buttonD.jpg" height="33" width="100" alt="Contact" onMouseOver="FP_swapImg(1,0,/*id*/'img5',/*url*/'images/buttonE.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img5',/*url*/'images/buttonD.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img5',/*url*/'images/buttonF.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img5',/*url*/'images/buttonE.jpg')" fp-style="fp-btn: Metal Tab 1; fp-font-style: Bold" fp-title="Contact"></a></p>
    <p align="center">&nbsp;
    
    <body bgcolor="#00FFFF">
    <?php 
    // simple login script 
    // filename: login.php 
    
       $form = ' 
       <p align="center" class="bodytext">
        Members Login<br> 
           <form action="login.php" method="post"> 
    	   
           Username:<input type="name" name="username"> 
    	   
           Password:<input type="password" name="password"> 
    	   
           <input type="submit" name="submit" value="submit this"> 
           </form> 
           '; 
    
    if(isset($_POST['submit'])){ 
        $hm = authenticate($_POST['username'], $_POST['password']); 
        $hm2 = mysql_num_rows($hm); 
        if($hm2 > 0){ 
          echo "You have successfully Logged in! You will be redirected in three seconds!><br /><br />
    				
    				<div class='info'>If you don't wish to wait, <a href='members_area.php'>click here</a>";
    				
    				echo'<meta http-equiv="REFRESH" content="3;url=members_area.php">';; 
        }else{ 
          echo "username / password not valid<br>"; 
          echo $form; 
        } 
    
    }else{ 
        echo $form; 
    } 
    
    function authenticate($username, $password){ 
        
    
        $request = "SELECT * FROM exchange WHERE password='$password' AND username='$username'"; 
    
        // Pass the request to the mysql connection, 
    
        $results = query_db($request); 
    
        // if mysql returns any number of rows great than 0 there is a match 
        return $results; 
    } 
    
    function query_db($query){ 
        $conn = mysql_connect(""); 
        if (!$conn) { 
            die('Could not connecteeer: ' . mysql_error()); 
        } 
        mysql_select_db(""); 
        $results = mysql_query($query, $conn); 
        mysql_close($conn); 
        return $results; 
    } 
     ?>
    </body>
    </html>
    PHP:
     
    dougvcd, May 21, 2007 IP
  2. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #2
    you need to edit this out of your post right now and change the mysql username and password


        $conn = mysql_connect("***", "***", "***");
    Code (markup):
    and i'd change EVERY password using '****' email,yahoo. dp, etc etc

    please post a response so i too can remove it from this post
     
    donteatchicken, May 21, 2007 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cheers for that
    slip up
    Doug
     
    dougvcd, May 21, 2007 IP
  4. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #4
    it happens
     
    donteatchicken, May 21, 2007 IP