/ / PHP HTML MYSQL versucht, eine bestimmte Zeile der Datenbank zu aktualisieren, nachdem der Benutzer die Registrierungsdetails eingegeben hat - php, html, mysql

PHP HTML MYSQL versucht eine bestimmte Zeile der Datenbank zu aktualisieren, nachdem der Benutzer die Registrierungsdetails eingegeben hat - php, html, mysql

Ich entwerfe eine Website, auf der Imker leben könnenRegistrieren Sie dort Shop-Details auf einer Website und nachdem sie ihre Informationen in der Datenbank registriert haben, werden sie eingeloggt und dann zur Account-Management-Seite weitergeleitet, wo sie ihre Daten ändern können, wenn sie wollen.

Ich habe ein Problem, wo nach dem Benutzer hatDort werden Details eingegeben, die Website wird an das Registerskript geleitet, das den Benutzer und seine Details zur Datenbank hinzufügt und sie dann zu einem Anmeldeskript bringt, um sie über den Eintrag in die gerade hinzugefügte Datenbank einzuloggen. Es bleibt jedoch nur im Skript registerlogin hängen (fügt aber immer noch den neuen Benutzer hinzu). Es fügt sie hinzu, meldet sie aber nicht danach an.

Ich kann sie über eine Login-Seite anmeldenwas sie nach einer erfolgreichen Anmeldung auf die Kontoverwaltungsseite leitet, habe ich ähnlichen Code aus dem Login-Skript im Skript registerlogin verwendet.

Kann jemand sehen, was ich falsch gemacht habe?

Registerseite (Benutzerseite):

<?php
session_start();
?>
<html>
<head>
<title>Beekeeper</title>
<meta name="author" content="Nigel Kennington">
<meta name="description" content="Find local honey near you">
<meta name="keywords" content="honey, bees, bee, local">
<link href="bees.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="linkbar">
<table height="140px" ID="Table1">
<tr>
<td valign="bottom"><a href="index.html">Home</a>&nbsp;&nbsp;|</td>
<td valign="bottom"><a href="about.html">About</a>&nbsp;&nbsp;|</td>
<td valign="bottom"><a href="contact.html">Contact</a></td>
</tr>
</table>
</div>

<div id="bulk">
<table width="100%" border="0" cellpadding="0" cellspacing="0" ID="Table1">
<tr id="spacer">
<td class="leftnav" align="right" valign="top" nowrap width="120px">
<h5>Find Honey from:</h5>
<p><a href="#">Highlands and Islands</a></p>
<p><a href="#">North Eastern Scotland</a></p>
<p><a href="#">Eastern Scotland</a></p>
<p><a href="#">South Western Scotland</a>
<h5>List your produce:</h5>
<p><a href="keeperlogin.php">Keepers Page</a></p>
<p>Register</p>
</td>
<td>
<p class="first">To get a free account and start advertising your produce here, fill in the information below:</p>
<p>If you already have an account, you can login by clicking on the "Keepers Page" link on the left hand side.</p>



<fieldset>
<?php
$fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if (strpos($fullUrl, "signup=empty") == true)
{
echo "<p class="error" >You did not fill in all fields,
please check you have filled all fields out!</p>";
//exit();
}
elseif (strpos($fullUrl, "signup=passwordnotmatch") == true)
{
echo "<p class="error">Passwords entered do not match!</p>";
//exit();
}
elseif (strpos($fullUrl, "signup=bothnumbersnotentered") == true)
{
echo "<p class="error">You must enter at least one phone number!</p>";
//exit();
}
elseif (strpos($fullUrl, "signup=usertaken") == true)
{
echo "<p class="error">User is already on the system!</p>";
//exit();
}
elseif (strpos($fullUrl, "signup=success") == true)
{
echo "<p class="success">You have been signed up!</p>";
//exit();
}
?>
<form method="POST" action="register.php">
<table border=0 id="flush">
<tr>
<td width="50"></td>
<td colspan="2"><div class="heading">About You</div></td>
</tr>
<tr>
<td width="50"></td>
<td>Your Name:</td>
<td><input type="text" name="keepername" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Password:</td>
<td><input type="password" name="password" size="16"></td>
</tr>
<tr>
<td width="50"></td>
<td>Re-enter Password:</td>
<td><input type="password" name="password2" size="16"></td>
</tr>
<tr>
<td width="50"></td>
<td>Your E-mail:</td>
<td><input type="text" name="accountemail" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td colspan="2"><div class="heading">About your produce</div></td>
</tr>
<tr>
<td width="50"></td>
<td>Shop Name:</td>
<td><input type="text" name="shopname" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Area:</td>
<td>
<input type="radio" name="area" value="HaI"> Highlands and Islands<br>
<input type="radio" name="area" value="NES"> North Eastern Scotland<br>
<input type="radio" name="area" value="ES"> Eastern Scotland<br>
<input type="radio" name="area" value="SWS"> South Western Scotland
</td>
</tr>
<tr>
<td width="50"></td>
<td>Address:</td>
<td><textarea rows="2" name="address" cols="27"></textarea></td>
</tr>
<tr>
<td width="50"></td>
<td>Town/City:</td>
<td><input type="text" name="town" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Postcode:</td>
<td><input type="text" name="postcode" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Phone Number:</td>
<td><input type="text" name="landline" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Mobile Number:</td>
<td><input type="text" name="mobile" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Shop E-mail:</td>
<td><input type="text" name="shopemail" size="32"></td>
</tr>
<tr>
<td width="50"></td>
<td>Describe your produce:</td>
<td><textarea rows="4" name="description" cols="27"></textarea></td>
</tr>
<tr>
<td width="50"></td>
<td></td>
<td><input type="submit" name="submit" value="Register"></td>
</tr>
</table>
</fieldset>
</form>
</td>
<td valign="top" align="right">
<img src="/images/gfx/register.jpg" alt="honey pots" class="imgborder">
</td>
</tr>
</table>
</div>

<div id="footer">
© 2008 beekeeper.com | <A href="privacy.html">Privacy Policy</A> |
<A href="terms.html">Terms of Use</A>
</div>

</body>

Registrierungsskript (Serverseite):

<?php

session_start();

/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user "root" with no password) */
$link = mysqli_connect("localhost", "root", "root") or die(mysqli_error($db));
mysqli_select_db($link, "keepers")
or die(mysqli_error($link));

// Check connection
if($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
if (isset($_POST["submit"]))
{
$name = mysqli_real_escape_string($link, $_REQUEST["keepername"]);
$password = mysqli_real_escape_string($link, $_REQUEST["password"]);
$password2 = mysqli_real_escape_string($link, $_REQUEST["password2"]);
$email = mysqli_real_escape_string($link, $_REQUEST["accountemail"]);
$shop = mysqli_real_escape_string($link, $_REQUEST["shopname"]);
$area = mysqli_real_escape_string($link, $_REQUEST["area"]);
$address = mysqli_real_escape_string($link, $_REQUEST["address"]);
$town = mysqli_real_escape_string($link, $_REQUEST["town"]);
$postcode = mysqli_real_escape_string($link, $_REQUEST["postcode"]);
$landline = mysqli_real_escape_string($link, $_REQUEST["landline"]);
$mobile = mysqli_real_escape_string($link, $_REQUEST["mobile"]);
$shopemail = mysqli_real_escape_string($link, $_REQUEST["shopemail"]);
$description = mysqli_real_escape_string($link, $_REQUEST["description"]);


//Error Handlers
//Check for empty fields
if (empty($name) || empty($password) || empty($email) || empty($shop) ||
empty($area) || empty($address) || empty($town) || empty($postcode) ||
empty($shopemail) || empty($description))
{
header("Location: keeperregister.php?signup=empty");
exit();
}
else
{
if ($password != $password2)
{
header("Location: keeperregister.php?signup=passwordnotmatch");
exit();
}
else
{
if (empty($landline) && empty($mobile))
{
header("Location: keeperregister.php?signup=bothnumbersnotentered");
exit();
}
else
{
$sql = "SELECT * FROM keepers WHERE keeper_email = "$email"";
$results = mysqli_query($link, $sql) or die (mysqli_error($link));
$resultCheck = mysqli_num_rows($results);

if ($resultCheck > 0)
{
header("Location: keeperregister.php?signup=usertaken");
exit();
}
else
{
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
//Insert the user into the database
$sqlinsert = "INSERT INTO keepers VALUES ("NULL","$name", "$hashedPwd", "$email", "$shop", "$area" ,"$address" ,"$town" ,"$postcode" ,"$landline" ,"$mobile" ,"$shopemail", "$description")";
if(mysqli_query($link, $sqlinsert))
{
header("Location: registerlogin.php?");
exit();
}
else
{
echo "ERROR: Could not able to execute $sqlinsert. " . mysqli_error($link);
}
}
}

}
}

// close connection
mysqli_close($link);
}
else
{
header("Location: keeperregister.php");
exit();
}

registerlogin Skript (serverseitig):

<?php

session_start();

if (isset($_POST["submit"]))
{
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user "root" with no password) */
$link = mysqli_connect("localhost", "root", "root") or die(mysqli_error($db));
mysqli_select_db($link, "keepers")
or die(mysqli_error($link));

// Check connection
if($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}

$name = mysqli_real_escape_string($_POST["keepername"]);
//$password = mysqli_real_escape_string($link, $_REQUEST["password"]);


$sql = "SELECT * FROM keepers WHERE keeper_name = "$name"";
$result = mysqli_query($link, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 1)
{
header("Location: keeperlogin.php?login=error");
exit();
}
else
{
if ($row = mysqli_fetch_assoc($result))
{
//Log in the user here
$_SESSION["u_id"] = $row["ID"];
$_SESSION["u_name"] = $row["keeper_name"];
$_SESSION["u_keeperemail"] = $row["keeper_email"];
$_SESSION["u_shopname"] = $row["shop_name"];
$_SESSION["u_area"] = $row["area"];
$_SESSION["u_address"] = $row["address"];
$_SESSION["u_town"] = $row["town/city"];
$_SESSION["u_postcode"] = $row["postcode"];
$_SESSION["u_landline"] = $row["phone number"];
$_SESSION["u_mobile"] = $row["mobile number"];
$_SESSION["u_shopemail"] = $row["shop_email"];
$_SESSION["u_produce"] = $row["produce"];
header("Location: accountmanagement.php?login=success");
exit();

}
else
{
header("Location: keeperlogin.php?login=error");
exit();
}


}

}
?>

Antworten:

0 für die Antwort № 1

Bei erfolgreicher Registrierung geben Sie keine a $_POST Wert wie in registerlogin.php benötigt. Eher, als $_POST du solltest es besser gebrauchen $_SESSION stattdessen. Änderungen unten.

In register.php:

Gleich darüber:

header("Location: registerlogin.php?");

Hinzufügen:

$_SESSION["keeper_name"] = $name;

In registerlogin.php:

Ersetzen:

isset($_POST["submit"])

Mit:

isset($_SESSION["keeper_name"]) AND $_SESSION["keeper_name"] != ""

Ersetzen:

$name = mysqli_real_escape_string($_POST["keepername"]);

Mit:

$name = mysqli_real_escape_string($_SESSION["keeper_name"]);