Can't insert values in database using form - php

I have a form where users can register other accounts. It was working fine until I changed the data type of the column date to data type date (I was using varchar so I changed it to date). After changing the datatype, the registration stopped working. I don't get an error but I can't see the new account when I try to view the records.
Here's my form:
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Contact</label>
<input type="text" name="contact" required>
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected hidden>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("m/j/Y");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
And here's code_exec.php
<?php
session_start();
include('connection.php');
$id=$_POST['id'];
$username=$_POST['username'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$street=$_POST['street'];
$town=$_POST['town'];
$city=$_POST['city'];
$contact=$_POST['contact'];
$gender=$_POST['gender'];
$password=$_POST['password'];
$user_levels=$_POST['user_levels'];
$date=$_POST['date'];
$picture=$_POST['picture'];
$sickleave=$_POST['sickleave'];
$vacationleave=$_POST['vacationleave'];
mysqli_query($bd, "INSERT INTO employee(id, firstname, lastname, username, email, street, town, city, contact, gender, password, user_levels, date, picture, sickleave, vacationleave)
VALUES ('$id', '$firstname', '$lastname', '$username', '$email', '$street', '$town', '$city', '$contact', '$gender', '$password', '$user_levels', '$date', '$picture', '$sickleave', '$vacationleave')");
echo "<script>alert('Successfully Added!'); window.location='register.php'</script>";
mysqli_close($con);
?>
Database Schema:
DB Schema

As others have already stated, your date format may not be correct. And you need to look at securing your queries against sql injection.
In order to get you date issue fixed try replacing:
$date=$_POST['date'];
With:
$date=date('Y-m-d', strtotime($_POST['date']));
The Date format for sql is described as YYYY-MM-DD meaning a four digit year-two digit month - two digit day.

You need to convert the received date from your input date :
$dt = \DateTime::createFromFormat('m/j/Y', $_POST['date']);
See this StackOverflow answer for more informations.
Moreover, as #Syscall said, you should also pay attention to your query which is open to SQL injections. To prevent that, you should use a PDO statement, for example :
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute(array('name' => $name));
Example taken from How can I prevent SQL injection in PHP?

Related

Trying to Insert data to multiple tables in single query in php

Im trying to add data to multiple tables using a single query.
These two tables are contacts and address. I think the issue is with my address table. IS it a good idea to separate my address table? since multiple contacts can share the same address.(family)
Query for inserting data
$sql = "INSERT INTO contacts (firstName,lastName,nickName,cellNumber,homeNumber,workNumber) VALUES ($firstName,$lastName,$nickName,$cellNumber,$homeNumber,$workNumber) "
. "INSERT INTO address(street,city,state,country) VALUES($street,$city,$state,$country) INSERT INTO contacts (email,birthday,memo)"
. "values($email,$birthday,$memo)";
My HTML form
<fieldset>
<legend>Register Form</legend>
<div>
<input type="text" name="firstName" placeholder="First Name"/>
</div>
<div>
<input type="text" name="lastName" placeholder="Last Name"/>
</div>
<div>
<input type="text" name="nickName" placeholder="Nick Name"/>
</div>
<div>
<input type="text" name="cellNumber" placeholder="Cell Number"/>
</div>
<div>
<input type="text" name="homeNumber" placeholder="Home Number"/>
</div>
<div>
<input type="text" name="workNumber" placeholder="Work Number"/>
</div>
<div>
<input type="text" name="street" placeholder="Street"/>
</div>
<div>
<input type="text" name="city" placeholder="City"/>
</div>
<div>
<input type="text" name="state" placeholder="state"/>
</div>
<div>
<input type="text" name="country" placeholder="country"/>
</div>
<div>
<input type="text" name="email" placeholder="Email"/>
</div>
<div>
<input type="text" name="birthday" placeholder="Birthday"/>
</div>
<div>
<div class="small"></div>
<textarea name="memo" placeholder="Memo"></textarea>
</div>
<input type="submit" name="addContact" value="Send"/>
</fieldset>
Thomas i try your query u should modify and try this query:
Code :
$sql = "INSERT INTO contacts (firstName,lastName,nickName,cellNumber,homeNumber,workNumber) VALUES ($firstName,$lastName,$nickName,$cellNumber,$homeNumber,$workNumber) " ; "INSERT INTO address(street,city,state,country) VALUES($street,$city,$state,$country)"; "INSERT INTO contacts (email,birthday,memo)
values($email,$birthday,$memo)";
I think it should be must helpful.

Form is submitting data but sql is showing no records

I have created a simple form to submit into mysql server. When I am hitting the submit button the form is sending data, but when I check the sql database its showing no data.
Here is php code
<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_POST['submit'])){
$user_id = $_POST['user_id'];
$type = $_POST['optionsRadiosInline'];
$qty = $_POST['qty'];
$de_add = $_POST['de_add'];
$re_add = $_POST['re_add'];
$sub = $_POST['sub'];
$time_deli = $_POST['time'];
$cost = $_POST['cost'];
$reg_date = date("Y-m-d H:i:s");
$query = "INSERT into `orders` (user_id, type, qty, de_add, re_add, sub, time_deli, cost, reg_date) VALUES ('$type','$qty','$de_add','$re_add','$sub','$time_deli','$cost', '$reg_date')";
$result = mysql_query($query);
if($result){
echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}else{
?>
Here is html form part
<form role="form" name="new_order" action="" method="post">
<div class="form-group">
<label>User ID</label>
<input class="form-control" name="user_id" value="<?php echo $_SESSION["username"]; ?>" readonly>
</div>
<div class="form-group">
<label>Type of Dabba : </label>
<label class="radio-inline">
<input type="radio" name="optionsRadiosInline" id="optionsRadiosInline1" value="xl" checked>X-Large
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadiosInline" id="optionsRadiosInline2" value="l">Large
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadiosInline" id="optionsRadiosInline3" value="m">Midiam
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadiosInline" id="optionsRadiosInline3" value="s">Small
</label>
</div>
<div class="form-group">
<label>Quantity</label>
<input class="form-control" name="qty" placeholder="Enter text">
</div>
<div class="form-group">
<label>Destination Address</label>
<input class="form-control" name="de_add" placeholder="Enter text">
</div>
<div class="form-group">
<label>Reciving Address</label>
<input class="form-control" name="re_add" placeholder="Enter text">
</div>
<div class="form-group">
<label>Subscription</label>
<select class="form-control" name="sub">
<option>weekly</option>
<option>Monthly</option>
<option>Quterly</option>
<option>Yearly</option>
</select>
</div>
<div class="form-group">
<label>Time</label>
<select class="form-control" name="time">
<option value="8.00 AM">8.00 AM</option>
<option value="9.00 AM">9.00 AM</option>
<option value="10.00 AM">10.00 AM</option>
<option value="11.00 AM">11.00 AM</option>
<option value="12.00 AM">12.00 AM</option>
<option value="6.00 PM">6.00 PM</option>
<option value="7.00 PM">7.00 PM</option>
<option value="8.00 PM">8.00 PM</option>
<option value="9.00 PM">9.00 PM</option>
<option value="10.00 PM">10.00 PM</option>
</select>
</div>
<label>Cost</label>
<div class="form-group input-group">
<input type="text" name="cost" class="form-control">
<span class="input-group-addon">.00</span>
</div>
<button type="submit" name="submit" class="btn btn-default">Submit Button</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</form>
Please help. Thanks.
$query = "INSERT into `orders` (user_id, type, qty, de_add, re_add, sub, time_deli, cost, reg_date) VALUES ('$type','$qty','$de_add','$re_add','$sub','$time_deli','$cost', '$reg_date')";
I see 9 columns but only 8 values in this query. You're missing $user_id in your VALUES (or whatever variable holds the user ID), which is causing the query to fail (columns and values must be equal in number).
First of all don't use mysql_* functions, they are deprecated and removed completely in PHP 7.
Back to your question.
Your SQL query has 9 fields and 8 values. It is mismatch.
$query = "INSERT into `orders` (user_id, type, qty, de_add, re_add, sub, time_deli, cost, reg_date)
VALUES ('$type','$qty','$de_add','$re_add','$sub','$time_deli','$cost',
'$reg_date')";
Missing $user_id
Ahoy!
In the first code fragment you did not close your "else" statement with "}"
The count of the fields and the count of the Values you are putting in are different, as pointed out by others
if you put those two lines at the start of your php script, it might help you see the errors (since most servers have them disabled by default in production)
ini_set('display_errors', true);
error_reporting(E_ALL);
or
error_reporting(E_ALL ^ E_NOTICE);
the latter one won't display notices
P.S I am subscribing to this answer so please keep me posted on how it goes!

Send html form data to sql database via php

I'm attempting to insert the data collected on the form into a mysql database. I'm able to make a successful connection but the data is not inserted. I've read many similar questions but have been unsuccessful so far.
sqldatabase.php
<?php
$servername = "localhost";
$username = "USER";
$password = "PASS";
$dbname = "DATABASE";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$first_spouse = $_POST['first_spouse'];
$last_spouse = $_POST['last_spouse'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$occupation = $_POST['occupation'];
$shirt_size = $_POST['shirt_size'];
$cap_size = $_POST['cap_size'];
$shirtnum1 = $_POST['shirtnum1'];
$shirtnum2 = $_POST['shirtnum2'];
$desc = $_POST['desc'];
$bylaws_rules = $_POST['bylaws_rules'];
$umpires = $_POST['umpires'];
$alcohol = $_POST['alcohol'];
$waiver = $_POST['waiver'];
$sql="INSERT INTO 'softball_reg_2016' (first_name, last_name, first_spouse, last_spouse,
address, city, state, zip, phonehome, phonecell, email, dob, occupation, shirt_size,
cap_size, shirtnum1, shirtnum2, desc, bylaws_rules, umpires, alcohol, waiver)
VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[first_spouse]', '$_POST[last_spouse]',
'$_POST[address]', '$_POST[city]', '$_POST[city]', '$_POST[state]', '$_POST[zip]',
'$_POST[phonehome]', '$_POST[phonecell]', '$_POST[email]', '$_POST[dob]', '$_POST[occupation]',
'$_POST[shirt_size]', '$_POST[cap_size]', '$_POST[shirtnum1]', '$_POST[shirtnum2]',
'$_POST[desc]', '$_POST[bylaws_rules]', '$_POST[umpires]', '$_POST[alcohol]', '$_POST[waiver]')";
echo "Connected successfully";
mysqli_close($conn);
?>
My html
<form action="/php/sqldatabase.php" method="POST" id="registration">
<h2>Registration for 2016 Summer Season (April-September)</h2>
<p>
<label for="name">Name:</label>
<input type="text" id="first_name" name="first_name" placeholder="First Name" autofocus="" />
<input type="text" id="last_name" name="last_name" placeholder="Last Name" />
</p>
<p>
<label for="spouse">Name of Spouse<i>(Optional)</i>:</label>
<input type="text" id="first_spouse" name="first_spouse" placeholder="First Name" />
<input type="text" id="last_spouse" name="last_spouse" placeholder="Last Name" />
</p>
<p>
<label for="address1">Address:</label>
<input type="text" id="address" name="address" placeholder="Street Address" />
<input type="text" id="city" name="city" placeholder="City" />
</p>
<p>
<label for="address2"></label>
<input type="text" id="state" name="state" placeholder="State" />
<input type="number" id="zip" name="zip" placeholder="Zip Code" />
</p>
<p>
<label for="phone">Phone:</label>
<input type="tel" id="phonehome" name="phone" placeholder="Home Phone" />
<input type="tel" id="phonecell" name="phone" placeholder="Work/Cell Phone" />
</p>
<p>
<label for="phone">Email:</label>
<input type="email" id="email" name="email" />
</p>
<p>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" />
</p>
<p>
<label for="occupation">Occupation (Former, if retired):</label>
<input type="text" id="occupation" name="occupation" />
</p>
<div id="shirt">
<p>
<label for="size">Uniform:</label>
<select name="shirt_size" id="shirt_size">
<option value="">Shirt Size</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="XL">XL</option>
<option value="2XL">2XL</option>
<option value="3XL">3XL</option>
</select>
<select name"cap_size" id="cap_size">
<option value="">Cap Size</option>
<option value="XS/S">XS/S</option>
<option value="S/M">S/M</option>
<option value="M/L">M/L</option>
<option value="L/XL">L/XL</option>
</select>
</p>
<p>
<label for="shirtnum">Shirt Number:</label>
<input type="number" id="shirtnum1" name="shirtnum1" placeholder="1st Choice" min="0" max="99" />
<input type="number" id="shirtnum2" name="shirtnum2" placeholder="2nd Choice" min="0" max="99" />
</p>
</div>
<div id="describe">
<p>
<span class="describe1">
<b>Describe any information you deem important regarding your ability and/or availability or any other information you deem important to the season.</b>
<textarea name="description" id="desc" cols="30" rows="10"></textarea>
</span>
</p>
</div>
<div id="ethics">
<h2>Code of Ethics</h2>
<p>
<span class="ethics1">
<input type="checkbox" id="bylaws_rules" name="bylaws_rules" />
I agree to abide by the Bylaws and decisions of the Club and Club Officials.
</span>
</p>
<p>
<span class="ethics1">
<input type="checkbox" id="umpires" name="umpires" />
I agree to accept the decisions of the Umpires and Team Managers.
</span>
</p>
<p>
<span class="ethics1">
<input type="checkbox" id="alcohol" name="alcohol" />
I agree to abstain from alcoholic beverages prior to a game.
</span>
</p>
</div>
<div id="waiver">
<h2>Release of Liability</h2>
<p>
<b>I agree to hold harmless the club.</b>
</p>
<input type="checkbox" id="waiver" name="waiver" />
</div>
<ol class="requires">
<li>Dues are $95 and should be received by April 6, 2016</li>
<li>If you decline to play after being drafted, your registration fee will not be refunded.</li>
<li>All members must be at least 50 years old by December 31, 2016</li>
<li>The deadline for receipt of registrations is April 6, 2016. Registrations received after this date will
not be processed for the player drat. Assignments to teams will then be made according to League guidelines
regarding late registering players.</li>
<li>Registrations received without the correct fee will not be considered as received and will not be valid until the correct fee is received.</li>
</ol>
<p> </p>
<p> </p>
<p> </p>
<p>
<button type="submit" id="register">Register!</button>
</p>
</form>
Thank you for any help!
Posting as a community wiki.
There are a few things wrong here.
First, you never executed the query.
You never check for empty() fields, which might insert empty rows on the table.
Consult the manual:
http://php.net/manual/en/mysqli.query.php
Object oriented style
mixed mysqli::query ( string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
Procedural style
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
Then you're using the wrong identifier qualifiers for your table:
INSERT INTO 'softball_reg_2016'
^ ^
being regular single quotes, where it should be ticks or no quotes at all:
INSERT INTO `softball_reg_2016`
and that alone would have thrown you a syntax error.
Read up on identifier qualifiers:
http://dev.mysql.com/doc/en/identifier-qualifiers.html
Then you're using desc as a column name which is a MySQL reserved word. That also would have thrown you an error about it. So, either you rename it to something else, or wrap it in ticks.
`desc`
Reference:
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
Also check for errors:
http://php.net/manual/en/mysqli.error.php
http://php.net/manual/en/function.error-reporting.php
Plus, your present code is open to SQL injection. Use mysqli_* with prepared statements, or PDO with prepared statements.
Also, since you already declared variables to your POST arrays, why put the POST arrays in the query? Just used the variables. You're using more code for nothing really.
And as noted in comments:
"You also have two input fields with same name: phone. Is that intended or just the copy/paste usual problem? – FirstOne"
You need to execute the query. You have just taken the string.
Here is what you are missing. Put
mysqli_query($conn,$sql);
before the success message.
You didn't excute the query
you have to do
mysqli_query($conn,$query);
before closing the connection

How to output information in a Database specific to a user

I have been teaching myself code for the past 3 months now and I am working on a project that is outside my level of knowledge. So on the site we're creating, we have a page where the user creates a profile and anyone who visits the site see's that information, the information they input is stored in a database table. What I am trying to do is only display that information for that specific user. Right now I have created three different users and when I login to each one it displays the same information for each user. I am sure this question has been answered i just dont know how to word it. Below is the input form and .php file i am currently using.
<div class="modal-body">
<form action="edit_profile.php" method="post">
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Name" name="name" required="">
<br>
<textarea class="form-control" name="about_me" rows="3" placeholder="About Me (300 Characters Max)"></textarea></textarea>
<br>
<input type="text" class="form-control" id="exampleInputEmail" placeholder="My Specialties" name="specialty" required="">
<br>
<input type="text" class="form-control" id="exampleInputEmail" placeholder="City" name="city" required="">
<br>
<input type="text" class="form-control" id="exampleInputEmail" placeholder="State" name="state" required="">
<br>
<input type="email" class="form-control" id="exampleInputEmail" placeholder="Email" name="email" required="">
<br>
<input type="text" class="form-control" id="exampleInputEmail" placeholder="Website" name="website" required="">
<br>
<input type="email" class="form-control" id="exampleInputEmail" name="facebook" placeholder="Facebook Link">
<br>
<input type="email" class="form-control" id="exampleInputEmail" name="instagram" placeholder="Instagram Link">
<br>
<input type="email" class="form-control" id="exampleInputEmail" name="twitter" placeholder="Twitter Link">
<br>
<input type="email" class="form-control" id="exampleInputEmail" name="google" placeholder="Google+ Link">
<br>
<input type="submit" class="btn btn-primary" value="submit">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
<!-- End Edit Profile Modal -->
<h4><strong>About Me: </strong></h4>
<?php echo $row['about_me'];?>
<h4><strong>My Specialties: </strong></h4>
<?php echo $row['specialty'];?>
<h4><strong>Location: </strong> </h4>
<?php echo $row['city'];?>, <?php echo $row['state'];?>
<h4><strong>Get Connected: </strong></h4>
<h5><strong>Email:</strong> <?php echo $row['email'];?> </h5>
<h5><strong>Website:</strong> <?php echo $row['website'];?></h5>
<h5><strong>Facebook:</strong> <?php echo $row['facebook'];?></h5>
//DATABASE CONNECT
<?php
$host="localhost";
$username="XXXXXXX";
$password="XXXXXXX";
$db_name="photographer_directory";
$tbl_name="qls3_profile";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM qls3_profile");
$row = mysql_fetch_array($result);
?>
<?php
include_once('includes/db_connect.php');
$name=$_POST['name'];
$about_me=$_POST['about_me'];
$specialty=$_POST['specialty'];
$city=$_POST['city'];
$state=$_POST['state'];
$email=$_POST['email'];
$website=$_POST['website'];
$facebook=$_POST['facebook'];
$instagram=$_POST['instagram'];
$twitter=$_POST['twitter'];
$google=$_POST['google'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, about_me, specialty, city, state, email, website, facebook, instagram, twitter, google)VALUES('$name', '$about_me', '$specialty', '$city', '$state', '$email', '$website', '$facebook', '$instagram', '$twitter', '$google')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
header( 'Location: userprofile.php' ) ;
?>
<?php
// close connection
mysql_close();
?>
You want to use a SQL SELECT ... FROM ... WHERE clause. It is best if you learn if for yourself: http://www.w3schools.com/sql/sql_where.asp

PHP Form data not inserting into MySQL database

HTML FORM
<form class="form" method="post" action="process.php">
<h4 class="form-heading">Please New Enter Customer Information</h4>
<label for="inital">Inital:</label>
<select id="inital" name="inital" required="required">
<option value="mr">Mr</option>
<option value="ms">Ms</option>
<option value="mrs">Mrs</option>
<option value="prof">Prof</option>
<option value="dr">Dr</option>
</select>
<label for="firstname">First Name:</label>
<input type="text" placeholder="First Name" name="firstname" required="required" >
<label for="lastname">last Name:</label>
<input type="text" placeholder="Last Name" name="lastname" required="required">
<label for="mobile">Mobile:</label>
<input type="tel" placeholder="Mobile" name="mobile" required="required">
<label for="landline">Landline:</label>
<input type="tel" placeholder="Landline" name="landline">
<label for="email">Email:</label>
<input type="email" placeholder="Email" name="email" required="required">
<label for="address">Address:</label>
<input type="text" placeholder="Address" name="address" required="required">
<label for="postocde">Postal Code:</label>
<input type="text" placeholder="Post Code" name="postcode">
<label for="accessibility">Accessibility:</label>
<input type="text" placeholder="Accessibility Needs" name="accessibility" value="">
<button class="btn btn-large btn-primary" type="submit">Enter</button>
process.php
<? php
require( '../connect_db.php' ) ;
$inital = $sql->real_escape_string($_POST[inital]);
$firstname = $sql->real_escape_string($_POST[firstname]);
$lastname = $sql->real_escape_string($_POST[lastname]);
$mobile = $sql->real_escape_string($_POST[mobile]);
$landline = $sql->real_escape_string($_POST[landline]);
$email = $sql->real_escape_string($_POST[email]);
$address = $sql->real_escape_string($_POST[address]);
$postcode = $sql->real_escape_string($_POST[postcode]);
$accessibility = $sql->real_escape_string($_POST[accessibility]);
$query = "INSERT INTO `customer` (inital, firstname, lastname, mobile, landline, email, address, postcode, accessibility) VALUES ('$inital','$firstname', '$lastname','$mobile','$landline','$email','$address','$postcode','$accessibility')";
/* execute the query, nice and simple */
$sql->query($query) or die($query.'<br />'.$sql->error);
?>
I have tried alternatives too but to no satisfaction like not including $inital =($_POST[inital]); Instead putting right into INSERT INTO section but that still does not help either.
It either prints out the whole code on screen or blank. I've looked at similar problems on here and on forums all them seem to present the issue differently and when i change it suit the so called answer it still does not work!
My other page that lists all the tables using the following connection required statment works works fine so there is no problem with connection to the database but at this moment just cannot insert content. Grr
Two problems:
change <? php to <?php
and then add quotes to your post data values. $_POST[inital] to $_POST['inital']
and for your information i would do isset($_POST['value']) ? $_POST['value'] : '';
you still need to check post value before using it.
Check the <? php tag. it should be <?php

Categories