Zdravim,
s php som amater a mam jeden problem. Mam takyto formular:
Spravnost udajov kontrolujem javascriptom. Ale ak sa chce zaregistrovat niekto a zada uz existujuce meno tak to kontrolujem cez php + mysql. Ak zadane meno uz existuje vypise echo nejake hlasenie.
Ako dosiahnem aby sa to hlasenie vypisalo takto?
Predpokladam ze to bude len nejaka podmienka pre DIV-om ktory chcem vypisat ale zatial mi nic nefungovalo. Za ochotu a pomoc vopred velmi pekne dakujem.
Pripajam aj zdrojovy kod:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<link href="style/index_default.css" media="all" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="js/script.js"></script>
<title></title>
</head>
<body>
<div class="buttons">
<ul>
<li><a href="index.php">HOME</a></li>
<li><a href="about.php">ABOUT</a></li>
<li><a href="login.php">LOGIN</a></li>
<li><a href="sign.php" class="buttons_selected">SIGN IN</a></li>
</ul>
</div>
<div class="error_msg">
Username taken
</div>
<div class="middle">
<h3>Complete the sign in, please.</h3>
<form method="post" action="sign.php" name="sign" class="sign" onsubmit="return control_sign();">
<p class="content" align="center">
<label for="usr">Username: </label>
<input style="margin-left: 57px;" type="text" size="30" id="usr" name="usr" /><br /><br />
<label for="passwd">Password: </label>
<input style="margin-left: 61px;" type="password" size="30" id="passwd" name="passwd" /><br /><br />
<label for="conf_passwd">Cofirm Password: </label>
<input style="margin-left: 15px;" type="password" size="30" id="conf_passwd" name="conf_passwd" /><br /><br />
<label for="email">E-mail: </label>
<input style="margin-left: 82px;" type="text" size="30" id="email" name="email" /><br /><br />
<input id="log_button" type="submit" value="SIGN IN" />
</p>
</form>
</div>
<?php
$link = mysql_connect("localhost", "root", "root") or die("Could not connect");
mysql_select_db("calendar") or die("Couldn't select db");
if (isset($_POST['usr']) && isset($_POST['passwd']) && isset($_POST['conf_passwd']) && isset($_POST['email']) && ($_POST['passwd'] == $_POST['conf_passwd']))
{
$username = mysql_real_escape_string($_POST['usr']);
$email = mysql_real_escape_string($_POST['email']);
$password = md5($_POST['passwd']);
$result = mysql_query("SELECT user_name FROM user WHERE user_name = '".$username."'");
if (mysql_num_rows($result))
{
die("<div class=pop>Username taken</div>");
}
mysql_query("INSERT INTO user (user_name, passwd, email) VALUES('$username', '$password', '$email')") or die (mysql_error());
echo "<div class=pop>Account created</div>";
}
mysql_close($link);
?>
</body>
</html>