Hi I hope you are well? I took my name Victor, I am 22 years in first year of the BTS in Computer Network and Telecom. To practice I created a website in php but I have trouble with my database. The liason is there but I can not connect or open an account. At first I use MYSQL and when I proceed to the user account login I encounter a problem that I am advised to use MYSQLI or PDO for my database:
( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wamp64wwwnewcoredatabaseconnect.php on line 8
I tried but no change. I do not know what approach to use. If you please, I will send you the site in compressed form by your email so that you can help me. My email is traoregeeker@gmail.com.
$query = $mysqli->query("SELECT * FROM users WHERE username = '$username'");
if(empty($username) OR empty($email) OR empty($password) OR empty($cpassword) OR empty($gender)){ $output = "Please Fill in All Fields."; }elseif($query->num_rows != 0){
$output = "that username already Taken."; }elseif ($cpassword !=$password) { $output = "Youre password Do'nt Match."; }elseif (strlen($password) < 6) { $output = "Youre password must be at least 5 characters."; }else{ //Encryption Password $password =md5($password); //insert the record $insert = $mysqli->query("SELECT INTO users (username,email,password,gender) VALUES('$username','$email','$password','$gender')"); if ($insert != TRUE){ $output = "There Was a Problem <br />."; $output .= $mysqli->error; }else{ $output = "You Have Been Registred!"; }
I would like to take this opportunity to highly appreciate and thank you for the wonderful work. i finally understood what i have been trying to understand for awhile. i would like to contact u directly for future questions i might be having.
When i reload the page it will automatically inserted last input data in the database. If i reload again then it will again inserted last input data. Also if i put new data then it inserted the current new data. again after inserted new data if i reload the page (without giving nothing in the input field) then it automatically inserted last new data.
student_name student_city DON india DON india (same data )
code:
<html> <head> <title>insert data in database using mysqli</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <form id="form1" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>"> <label>Student Name :</label> <input type="text" name="stu_name" id="name" required="required" placeholder="Please Enter Name"/><br /><br />
<label>Student City :</label> <input type="text" name="stu_city" id="city" required="required" placeholder="Please Enter Your City"/><br/><br />
Thank you so much, you're such a great teacher. Your videos are really easy to follow. I said thank you in another video, but this was an awesome breakdown.
15 responses to “PHP MySQLi Registration Tutorial”
Top video thanx…. one question… how can i build in a email confirmation into?
Hi I hope you are well?
I took my name Victor, I am 22 years in first year of the BTS in Computer Network and Telecom.
To practice I created a website in php but I have trouble with my database. The liason is there but I can not connect or open an account.
At first I use MYSQL and when I proceed to the user account login I encounter a problem that I am advised to use MYSQLI or PDO for my database:
( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wamp64wwwnewcoredatabaseconnect.php on line 8
I tried but no change. I do not know what approach to use. If you please, I will send you the site in compressed form by your email so that you can help me. My email is traoregeeker@gmail.com.
Thank you
thank you so much you helped me a lot man.. keep it up
thank you sir
Not Work for me <?php
$output = NULL;
if (isset($_POST['submit'])){
//connect to database a habibi
$mysqli = NEW MySQLi('localhost','root','','socres');
$username = $mysqli->real_escape_string($_POST['username']);
$email = $mysqli->real_escape_string($_POST['email']);
$password = $mysqli->real_escape_string($_POST['password']);
$cpassword = $mysqli->real_escape_string($_POST['cpassword']);
$gender = $mysqli->real_escape_string($_POST['gender']);
$query = $mysqli->query("SELECT * FROM users WHERE username = '$username'");
if(empty($username) OR empty($email) OR empty($password) OR empty($cpassword) OR empty($gender)){
$output = "Please Fill in All Fields.";
}elseif($query->num_rows != 0){
$output = "that username already Taken.";
}elseif ($cpassword !=$password) {
$output = "Youre password Do'nt Match.";
}elseif (strlen($password) < 6) {
$output = "Youre password must be at least 5 characters.";
}else{
//Encryption Password
$password =md5($password);
//insert the record
$insert = $mysqli->query("SELECT INTO users (username,email,password,gender) VALUES('$username','$email','$password','$gender')");
if ($insert != TRUE){
$output = "There Was a Problem <br />.";
$output .= $mysqli->error;
}else{
$output = "You Have Been Registred!";
}
}
}
?>
Thanks alot
Thank you! 🙂
I would like to take this opportunity to highly appreciate and thank you for the wonderful work. i finally understood what i have been trying to understand for awhile.
i would like to contact u directly for future questions i might be having.
"Parse error: syntax error, unexpected 'if' (T_IF) in C:xampphtdocsloginregisterindex.php on line 17"
i got this error, help?
the md5 encryption doesnt work for me :((((( i
When i reload the page it will automatically inserted last input data
in the database. If i reload again then it will again inserted last
input data. Also if i put new data then it inserted the current new
data. again after inserted new data if i reload the page (without
giving nothing in the input field) then it automatically inserted last
new data.
student_name student_city
DON india
DON india (same data )
code:
<html>
<head>
<title>insert data in database using mysqli</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form id="form1" method="post" action="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<label>Student Name :</label>
<input type="text" name="stu_name" id="name" required="required"
placeholder="Please Enter Name"/><br /><br />
<label>Student City :</label>
<input type="text" name="stu_city" id="city" required="required"
placeholder="Please Enter Your City"/><br/><br />
<input type="submit" name="submit" id="submit" value="Submit Data" /><br />
</form>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit']))
{
//$name = $email = $city = "";
$name= ($_POST['stu_name']);
$city= ($_POST['stu_city']);
echo "$name" . "<br/>";
echo "$city" . "<br/>";
$sql = "INSERT INTO students (student_name, student_city) VALUES
('$name','$city')";
echo "$sql";
if (mysqli_query($conn,$sql))
{
echo "<br/> " . "<br/> " . "<br/> " . "New record created
successfully";
//header('Location:example1.php?msg=success');
exit;
}
else
{
//echo "<br/> " . "<br/> " . "<br/> " . "Not successfull";
header('Location:example1.php');
exit;
}
//mysqli_free_result($sql);
}
$conn->close();
?>
</body>
</html>
please help me —-i dont want want to redirect the page to other page…….for processing……
Thanks, I've watched 20 tutorials and this is the only good one with clear instructions!
Before you get too far along, I made an error. It's really REAL_ESCAPE_STRING
Thank you so much, you're such a great teacher. Your videos are really easy to follow. I said thank you in another video, but this was an awesome breakdown.
Thank you so much!