- Joined
- Aug 21, 2023
- Messages
- 40
- Reaction score
- 0
Hello there,
Again I have some issues with the final chapter of Learn PHP, MySQL and Javascript book. I'm moving forward thanks to your advices. I finally can open the index.php site. It looks nice. But now I have a problem with signup. When I enter a name and password I get the message "Error loading page" and the 500 Internal Server error. I opened the developer tools error console and it shows me this:
This is the checkuser.php :
and the signup.php :
If anybody knows how to fix this it would be helpful?
Thanks
Again I have some issues with the final chapter of Learn PHP, MySQL and Javascript book. I'm moving forward thanks to your advices. I finally can open the index.php site. It looks nice. But now I have a problem with signup. When I enter a name and password I get the message "Error loading page" and the 500 Internal Server error. I opened the developer tools error console and it shows me this:
This is the checkuser.php :
PHP:
<?php // Example 06: checkuser.php
require_once 'functions.php';
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$result = queryMysql("SELECT * FROM members WHERE user='$user'");
if ($result->rowCount())
echo "<span class='taken'> ✘ " .
"The username '$user' is taken</span>";
else
echo "<span class='available'> ✔ " .
"The username '$user' is available</span>";
}
?>
and the signup.php :
PHP:
<?php // Example 05: signup.php
require_once 'header.php';
echo <<<_END
<script>
function checkUser(user)
{
if (user.value == '')
{
$('#used').html(' ')
return
}
$.post
(
'checkuser.php',
{ user : user.value },
function(data)
{
$('#used').html(data)
}
)
}
</script>
_END;
$error = $user = $pass = "";
if (isset($_SESSION['user'])) destroySession();
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
$error = 'Not all fields were entered<br><br>';
else
{
$result = queryMysql("SELECT * FROM members WHERE user='$user'");
if ($result->rowCount())
$error = 'That username already exists<br><br>';
else
{
queryMysql("INSERT INTO members VALUES('$user', '$pass')");
die('<h4>Account created</h4>Please Log in.</div></body></html>');
}
}
}
echo <<<_END
<form method='post' action='signup.php?r=$randstr'>$error
<div data-role='fieldcontain'>
<label></label>
Please enter your details to sign up
</div>
<div data-role='fieldcontain'>
<label>Username</label>
<input type='text' maxlength='16' name='user' value='$user'
onBlur='checkUser(this)'>
<label></label><div id='used'> </div>
</div>
<div data-role='fieldcontain'>
<label>Password</label>
<input type='text' maxlength='16' name='pass' value='$pass'>
</div>
<div data-role='fieldcontain'>
<label></label>
<input data-transition='slide' type='submit' value='Sign Up'>
</div>
</div>
</body>
</html>
_END;
?>
If anybody knows how to fix this it would be helpful?
Thanks