I'm new to php and I'm trying to register a user to a database using a form.
This is the code for the form (using the bootstrap framework):
<form class="form-horizontal" role="form" method="POST" action="connectivity-reserve.php">
<div class="form-group">
<label class="col-sm-2 control-label">Customer's name</label>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control" id="Customername" name="Customername" placeholder="Customer name">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Password</label>
<div class="col-sm-6">
<div class="input-group">
<input type="password" class="form-control" id="pwd" name="pwd" placeholder="Password">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name ="submit" class="btn btn-primary">Reserve</button>
<button type="button" class="btn btn-default btn-sm"
data-dismiss="modal">Cancel</button>
</div>
</div>
<div class="form-group">
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Warning:</strong>: Please <a href="tel:+85212345678" class="alert-link">
call</a> us to reserve for more than six guests.
</div>
</div>
</form>
Here is the file (mysqli_connect.php) for connecting to the database. This is working:
<?php
// This provides the information for accessing the database.
// It also creates a connection to MySQL,
// It selects the database, and sets the encoding.
// Set the database access information as constants:
DEFINE ('DB_USER', 'xxxx');
DEFINE ('DB_PASSWORD', 'xxxx');
DEFINE ('DB_HOST', 'xxxx');
DEFINE ('DB_NAME', 'xxxx');
// Make the connection:
$dbcon = #mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
The file connectivity-reserve.php is what I'm using to add the user into the database.
Here is the code:
<?php
require ('mysqli_connect.php');
echo "yay";
if(isset($_POST['submit']))
{
$Customername = $_POST['Customername'];
$pwd = $_POST['pwd'];
$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";
$result = #mysqli_query ($dbcon, $q);
if($result)
{
echo "YOUR REGISTRATION IS COMPLETED...";
}
else
{
echo "nah";
}
}
?>
I'm able to connect to the database since the code echo "yay" is displayed on the browser. The issue is with the if(isset($_POST['submit'])) condition. I thought it should work since my button's type and name are 'submit' on the form:
<button type="submit" name ="submit" class="btn btn-primary">Reserve</button>
Help will be greatly appreciated.
Edit: Thanks guys! It was the , after psword. Also I know the code isn't secure. I'm just starting out with php so that isn't really a priority for me right now.
Replace
<button type="submit" name ="submit" class="btn btn-primary">Reserve</button>
By
<input type="submit" name ="submit" class="btn btn-primary" value="Reserve">
Error in query
$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";
comma after psword
$q = "INSERT INTO users (user_id, cname, psword ) VALUES (' ', '$Customername', '$pwd')";
Remove the comma from psword. Tested your code in my local db and is working just fine.
INSERT INTO users (cname, psword, ) VALUES ('{$Customername}', '{$pwd}')
You Should remove user_id because its already auto i
There is an error in your query:
Below statement:
$q = "INSERT INTO users (user_id, cname, psword, ) VALUES (' ', '$Customername', '$pwd')";
should be:
$q = "INSERT INTO users (user_id, cname, psword) VALUES (' ', '$Customername', '$pwd')";
There was an additional comma which would fail the query and result in error.
Secondly, instead of checking if(isset($_POST['submit'])), you should check for Customername and pwd
if(isset($_POST['Customername']) && isset($_POST['pwd'])) {
Related
I have a page where theres a button, when I click the button a Modal shows up, which contains a form for adding a new user.
in the user table, username + email + userid are primary keys. So I need to validate first that they don't exist in the table.
Now inserting works just fine. also when I insert an already existing username/userid/email it doesn't get added. However, the alert doesn't show. so the user won't know why it wasn't added
try
{
if(isset($_POST['submit']))
{
if($_POST['submit'] == 'إضافة'){
$user_name = $_POST['user_name'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$userid = $_POST['userid'];
//check to see if username/email/userid already exists
//Check username
$stmt1 = $conn->prepare("SELECT * FROM users WHERE username='$user_name'");
//Check email
$stmt2 = $conn->prepare("SELECT * FROM users WHERE E-mail='$email'");
//Check userid
$stmt3 = $conn->prepare("SELECT * FROM users WHERE id=$userid");
$stmt1->execute();
$stmt2->execute();
$stmt3->execute();
if (mysqli_num_rows($stmt1)>0)
{
$name_error = "username already exists";
die();
}
else if (mysqli_num_rows($stmt2)>0)
{
$name_error = "email already exists";
die();
}
else if (mysqli_num_rows($stmt3)>0)
{
$name_error = "employee id already exists";
die();
}
//if username/email/userid don't exist, proceed with the insert query.
else
{
$stmt = $conn->prepare("INSERT INTO `user` (`id`, `username`, `name`, `E-mail`, `Password`, `Role`, `User_Id`) VALUES (NULL, '$username', '$Name', '$email', '$password', '$role', $userid)");
$stmt->execute();
$lastIntertedId = $conn->lastInsertId();
}
I added the following to the text fields, so the error shows beneath them.
<!-- Add User Modal -->
<div id="addUserModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="user_managment.php" >
<div class="modal-header">
<h4 class="modal-title">إضافة مستخدم </h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>اسم المستخدم</label>
<input name="user_name" type="text" class="form-control" required>
<?php if(isset($name_error)): ?>
<span><?php echo $name_error;?></span>
<?php endif ?>
</div>
<div class="form-group">
<label>الاسم</label>
<input name="name" type="text" class="form-control" required>
</div>
<div class="form-group">
<label>الرقم الوظيفي</label>
<input name="userid" type="number" class="form-control" required>
<?php if(isset($name_error)): ?>
<span><?php echo $name_error;?></span>
<?php endif ?>
</div>
<div class="form-group">
<label>دور المستخدم </label>
<select name="role" class="form-control" id="sel1">
<option value="admin">مشرف</option>
<option value="employee">مدخل بيانات</option>
</select>
</div>
<div class="form-group">
<label>البريد الالكتروني</label>
<input name="email" type="email" class="form-control" required>
<?php if(isset($name_error)): ?>
<span><?php echo $name_error;?></span>
<?php endif ?>
</div>
<div class="form-group">
<label>الرقم السري</label>
<input name="password" type="password" class="form-control" required>
</div>
</div>
<div class="modal-footer" >
<input name="submit" type="submit" class="btn btn-success" value="إضافة">
<input type="button" class="btn btn-default" data-dismiss="modal" value="إلغاء">
</div>
</form>
</div>
</div>
</div>
Isn't your UserId a generated value in your DB's schema ?
If i understand correctly what you are trying to achieve, you shouldn't be able to know if your user_id already exist since you shouldn't have a user_id at the moment you are trying to execute your form.
Here's how i understand your page:
You have a page, on this page there's a modal to add new user, in this page you verify if there's already an existing user with the same Email | Username | Id, but my issue is that you can't know the user_id of a user that hasn't been created yet, and also you shouldn't validate a duplicate based on an auto-generated value by your DB (imo)
I hope my message is understandable, what i want to say is that you can't verify the existence of something that hasn't been created yet.
I want to add dynamic form fields in the database using PHP. I have used angular to add dynamic form fields. The thing is when I am trying to insert this data into the database only last form field is inserting in the database. SO, I used array and loop to increment and update this form field into the database. but somehow query is not working properly and data is also not inserting into the database. can anybody tell me what is wrong here? I am stuck. Please help. Thanx in advance
Php Code:
<?php
if(isset($_POST['submit_row']))
{
$link = mysqli_connect("localhost", "root", "", "midata");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$camp_name = mysqli_real_escape_string($link, $_REQUEST['camp_name']);
$start_date = mysqli_real_escape_string($link, $_REQUEST['start_date']);
$end_date = mysqli_real_escape_string($link, $_REQUEST['end_date']);
$store = mysqli_real_escape_string($link, $_REQUEST['$store']);
$elements= $mysqli->real_escape_string($_POST['elements']);
$quantity = $mysqli->real_escape_string($_POST['quantity']);
$description = mysqli_real_escape_string($link, $_REQUEST['description']);
for($i=0;$i<count($elements);$i++)
{
if( $elements[$i]!="" && $quantity[$i]!="")
{
$sql = "INSERT INTO create_campaign(camp_name, start_date, end_date,store,elements,quantity, description )
VALUES('$camp_name',' $start_date', '$end_date','$store','$elements[$i]', '$quantity[$i]', '$description')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_query($sql, $link);
}
}
}
?>
HTML Code:
<div class="row col-md-12" ng-app="angularjs-starter" ng-controller="MainCtrl">
<fieldset data-ng-repeat="choice in choices" name="records">
<label for="inputPassword3" class="col-md-1 control-label">Elements</label>
<div class="form-group col-md-3 ">
<input type="text" placeholder="Campaign Name" ng-model="choice.name" class="form-control c-square c-theme input-lg" name="elements[]">
</div>
<label for="inputPassword3" class="col-md-1 control-label">Quantity</label>
<div class="form-group col-md-3" >
<select class="form-control c-square c-border-2px c-theme" name="quantity[]>
<option value="1">100</option>
<option value="2">200</option>
<option value="3">300</option>
<option value="4">400</option>
</select>
</div>
<button type="button" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" ng-click="addNewChoice()" >add</button>
<button ng-show="$last" ng-click="removeChoice()" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" >Remove</button>
</fieldset>
</div>
</div>
</div>
<div class="form-group">
<input type="text" placeholder="Description" class="form-control c-square c-theme input-lg" name="description">
</div>
<input class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" value="Submit" type="submit" name="submit_row">
</form>
</div>
You should declare a variable like x=1 and use it inside your array of input like name="input_name[+ x +]"
and increment the variable after each input field i.e x++
You can access those inputs using inputName[1], input_name[2] in your php controller
Submit button does not functioning when I click. All of the code seem to have no errors, but it just does not inserted to my database. I am currently using bootstrap. I don't know what is the error I am having.
index.html
<div class="container">
<div class="col-md-5">
<div class="form-area">
<form role="form">
<br style="clear:both">
<h3 style="margin-bottom: 25px; text-align: center;">Schedule Form</h3>
<form name="form2" method="post" action="scheduleform.php">
<div class="form-group">
<input type="text" class="form-control" id="tajuk" name="tajuk" placeholder="Tajuk" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="tarikh" name="tarikh" placeholder="Tarikh" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" required>
</div>
<div class="form-group">
<textarea class="form-control" type="textarea" id="maklumat" name="maklumat" placeholder="Maklumat" maxlength="140" rows="7"></textarea>
<span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
</div>
<button><input type="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
</form></form>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
scheduleform.php
<?php
$server = "localhost";
$user = "root";
$pass = "";
$dbname = "kajangdb";
//Creating connection for mysqli
$conn = new mysqli($server, $user, $pass, $dbname);
//Checking connection
if($conn->connect_error){
die("Connection failed:" . $conn->connect_error);
}
$tajuk = mysqli_real_escape_string($conn, $_POST['tajuk']);
$tarikh = mysqli_real_escape_string($conn, $_POST['tarikh']);
$mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
$maklumat = mysqli_real_escape_string($conn, $_POST['maklumat']);
$sql = "INSERT INTO schedule (tajuk, tarikh, mobile, maklumat) VALUES ('$tajuk', '$tarikh', '$mobile', '$maklumat')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
Issues i found with your code.
1. You don't need to wrap form element with another form element
2.
$sql = "INSERT INTO schedule (tajuk, tarikh, mobile, maklumat) VALUES ('$tajuk', '$tarikh', '$mobile', '$maklumat')";
Here you added extra space after "schedule" and "VALUES" which may created problem. change your code as below.
$sql = "INSERT INTO schedule(tajuk, tarikh, mobile, maklumat) VALUES('$tajuk', '$tarikh', '$mobile', '$maklumat')";
1) Nested forms are definitely error-prone. Use more forms in a page, if
you wish, but never nest them. Here you are using form2 inside
another one. Don't do that, delete the outer one.
2) Your submit button syntax is wrong. Use input OR button.
Instead of:
<button><input type="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
use:
<input type="submit" name="submit" value="Submit Form" class="btn btn-primary pull-right" />
or:
<button type="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
3) Provide validation on $_POST values. Like:
if (
!isset($_POST['tajuk']) ||
!isset($_POST['tarikh']) ||
!isset($_POST['mobile']) ||
!isset($_POST['maklumat'])
) {
echo 'Error: not all values are valid. Please provide valid values.';
}
$conn = new mysqli($server, $user, $pass, $dbname);
//...
I recommend you to always prepare your sql statements for execution, in order to avoid the SQL injection risks. Use prepare() before querying. See: mysqli::prepare.
Also use exception handling. See please The mysqli_sql_exception class
EDIT 1:
It is not allowed to use paragraphs (<p>) inside spans (<span>). Use other container types, like <div> instead of <span>. So, replace
<span class="help-block">
<p id="characterLeft" class="help-block ">
You have reached the limit
</p>
</span>
with
<div class="help-block">
<p id="characterLeft" class="help-block ">
You have reached the limit
</p>
</div>
Not sure where is a problem.
Really, the thing is that after submitting the page refreshes and it looks like code worked well.
But when I refresh my database there is no new data...
Modal (file path incl/modals.inc.php and is included in index.php file):
<div class="modal fade" id="addPlayer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Player </h4>
</div>
<div class="modal-body">
<form action="incl/addplayer.inc.php" method="POST" class="form" role="form">
<div class="row">
<div class="col-xs-6 col-md-6">
<input class="form-control" name="addname" placeholder="First Name (*)" type="text" />
</div>
<div class="col-xs-6 col-md-6">
<input class="form-control" name="addsurname" placeholder="Last Name (*)" type="text" />
</div>
</div><br/>
<div class="row">
<div class="col-xs-6 col-md-6">
<input class="form-control" name="addlvpoints" placeholder="LV points" type="text" />
</div>
<div class="col-xs-6 col-md-6">
<input class="form-control" name="additfpoints" placeholder="ITF points" type="text" />
</div>
</div><br/>
<div class="row">
<div class="col-xs-6 col-md-6 col-md-offset-3">
<input class="form-control" name="addrank" placeholder="Rank" type="text" />
</div>
</div><br/>
<div class="row">
<div class="col-xs-6 col-md-6">
<label for="">
Gender</label>
<br/>
<label class="radio-inline">
<input type="radio" name="addgender" value="M" name="male" />
Male
</label>
<label class="radio-inline">
<input type="radio" name="addgender" value="F" name="female" />
Female
</label>
</div>
</div>
<br/><br/>
(*) - Required
<br/>
<br />
<button class="btn btn-lg btn-default btn-block" type="submit" name="addsubmit">
Add Player
</button>
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
Action file (incl/addplayer.inc.php) :
<?php
include '../core.php';
if(isset($_POST['addsubmit'])){
$rank = $_POST['addrank'];
$name = $_POST['addname'];
$surname = $_POST['addsurname'];
$lvpoints = $_POST['addlvpoints'];
$itfpoints = $_POST['additfpoints'];
$gender = $_POST['addgender'];
if(empty($name) || empty($surname) || empty($gender)){
header("Location: ../index.php?error=empty");
exit();
} else {
$sql = "INSERT INTO 'players' ('id', 'rank', 'surname', 'name', 'lvpoints', 'itfpoints', 'gender') VALUES (NULL, '$rank', '$surname', '$name', '$lvpoints', '$itfpoints', '$gender')";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php?addedsuccessfuly");
}
}
?>
When submit the form it goes to
header("Location: ../index.php?addedsuccessfuly");
as excepted
Column structure:
id | rank | surname | name | lvpoints | itfpoints | gender
Thanks in advance!
First try changing:
$result = mysqli_query($conn, $sql);
To:
$result = mysqli_query($sql);
Secondly, remove the insert to ID. If you have set it as "auto increment" in phpmyadmin, the ID will increment automagically. So from:
$sql = "INSERT INTO 'players' ('id', 'rank', 'surname', 'name', 'lvpoints', 'itfpoints', 'gender') VALUES (NULL, '$rank', '$surname', '$name', '$lvpoints', '$itfpoints', '$gender')";
To:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$rank = $_POST["addrank"];
$surname = $_POST["addsurname"];
$name = $_POST["addname"];
$ivp = $_POST["addlvpoints"];
$ift = $_POST["additfpoints"];
$gender = $_POST["addgender"];
$sql = "INSERT INTO players (rank, surname, name, ivpoints, itfpoints, gender)
VALUES ('$rank', '$surname', '$name', '$ivp', '$ift', '$gender')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Now, the code could be a lot more elegant and better, but there are literally tons of articles on the Internet about inserting into databases securly that also explains "do's" and "don't's" in more detail and a lot better - just a Google search away.
There are a lot of answers to this on Stackoverflow too.
Can someone please help me understand, why my code is not inserting data into my database from this form? I can get it to Select and Echo the same info from the same database to the page but when I go to add new data through the form it never makes it to the db.
I'm not getting any errors at all and I have error reporting set at the top of my page. I even set a javascript alert to capture the values of the input when clicking the submit button and they return the true values. They just won't insert into the database.
What am I doing wrong here?
<?php
if(isset($_POST['addContent'])) {
$addTitle = $_POST['title'];
$addEntry = $_POST['entry'];
$sql = mysqli_query($conn, "INSERT INTO `basic` (`title, entry`) VALUES ('$addTitle', '$addEntry')") or die(mysqli_error($conn));
$result = mysqli_query($sql);
if(!$result) {
echo mysql_error($sql);
}
}
?>
<!-- Modal -->
<div class="modal fade" id="addContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Data</h4>
</div>
<div class="modal-body">
<form method="POST" action="">
<input type="hidden" name="addContent" id="addContent" value="1">
<div class="form-group">
<label for="title">Title</label>
<input id="addTitle" name="addTitle" type="text" class="form-control">
</div>
<div class="form-group">
<label for="entry">Entry</label>
<textarea id="addEntry" name="addEntry" class="form-control" ></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" id="saveAddBtn" class="btn btn-primary" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
UPDATE:
Ok so here's my attempt at addressing some of the issues you all have enlightened me to. Still same result...any other ideas?
<?php
if(isset($_POST['addContent'])) {
$addTitle = $_POST['title'];
$addEntry = $_POST['entry'];
if($addTitle != "" && $addEntry != "")
{
$sql = $conn->prepare("INSERT INTO basic VALUES ('',?,?)");
$sql->bind_param('sss', $addTitle, $addEntry);
$result = mysqli_query($sql);
if(!$result) {
echo mysqli_error($sql);
}
}
}
?>
<!-- Modal -->
<div class="modal fade" id="addContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Data</h4>
</div>
<div class="modal-body">
<form method="POST" action="">
<input type="hidden" name="addContent" id="addContent" value="1">
<div class="form-group">
<label for="title">Title</label>
<input id="addTitle" name="title" type="text" class="form-control">
</div>
<div class="form-group">
<label for="entry">Entry</label>
<textarea id="addEntry" name="entry" class="form-control" ></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" id="saveAddBtn" class="btn btn-primary" data-dismiss="modal" value="Save changes">
</div>
</div>
</div>
</div>
The problem are these lines:
$sql = mysqli_query($conn, "INSERT INTO `basic` (`title`, `entry`) VALUES ('$addTitle', '$addEntry')") or die(mysqli_error($conn));
$result = mysqli_query($sql);
Remove the first mysqli_query and set $sql to equal just the string, this will give you the result and not the result of the result (it'll return boolean false when using the result as a query) and also, backtick each column name singularly, not as a whole :)
change your query to:
$sql = mysqli_query($conn, "INSERT INTO `basic` (`title`, `entry`) VALUES ('$addTitle', '$addEntry')") or die(mysqli_error($conn));
The backticks are affecting the query. Note that the back ticks are around each column individualy not around all of them. The way you have it would suggest you have a column called title, entry. You should also remove the $result line because the query has been executed already. Now you also have to change the if statement to if (! $sql).
Update
<?php
if(isset($_POST['addContent'])) {
$addTitle = $conn->real_escape_string($_POST['title']);
$addEntry = $conn->real_escape_string($_POST['entry']);
if(!empty($addTitle) && !empty($addEntry)) // There is a function for this
{
// Because you are only inserting 2 values there only need to be 2 `?` and 2 parameters
$sql = $conn->prepare("INSERT INTO `basic` (`title`, `entry`) VALUES (?,?)"); // Added column names just to be sure values are inserted on correct columns
$sql->bind_param('ss', $addTitle, $addEntry); // Note the 2 "s" not 3
$sql->execute();
if($sql->affected_rows < 1 ) {
echo $sql->error(); // Don't know for shure what this should be `error` or `error()`
}
}
}
?>
I can't believe none of us caught this sooner. But my submit button was not even inside the form tag! My buddy pointed this out and it fixed the issue. Thanks for trying everyone!
change your query to:
$sql = mysqli_query($conn, "INSERT INTO `basic` (title, entry) VALUES ('$addTitle', '$addEntry')") or die(mysqli_error($conn));
The backticks are affecting the query.