Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
am trying to create a website and trying to get data into the database after clicking the submit button .

i have three text field on the webpage their names are
.UName
.EnterEmail
.passwordsignuptextbox

and the button name is
.signupbutton

my goal is after clicking the signupbutton it send the data which is in the three text field into the database .so far this is my php code


include_once 'db_connect.php';

if(isset ($_POST['signupbutton'])) {
$uname= $_POST['UName'];
$email= $_POST['EnterEmail'];
$password=$_POST['passwordsignuptextbox'];


if (mysqli_query($conx , "INSERT INTO registration ( UserName, Email,user_password)"
. "VALUES( $uname,$email,$password)" ))

echo "inserted okay";
else {
echo " erros upon inserting data";
}



mysqli_close($conx);
}

?>

i keep on getting errors please help
Posted
Comments
Peter Leow 12-Feb-14 6:27am    
Show your code for the form. Is there a '.' before "VALUES...?
EZW 13-Feb-14 4:02am    
No, he is just appending a second string to the first VIA a dot
sean871 14-Feb-14 13:04pm    
yes there is a '.' before VALUES
EZW 13-Feb-14 4:00am    
What do the errors say that you are getting?
sean871 14-Feb-14 13:11pm    
erros upon inserting data.

You should not be injecting user's inputs directly into any sql statement, that makes your application vulnerable to SQL Injection[^].
Change your sql statement to a prepared statement like this:
SQL
$sql = "INSERT INTO registration UserName, Email, user_password) VALUES (?, ?, ?)";

if (!($stmt = $mysqli->prepare($sql))) {
    die("Prepare failed: ".$mysqli->errno);
}

if (!$stmt->bind_param('sss', $uname, $email, $password)){
    die("Binding parameters failed: ".$stmt->errno);
}

if (!$stmt->execute()) {
    die("Insert registration table failed: ".$stmt->errno);
}
 
Share this answer
 
v2
In your <form> tag, you have a action..

HTML
<form action="yourphpfile.php" method="POST">
  <input type="text" name="UName" />
  <input type="email" name="EnterEmail" />
  <input type="password" name="passwordsignuptextbox" />
  <button type="submit">Send</button>
</form>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900