Automatisch User ausfüllen

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Automatisch User ausfüllen

    Hi,

    mein problem ist:
    ich habe ein loginscript, welches hervorragend funktioniert.
    Jedoch will ich bei einer Bestellung, dass sich der username automatisch ausfüllt. (es sind 1-2 andere Seiten dawischen)
    Ich hab schon vieles probiert jedoch ohne Erfolg, da ich noch ein ziemlicher Anfänger bin.

    Fürs Loginscript hab ich 3 Datein:

    main_login.php in der das Formular zum Login ist.

    PHP-Code:
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <
    tr>
    <
    form name="form1" method="post" action="checklogin.php">
    <
    td>
    <
    table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <
    tr>
    <
    td colspan="3"><strong>DB Login</strong></td>
    </
    tr>
    <
    tr>
    <
    td width="78">Username</td>
    <
    td width="6">:</td>
    <
    td width="294"><input name="myusername" type="text"></td>
    </
    tr>
    <
    tr>
    <
    td>Password</td>
    <
    td>:</td>
    <
    td><input name="mypassword" type="text"></td>
    </
    tr>
    <
    tr>
    <
    td>&nbsp;</td>
    <
    td>&nbsp;</td>
    <
    td><input type="submit" name="Submit" value="Login"></td>
    </
    tr>
    </
    table>
    </
    td>
    </
    form>
    </
    tr>
    </
    table
    checklogin.php wo sich die Logik zum überprüfen der Formulardaten befindet:

    PHP-Code:
    <?php
    $host
    ="localhost"// Host name
    $username="username"// Mysql username
    $password="dbpw"// Mysql password
    $db_name="dbname"// Database name
    $tbl_name="login"// 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");

    // 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);
    ?>

    <?php
    $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 "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:login_success.php");
    ?>
    bestellung.php?username=$myusername
    <?
    }
    else {
    echo "Wrong Username or Password";
    }
    ?>
    login_success.php, in der lediglich weitererlinkt wird wenn alles richtig eingegeben wurde

    PHP-Code:
    <?
    session_start();
    if(!session_is_registered(myusername)){
    header("location:main_login.php");
    }
    ?>

    <html>
    <body>
    Login Successful<br>
    <a href='db_index.html'>Zur DB</a>
    </body>
    </html>
    Das hier ist das Bestellungsformular in das sich der username dann automatisch schreiben soll:
    PHP-Code:
    <?
    session_start();
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test DB</title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="">
      <p align="center">  
      <b><font size="5">Ressourcenbestellung</font></b></p>
        <p align="center">  
      <font color="#FF0000">Alle Angaben sind in k anzugeben.</font></p>
        <p>  
      &nbsp;</p>
        <p>  
      <label>Titan
      <input type="text" name="Titan" id="Titan" />
      </label>
      <label>Silicium
      <input type="text" name="Silicium" id="Silicium" />
      </label>
      <label>Helium
      <input type="text" name="Helium" id="Helium" />
      </label>
      <label>Nahrung
      <input type="text" name="Nahrung" id="Nahrung" />
      </label>
      <label>Wasser
      <input type="text" name="Wasser" id="Wasser" />
      </label>
      </p>
      <p>
      <label>Bauxit
      <input type="text" name="Bauxit" id="Bauxit" />
      </label>
      <label>Aluminium
      <input type="text" name="Aluminium" id="Aluminium" />
      </label>
      <label>Uran
      <input type="text" name="Uran" id="Uran" />
      </label>
      <label>Plutonium
      <input type="text" name="Plutonium" id="Plutonium" />
      </label>
      <label>Wasserstoff
      <input type="text" name="Wasserstoff" id="Wasserstoff" />
      </label></p>
      <p>
      <label>Credits
      <input type="text" name="Credits" id="Credits" />
      </label>  
      
      <input type="submit" name="Bestellung" id="button" value="Senden"/>
      
    </form>
    <?php
    include("connect.php");

      
    $user $_GET["username"];
      
    $ti $_POST["Titan"];
      
    $si $_POST["Silicium"];
      
    $na $_POST["Nahrung"];
      
    $he $_POST["Helium"];
      
    $wa $_POST["Wasser"];
      
    $ba $_POST["Bauxit"];
      
    $al $_POST["Aluminium"];
      
    $ur $_POST["Uran"];
      
    $pl $_POST["Plutonium"];
      
    $ws $_POST["Wasserstoff"];
      
    $cr $_POST["Credits"];
      
    $eintrag "INSERT INTO Ress (User, Titan, Silicium, Helium, 
    Nahrung, Wasser, Bauxit, Aluminium,
     Uran, Plutonium, Wasserstoff, Credits) 
    VALUES ('
    $user', '$ti','$si', '$he', $na$wa$ba
    $al$ur$pl$ws$cr)";

      
    $eintragen mysql_query($eintrag);

    ?>
    </body>
    </html>
    Ich hoffe ihr wisst wie ich es hinbekommen kann.

    Danke im Vorraus!
    Gruß Torfu
    Zuletzt geändert von Torfu; 17.03.2008, 18:26.

  • #2
    Regel lesen: http://www.php-resource.de/forum/sho...threadid=50454

    Kommentar


    • #3
      Ganz prinzipiell:
      User logged sich ein --> Username wird in einer Session Var gespeichert.
      Solange du sicherstellst, dass die Session ID von Seite zu Seite weitergegeben wird (URL oder Cookie) kannst du immer auf den Usernamen zugreifen z.B.
      PHP-Code:
      <?php
      session_start
      ();
      //setzt voraus, dass der Name in $_SESSION['uName'] gespeichert wurde
      if(isset($_SESSION['uName'])){
        
      ?>
      <form action="blabla.php?<?php echo strip_tags(SID);?>" method="post">
      <input type="text" name="userName" value="<?php echo $_SESSION['uName'];?>" /><br />
      <input type="submit" value="Anmelden" />
      </form>
      <?php
      }else{
        
      //was immer du willst
      }
      Und ja brich bitte deinen Code um, damit man nicht zur Seite scrollen muss (habe ne 1650-er Auflösung und einen Scrollbalken!!)

      Gruss

      tobi
      Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

      [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
      Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

      Kommentar


      • #4
        Danke! habs mittlerweile über cookies gelöst

        Kommentar


        • #5
          Danke! habs mittlerweile über cookies gelöst
          und wenn der User keine Cookies erlaubt, was dann? Ich würde als Fallback auf die Konstante SID zugreifen, die es erlaubt, wenn Cookies nicht aktiviert sind, die Session ID via URL durchzuschleifen.

          Gruss

          tobi
          Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

          [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
          Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

          Kommentar

          Lädt...
          X