WebWork Magazin - Webseiten erstellen lassen, Online Medien, html

Webhoster, Webhosting Provider und Domain registrieren

Home | Registrieren | Einloggen | Suchen | Aktuelles | GSL-Webservice | Suleitec Webhosting
Reparatur-Forum | Elektro forum | Ersatzteilshop Haushalt und Elektronik


Homepage und Webhosting-Forum

Scripte und Programme für PHP, MYSQL. Diskussionen zur Programmierung im Web. Fragen zu CMS, Blogsoftware, Shops, Newsletter und vielen weiteren Scripten.


Forum » PHP & MySQL » autofill user bei bestellung » Antworten
Benutzername:
Passwort: Passwort vergessen?
Inhalt der Nachricht: Fett | Kursiv | Unterstrichen | Link | Bild | Smiley | Zitat | Zentriert | Quellcode| Kleiner Text
Optionen: Emailbenachrichtigung bei Antworten
 

Die letzten 5 Postings in diesem Thema » Alle anzeigen
von Torfu
danke vielmals
von chip
Da du die entsprechende Variable in der Session registrierst
1:
session_register("myusername");

kannst du sie in den übrigen Scripts über
1:
$_SESSION['myusername']

wieder auslesen.
von Torfu
Hi,

mein problem ist:
ich habe ein loginscript, welches hervorragend funktioniert.
Jedoch will ich bei einer Bestellung, dass sich der username automatisch ausfüllt. 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 Einlogen ist.
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28:
<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:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41:
<?php
$host="localhost"; // Host name
$username="dbuser"; // 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");

}
else {
echo "Wrong Username or Password";
}
?>


login_success.php

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13:
<?
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:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82:
<?
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 = $_POST["myusername"];
  $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

Nach oben