r/PHPhelp • u/Destrudooo • Jan 10 '25
Solved Error in php code ...I'm beginner
Here is the code , and thanks in advance.
protected function setUser($uid,$pwd,$email){
$this->connect()->prepare('INSERT INTO users ( users_uid , users_pwd , users_email) VALUES ( ? , ? , ? ) ');$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
if (!$stmt->execute(array($uid,$email,$hashedPwd)){
$stmt = null ; header("location: ../index.php?error=stmtfailed") ; exit();
} }
The Error
Parse error: syntax error, unexpected ';' in C:\Program Files\Ampps\www\projectxxx\classes\signup.classes.php on line 17
4
Upvotes
6
u/[deleted] Jan 10 '25
Fix :
if (!$stmt->execute(array($uid,$email,$hashedPwd))){if (!$stmt->execute(array($uid,$email,$hashedPwd))){')' is missing
3
u/NahidasDookie Jan 10 '25
You're missing a closing bracket ) in the if statement
2
u/colshrapnel Jan 10 '25 edited Jan 10 '25
Actually, there must be not a single if statement in this code.
It seems you are using a video from infamous impostor, Danny Krossing. Be advised that his code makes no sense. Doing a redirect amidst of database interaction is totally wrong. Besides, in the modern PHP this if statement will never be fired anyway. Your function should be executed without if or redirect:
Edit: code edited as per u/eurosat7 suggestion.
1
u/eurosat7 Jan 10 '25
Also watch the order! You switched the hashed password and email in execute(). Better use named placeholders to avoid order issues.
1
u/allen_jb Jan 10 '25
It may help you to use short array syntax -
[]rather thanarray(). This makes arrays visually distinct from other uses of(), which can make counting brackets easier. See https://www.php.net/manual/en/language.types.array.php#example-58Another solution would be to declare the placeholder list using a variable:
1
u/istifano Jan 11 '25
You're missing a closing bracket ) in the if statement
1
u/FluffyDiscord Jan 12 '25
You should really install PHPStorm or VSCode with PHP extension that will yell at you that you are missing a bracket or so. Don't code blind, when theres a smarter way ;)
1
u/flyingron Jan 13 '25
You'll find that some of the syntax-aware editors will help you find these mismatches. They can go anywhere from emacs's php-mode to full up IDEs like PHPStorm.
1
u/ALameLlama Jan 10 '25
Missing a
)on this line at the ende.g
edit: I also really hope that password is hashed and not just raw dogged into the db