I'm having trouble with data not saving to a table, I've got the following code in a file called Register.php, I have enabled error_reporting to see any errors, but none are showing. My database is called Registration and the table is called users and is being hosted on GoDaddy
<?php
require 'Connections/Connections.php';
?>
<?php
if(isset($_Post['Register'])) {
session_start();
$FName = $_POST['First_Name'];
$LName = $_POST['Last_Name'];
$Username = $_POST['Username'];
$Email = $_POST['Email'];
$PW = $_POST['Password'];
$sql = $con->query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('{$Fname}', '{$LName}', '{$Username}', '{$Email}', '{$PW}')");
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<link href="Style/Master.css" rel="stylesheet" type="text/css" />
<title>Register</title>
</head>
<body>
<form action="" method="post" name="RegisterForm" id="RegisterForm">
<div class="FormElement">
<input name="First_Name" type="text" required="required" class="TField" id="First_Name" placeholder="First Name">
</div>
<div class="FormElement">
<input name="Last_Name" type="text" required="required" class="TField" id="Last_Name" placeholder="Last Name">
</div>
<div class="FormElement">
<input name="Username" type="text" required="required" class="TField" id="Username" placeholder="Username">
</div>
<div class="FormElement">
<input name="Email" type="text" required="required" class="TField" id="Email" placeholder="Email">
</div>
<div class="FormElement">
<input name="Password" type="text" required="required" class="TField" id="Password" placeholder="Password">
</div>
<div class="FormElement">
<input name="Register" type="submit" class="button" id="Register" placeholder="Register">
</div>
</body>
</html>
This is the code in the Connections.php just without my real username and password
<?php
$con = mysql_connect("localhost", "USERNAME", "PASSWORD", "Registration");
?>
Any help would be very much appreciated!
You need to edit the Connection.php
mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("Registration"); //your data base name
And also you have to edit
mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());
Try this
mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());
Related
I have this problem with the submit button in the html form where by when I click it instead of sending the form details to the database it displays the php script in a new window,I've tried everything I could still not working,please help
html code:
<!DOCTYPE html>
<html>
<head>
<title>sign up</title>
<link href="sign in.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<div class="signbox">
<h1>SIGN UP HERE</h1>
<form method="" action="connect.php" method="POST">
<p>First name:</p>
<input type="text" name="firstname" placeholder="enter your first name">
<p>Email address:</p>
<input type="text" name="email" placeholder="enter your email address">
<p>Password:</p>
<input type="password" name="password" placeholder="enter your password">
<p>Confirm password:</p>
<input type="password" name="password2" placeholder="confirm your password">
<input type="submit" value="sign in">
already have an account?login here.
</form>
</div>
</body>
</html>
PHP code:
<?php
$firstname = $_POST['firstname'];
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
//database connection.
$conn = new mysqli('loacalhost','root','','','first_db');
if($conn->connect_error){
die('connection failed : '.$conn->connect_error);
}else{
$stmt = $conn->prepare("insert into users3(firstname, email, password, password2)
values(?, ?, ?, ?)");
$stmt->bind_param("ssss",$firstname, $email, $password, $password2);
$stmt->execute();
echo "registration complete...";
$stmt->close();
$conn->close();
}
?>
In your form tag there are 2 method attributes, should be corrected as;
<form action="connect.php" method="POST">
And also in the php code, mysqli connection should be;
$conn = new mysqli('localhost','root','','first_db');
in which the four parameter are;
$conn= new mysqli("server name","username","password","database name");
My form won't post inserted data into my database, i know this is a very basic problem but I am only just starting to learn to code
connect_to_mysql.php:
<?php
$db_host="localhost";
$db_username="ajamesbird";
$db_pass="";
$db_name="test";
$db_connect = mysql_connect("$db_host","$db_username","$db_pass")or die
("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
?>
login.php
<html>
<?php include "C:\Users\andrew\Documents\Websites\Seller\storescripts\connect_to_mysql.php";?>
<?php
if(isset($_POST['loginform'])){
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$sql = ("INSERT INTO users (id, access_level, username, firstname,
lastname, email, password, dob, date_added, activated)
VALUES ('NULL','NULL','$username','$firstname','$lastname','$email', '$password', '$dob', now(), '0')") or die (mysql_error());
if(!mysql_query($db_connect, $sql)){
die('Error inserting into database');
}
}
?>
<head>
<link href="style/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="login.php" enctype="multipart/form-data" name="loginform" id="loginform" method="post">
<input name="username" type="text" id="username" size="63" class="form-control" value="Username" required/>
<input name="firstname" type="text" id="firstname" size="63" class="form-control" value="First name" required/>
<input name="lastname" type="text" id="lastname" size="63" class="form-control" value="Last name" required/>
<input name="email" type="email" id="email" size="63" class="form-control" value="Email" required/>
<input name="password" type="password" id="password" size="63" class="form-control" value="Password" required/>
<input name="dob" type="text" id="dob" size="63" class="form-control" value="Date of Birth" required/>
<input type="submit" name="button" id="button" size="64" value="Sign Up" />
</form>
</body>
</html>
Thank you in advance
Try to move name="loginform" from and put it in hidden input
<html>
<?php include "C:\Users\andrew\Documents\Websites\Seller\storescripts\connect_to_mysql.php";?>
<?php
if(isset($_POST['loginform'])){
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$sql = ("INSERT INTO users (id, access_level, username, firstname,
lastname, email, password, dob, date_added, activated)
VALUES ('NULL','NULL','$username','$firstname','$lastname','$email', '$password', '$dob', now(), '0')") or die (mysql_error());
if(!mysql_query($db_connect, $sql)){
die('Error inserting into database');
}
}
?>
<head>
<link href="style/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="login.php" enctype="multipart/form-data" method="post">
<input name="username" type="text" id="username" size="63" class="form-control" value="Username" required/>
<input name="firstname" type="text" id="firstname" size="63" class="form-control" value="First name" required/>
<input name="lastname" type="text" id="lastname" size="63" class="form-control" value="Last name" required/>
<input name="email" type="email" id="email" size="63" class="form-control" value="Email" required/>
<input name="password" type="password" id="password" size="63" class="form-control" value="Password" required/>
<input name="dob" type="text" id="dob" size="63" class="form-control" value="Date of Birth" required/>
<input type="submit" name="button" id="button" size="64" value="Sign Up" />
<input type="hidden" name="loginform">
</form>
</body>
</html>
I have a project and in this project, I mast to use the registers. I try to write many user registers but isn't show in the databases. I don't know what is the problem. Please, can you help me?
This is one of them:
form.php
<?php
session_start();
$_SESSION['massage'] = " ";
?>
<html>
<head>
</head>
<body>
<div class="module">
<fieldset>
<legend>Create an account:</legend>
<form class="flp" mathod ="POST" action="Register.php" enctype="multipart/form-data">
<div>
<input type="text" placeholder="User Name" name="username" required />
</div>
<div>
<input type="email" placeholder="Email" name="email" required />
</div>
<div>
<input type="password" placeholder="Password" name="password" required />
</div>
<div>
<input type="password" placeholder="Confrim Password" name="confrimpassword" required />
</div>
<center>
<input type="submit" name="Register" value="Go"/>
</center>
<div>
<?php echo $_SESSION['massage']; ?>
</div>
</fomr>
</fieldset>
</div>
</body>
</html>
Register.php
<?php
session_start();
$_SESSION['massage'] = " ";
//connect to database
$mysqli = new mysqli("localhost", "root", "", "accounts");
if (isset($_POST['Register'])){//to check the button
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['confrimpassword']);
if($password == $password2){
//Create User
$password = md5($_POST['password']);//hash password before storing for security purposes
$sql = "INSERT INTO account (UserName, Email, PassWord) VALUES ('$username', '$email', '$password')";
mysql_query($mysqli, $sql);
}
else
{
$_SESSION['massage'] = "There error!";
}
mysql_close($mysqli);
}
?>
This is the code for saving the information into mysql database from a FORM.
In the HTML section the form is being handled i.e. retrieving required data from user.
In the PHP section storing data has been handled.
But the problem is it doesn't store data.
I'm using XAMPP server.
<html>
<head>
<title>signup</title>
<link rel="stylesheet" href="css/insert.css" />
</head>
<body>
<div class="maindiv">
<!--HTML form -->
<div class="form_div">
<div class="title"><h2>Insert Data In Database Using PHP.</h2> </div>
<form action="signup.php" method="post"> <!-- method can be set POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<br />
<input class="input" type="text" name="name" value="" />
<br />
<label>Email:</label><br />
<input class="input" type="text" name="mail" value="" />
<br />
<label>Phone:</label><br />
<input class="input" type="text" name="phone" value="" />
<br />
<label>Password:</label><br />
<input class="input" type="text" name="pass" value="" />
<br />
<label>Address:</label><br />
<textarea rows="5" cols="25" name="add"></textarea>
<br />
<input class="submit" type="submit" name="submit" value="Insert" />
<?php
//Establishing Connection with Server
$connection = mysql_connect("localhost", "root", "buet2010");
//Selecting Database from Server
$db = mysql_select_db("tanni", $connection);
if(isset($_POST['submit'])){
//Fetching variables of the form which travels in URL
$name = $_POST['name'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$pass = $_POST['pass'];
$add = $_POST['add'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query($db, "INSERT INTO user (name, mail, phone, pass, add)VALUES('$name', '$mail', '$phone', '$pass', '$add')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
//Closing Connection with Server
mysql_close($connection);
?>
</form>
</div>
</div>
</body>
I don't understand what can be the problem.
Thanks all. I got the problem.
Actually the sequence of the column in my database was not matching with the query in php code.
I have solved this by changing the variable sequence in the query which is maintained in the database.
$query = mysql_query("INSERT INTO user (`name`, `mail`, `pass`, `address`, `phone`)VALUES('".$name."', '".$mail."', '".$pass."', '".$address."', '".$phone."')");
Here is the code and it will work for your..
I have passed connection link in your mysql_query. and used PHP_SELF for current page.
<html>
<head>
<title>signup</title>
<link rel="stylesheet" href="css/insert.css" />
</head>
<body>
<div class="maindiv">
<!--HTML form -->
<div class="form_div">
<div class="title"><h2>Insert Data In Database Using PHP.</h2> </div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- method can be set POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<br />
<input class="input" type="text" name="name" value="" />
<br />
<label>Email:</label><br />
<input class="input" type="text" name="mail" value="" />
<br />
<label>Phone:</label><br />
<input class="input" type="text" name="phone" value="" />
<br />
<label>Password:</label><br />
<input class="input" type="text" name="pass" value="" />
<br />
<label>Address:</label><br />
<textarea rows="5" cols="25" name="add"></textarea>
<br />
<input class="submit" type="submit" name="submit" value="Insert" />
<?php
//Establishing Connection with Server
$connection = mysql_connect("localhost", "root", "buet2010");
//Selecting Database from Server
$db = mysql_select_db("tanni", $connection);
if(isset($_POST['submit'])){
//Fetching variables of the form which travels in URL
$name = $_POST['name'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$pass = $_POST['pass'];
$add = $_POST['add'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query($db, "INSERT INTO user (name, mail, phone, pass, add)VALUES('$name', '$mail', '$phone', '$pass', '$add')",$connection);
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
//Closing Connection with Server
mysql_close($connection);
?>
</form>
</div>
</div>
</body>
<!--This is the html form code-->
<div class="modal-body">
<form id="modal-form" accept-charset="UTF-8" method="POST" action="signUp.php" data-remote="true" >
<p><label for="firstName"><small>First Name:</small></label><br />
<input type="text" id="firstName" name="firstName" required="required" /></p><br />
<p><label for ="lastName"><small>Last Name:</small></label><br />
<input type="text" id="lastName" name="lastName" required="required" /></p><br />
<p><label for="email"><small>Email: </small></label><br />
<input type="email" name="email" required="required"/></p><br />
<input id="modal-form-submit" type="submit" name="submit" class="btn btn-success"/>
</form>
`
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
require("includes/config.php");
require("includes/connect.php");
if(isset($_POST['submit'])){
$query="INSERT INTO mb_emaillist (ID, firstName, lastName, email) VALUES (null, '$firstName', '$lastName', '$email')";
$result=mysqli_query($db, $query);
if(!$result)
die("SELECT error: " .mysqli_error($db));
if($result){
print"Thank you $firstName $lastName for signing up with MyBrunch!";
}
}
mysqli_close($db);
?>`
I am looking to get a success message delivered in a modal after my form was successfully sent to my database. Right now the information is sent but, nothing happens.
Wow, just pick a PHP Framework! Don't work like this even for a small project.
Among so many options, I recommend Laravel...
Pick the 4.2 release, it's the simplest!
BTW: Your print call at line 16, lack of parenthesis.