I have a HTML form that stores the information on a MySQL database. It works! But I want an only file that do all with PHP extension. I filled the database when clicking on the button but turn to deploy a PHP file, and I do not want that to happen.
Here is my HTML code:
<html>
<head></head>
<body>
<form id="form" name="form" action="insert.php" method="POST">
<label id="lbluser">Name:</label>
<input type="text" name="name" id="name" /><br/>
<label id="lbllastaname">Lastname:</label>
<input type="text" name="lstname" id="lstname" /><br/>
<label id="lblmail">E-mail:</label>
<input type="text" name="email" id="email" /><br/>
<label id="lblpassword">Password:</label>
<input type="password" name="password" id="password" /><br/>
<label id="lblpassword">Repeat password:</label>
<input type="password" name="passwordr" id="passwordr" /><br/>
<button type=”submit” name=”button” value=”insert”>OK</button>
</form>
</body>
</html>
And this is my PHP code:
<?php
$mysqli = mysqli_connect("localhost", "user", "12345", "own_bd");
if (mysqli_connect_errno()) {
printf("Problem with connection: %s\n", mysqli_connect_error());
exit();
}
else {
$var_name = mysqli_real_escape_string($mysqli, $_POST['name']);
$var_lst = mysqli_real_escape_string($mysqli, $_POST['lstname']);
$var_mail = mysqli_real_escape_string($mysqli, $_POST['email']);
$var_pwd = mysqli_real_escape_string($mysqli, $_POST['password']);
$var_pwdr = mysqli_real_escape_string($mysqli, $_POST['passwordr']);
$sql = "INSERT INTO users_tbl (Name,Lastname,Mail,Pwd,PwdR) VALUES ('".$var_name."','".$var_lst."','".$var_mail."','".$var_pwd."','".$var_pwdr."')";
$res = mysqli_query($mysqli, $sql);
if ($res === TRUE) {
echo "User added.";
}
else {
printf("Error: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
?>
How I do it? I hope your help.
isset function doesn't work for me in this script, but if I try this code, it works!
<form action="" method="post">
<input type="submit" value="Click" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Help!!!