$dbcnx = @mysql_connect(‘localhost’, ‘sura’, ‘lionlion’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the ’ .
‘database server at this time.</p>’);
}
// Select the jokes database
if (!@mysql_select_db(‘form’)) {
exit(’<p>Unable to locate the form ’ .
‘database at this time.</p>’);
}
// add it to the database.
if (isset($_POST[‘username’])) {
$username = $_POST[‘username’];
$sql = “INSERT INTO form SET
username=‘$username’,
password=‘password’”;
if (@mysql_query($sql)) {
echo ‘<p>Your username has been added.</p>’;
} else {
echo '<p>Error adding submitted joke: ’ .
mysql_error() . ‘</p>’;
}
$username=$_POST[‘username’]; //pretty sure POST has to be capital - I could be wrong though
$password=$_POST[‘password’];
if ($username==“dina” && $password==“lion”) { //no need for extra brackets inside unless you want to group logic together
echo “ok you can acsess!”;
}
else {
echo ‘<p> denied </p>’;
}
Meanwhile, these are the problems that I notice with the above code.
[list][]Missing xhtml doctype (assuming xhtml from structure of input elements)
[]HTML tags should normally be in lowercase
[]form action is for tes.php - should that be test.php ?
[]form elements need to be contained within block-level elements, for unstyled compatibility. Wrap them with paragraph tags instead.
[]inappropriate break elements. use them only with poetry and addresses
[]password isn’t retrieved from form, or set correctly in the sql statement[/list]
I copied and pasted your code into Firefox and an error showed with Missing closing brace.
Here is the amended code with some additions and corrections:
<!Doctype html5>
<html>
<head>
<title>New Document</title>
<style type='text/css'>
fieldset {width:42%; margin:2em auto; background:#dff none; color:#00f}
</style>
</head>
<body>
<form action="tes.php" method="post">
<fieldset'>
<legend>New Document </legend>
<label>userName: </label>
<input type="text" name="username" /><br />
<label>password: </label>
<input type="text" name="password" /><br />
<input type="submit" value="SUBMIT" />
</fieldset>
</form>
<?php
$dbcnx = @mysql_connect('localhost', 'sura', 'lionlion');
if (!$dbcnx)
{
exit('<p>Unable to connect to the ' . 'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('form'))
{
exit('<p>Unable to locate the form ' .'database at this time.</p>');
}
// add it to the database.
if (isset($_POST['username']))
{
$username = $_POST['username'];
$sql = "INSERT INTO form SET
username='$username',
password='password'";
if (@mysql_query($sql))
{
echo '<p>Your username has been added.</p>';
} else {
echo '<p>Error adding submitted joke: ' .
mysql_error() . '</p>';
}
$username=$_POST['username']; //pretty sure POST has to be capital - I could be wrong though
$password=$_POST['password'];
if ($username=="dina" && $password=="lion") { //no need for extra brackets inside unless you want to group logic together
echo "ok you can acsess!";
} else {
echo '<p> denied </p>';
}
}// missing closing brace
?>
</body>
</html>