简体   繁体   中英

how to store data in mysql with php

So, i just started learning php and I can't figure out what I doing wrong, data doesn't register to database on mysql. I am using xampp. All names and data are written right. I checked all functions... Still doesn't work.

 <DOCTYPE html> <html> <head> <title>New Account</title> </head> <body> <?php /* Implementare: -functie de verificare daca functia exista in baza de date -function bool_email($POST_('email adress')) -functie comparare stringuri */ $name = ''; $password = ''; $gender = ''; $email = ''; $tc = ''; if(isset($_POST['submit'])) { $ok = true; if(!isset($_POST['name']) || $_POST['name'] === '' /*bool_name_exist($the string)*/) { $ok = false; printf("You forget about name or it exist already in the database!"); echo '<br>'; } else { $name = $_POST['name']; } if(!isset($_POST['password']) || $_POST['password'] === '' ) { $ok = false; printf('You forget about password!'); echo '<br>'; } else { $password = $_POST['password']; } if(!isset($_POST['password_conf']) || $_POST['password_conf'] === '' || strcmp($_POST['password'], $_POST['password_conf']) != 0) { $ok = false; printf('You forget about password or password conf. does not match!'); echo '<br>'; } if(!isset($_POST['email']) || $_POST['email'] === '' /*functie care verifica daca emailul e valid sau este in baza de date*/) { $ok = false; printf('You forget about email or your email address is not validate!'); echo '<br>'; } else { $email = $_POST['email']; } if(!isset($_POST['gender']) || $_POST['gender'] === '') { $ok = false; printf('You forget about gender!'); echo '<br>'; } else { $gender = $_POST['gender']; } if(!isset($_POST['tc']) || $_POST['tc'] === '') { $ok = false; printf('You need to validate t&c!'); echo '<br>'; } else { $tc = $_POST['tc']; } if($ok === true) { printf('your account has been registered'); } if($ok) { $db = mysqli_connect('localhost', 'root', '', 'platformaworkout'); $sql = sprintf("INSERT INTO registerdata (Name, Gender, Password, Email), VALUES ('%s', '%s', '%s', '%s') ", mysqli_real_escape_string($db, $name), mysqli_real_escape_string($db, $gender), mysqli_real_escape_string($db, $password), mysqli_real_escape_string($db, $email)); printf('<br>%s', $sql); if(mysqli_query($db, $sql)) { echo '<br>it work'; }else { echo '<br>I want to kill myself...'; } mysqli_close($db); echo '<p>user added</p>'; } } ?> <form method="post" action=""> <header>Register new account:<br></header> UserName:<input type="text" name="name" value="<?php echo htmlspecialchars($name); ?>"><br> Password:<input type="password" name="password" value="<?php echo htmlspecialchars($password); ?>"><br> Password confirmation:<input type="password" name="password_conf"><br> Gender: <input type="radio" name="gender" value="f" <?php if($gender === 'f'){echo 'checked';}?>>female <input type="radio" name="gender" value="m" <?php if($gender === 'm'){echo 'checked';}?>>male<br> Email Address:<input type="text" name="email" value="<?php echo htmlspecialchars($email); ?>"><br> <input type="checkbox" name="tc" value="ok" <?php if($tc === 'okay'){echo 'checked';}?>>I accept t&c!<br> <a src="#">Read t&c!</a> <input type="submit" name="submit" value = "submit"> </form> </body> </html> 

What I see in the browser My database structure

也许您忘记了动作部分:

 <form method="post" action="echo $_SERVER['PHP_SELF'];">

INSERT INTO registerdata (Name, Gender, Password, Email), VALUES ('jarlio', 'm', 'leaf', 'somemail@gmail.com') , is not a correct command in sql because of that "," before "VALUES". Find it, thanks for help anyway

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM