I am trying to create a simple form that will insert the given data received by my HTML form, into my SQL table named 'Vendors', however I am struggling to work with its functionality.
There are 7 text fields that I am wanting to add to my Vendors table, and these are so named:
vendorName
addressL1 (Line 1)
addressL2
postcode
email
telephone
description
The HTML for this form can be found below:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form action="" method="post">
<ul class="form-style-1">
<li>
<label style="color:#4D4D4D;" >Vendor Name <span class="required">*
</span></label>
<center> <input type="text" name="vendorName" class="field-long"
required="required" placeholder="Vendor Name" /> </center>
</li>
<li>
<label style="color:#4D4D4D;">Vendor Address <span class="required">*
</span></label>
<center> <input type="text" name="addressL1" required="required"
class="field-long" placeholder="Address Line 1" /> </center>
</br>
<center> <input type="text" name="addressL2" required="required"
class="field-long" placeholder="Address Line 2" /> </center>
</br>
<center> <input type="text" name="postcode" required="required"
class="field-short" placeholder="Postcode" /> </center>
</li>
<li>
<label style="color:#4D4D4D;">Vendor Contact Details <span
class="required">*</span></label>
<center> <input type="text" name="email" required="required"
class="field-long" placeholder="Email Address" /> </center>
</br>
<center> <input type="text" name="telephone" required="required"
class="field-long" placeholder="Phone Number" /> </center>
</select>
</li>
<li>
<label style="color:#4D4D4D;">Vendor Description </label>
<center> <textarea name="description" id="field5" class="field-long
field-textarea" placeholder="Description"></textarea> </center>
</li>
<li>
<center> <input type="submit" class="AddButton" value="POST"></input>
</center>
</li>
</ul>
</form>
</body>
</html>
And the PHP I have used is:
<?php
date_default_timezone_set('Europe/London');
$server = "";
$connectionInfo = array( "Database"=>"");
$conn = sqlsrv_connect($server,$connectionInfo);
if (!$conn)
{
die("Connection failed");
}
$_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$VendorName = $_POST['vendorName'];
$AddressLine1 = $_POST['addressL1'];
$AddressLine2 = $_POST['addressL2'];
$Postcode = $_POST['postcode'];
$VendorEmail = $_POST['email'];
$VendorNumber = $_POST['telephone'];
$VendorDes = $_POST['description'];
$time = time();
$timestamp = date("Y-m-d H:i:s", $time);
$describeQuery = ("INSERT INTO Vendors (VendorName, VendorAL1,
VendorAL2, VendorPost, VendorEmail, VendorNumber, VendorDes,
Added)
VALUES ('".$VendorName."', '".$AddressLine1."',
'".$AddressLine2."', '".$Postcode."',
'".$VendorEmail."', '".$VendorNumber."',
'".$VendorDes."', '".$timestamp."')");
$results = sqlsrv_query($conn, $describeQuery);
if(sqlsrv_query($conn, $describeQuery))
{
$alert = "Vendor Successfully Added";
echo "<script type='text/javascript'>alert('$alert');
</script>";
}
else
{
echo 'Information not inserted';
}
}
sqlsrv_close($conn);
?>
Each time I submit the form, it goes straight to the 'Information not inserted' ELSE statement and doesn't import the data into my database.
I have removed my server name and database name for precautionary reasons, however I can assure you they are correct as I have worked on a previous project and used the same method of connecting.
Any help on this would be greatly appreciated, and if there are any formatting mistakes, apologies in advance, I am not an avid user of stack overflow.
Use Mysqli Please, I have updated the script.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Vendors (VendorName, VendorAL1,
VendorAL2, VendorPost, VendorEmail, VendorNumber, VendorDes,
Added)
VALUES ($VendorName, $AddressLine1, $AddressLine2,$Postcode,$VendorEmail,$VendorNumber,$VendorDes,$timestamp)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
Related
I'm using Cloud9 to create a website. For whatever reason, the data taken from a HTML page will not get inserted into the Database.
I have tested to see if the Database is connected and it is. I would like to be able to get the data to be inserted into the Database.
The HTML code and PHP code is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form
</title>
</head>
<body>
<form action="../php/keithphp/address_submit.php" method="post">
<p>
<label for="address_street">Street</label>
<input type="text" name="address_street" id="address_street">
</p>
<p>
<label for="address_street2">Street 2</label>
<input type="text" name="address_street2" id="address_street2">
</p>
<p>
<label for="address_city">City</label>
<input type="text" name="address_city" id="address_city">
</p>
<p>
<label for="address_county">County</label>
<input type="text" name="address_county" id="address_county">
</p>
<p>
<label for="eircode">Eircode</label>
<input type="text" name="eircode" id="eircode">
</p>
<!-- <p>
<label for="address_geo_latitude">Latitude</label>
<input type="float" name="address_geo_latitude" id="address_geo_latitude">
</p>
<p>
<label for="address_geo_longtitude">Longitude</label>
<input type="float" name="address_geo_longtitude" id="address_geo_longtitude">
</p> -->
<input type="submit" value="Submit">
</form>
</body>
</html>
*****************
<?php
$servername = getenv('IP');
$username = getenv('C9_USER');
$password = "";
$database = "c9";
$dbport = 3306;
// Create connection
$db = new mysqli($servername, $username, $password, $database, $dbport);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
/*$address_id = $_POST['address_id'];*/
$address_street = $_POST['address_street'];
$address_street2 = $_POST['address_street2'];
$address_city = $_POST['address_city'];
$address_county = $_POST['address_county'];
$address_eircode = $_POST['address_eircode'];
/*$address_geo_latitude = $_POST['address_geo_latitude'];
$address_geo_longtitude = $_POST['address_geo_longtitude'];*/
$sql = "INSERT INTO Address(address_id, address_street, address_street2, address_city, address_county, address_eircode, address_geo_latitude, address_geo_longtitude) VALUES ('$address_id', '$address_street', '$address_street2', '$address_city', '$address_county', '$address_eircode', '$address_geo_latitude', '$address_geo_longtitude')";
$success = $db->query($sql);
if (!$sucess){
die("Could not enter data: ".$db->error);
}
echo "Thank you. Address submitted!"
/*my$db->close();*/
?>
And the result after typing in test data is (no error message after text), I get;
Could not enter data:
The below code is a simple form that is sending the data that is inputted to my local database.
<html>
<head>
<title>!!!!!!!!!!!!!!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="main">
<h1>Insert data into database using mysqli</h1>
<div id="login">
<h2>Student's Form</h2>
<hr/>
<form action="" method="post">
<label>Student Name :</label>
<input type="text" name="stu_name" id="name" required="required" placeholder="Please Enter Name"/><br /><br />
<label>Student Email :</label>
<input type="email" name="stu_email" id="email" required="required" placeholder="john123#gmail.com"/><br/><br />
<label>Student City :</label>
<input type="text" name="stu_city" id="school" required="required" placeholder="Please Enter Your City"/><br/><br />
<input type="submit" value=" Submit " name="submit"/><br />
</form>
</div>
<!-- Right side div -->
</div>
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Student";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO students (student_name, student_email, student_school)
VALUES ('".$_POST["stu_name"]."','".$_POST["stu_email"]."','".$_POST["stu_city"]."')";
if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
</body>
</html>
The issue that I am finding is that I am trying to change the Student City input field into a drop down where the values is retrieve from the database and put into a drop down list for a new user to select.
Could someone advise on what needs to be done please.
i am trying to use the below code and send the below list to my database.
<option value="US">United States</option>
<option value="UK">United Kingdom</option>
<option value="France">France</option>
<option value="Mexico">Mexico</option>
but i am finding it hard to send the these values to the database with my above code as well as where to place this code.
As a rough example of how you could build the dropdown menu using data from your db this should give you the general idea perhaps.
/* store formatted menu options in temp array */
$html=array();
/* query db to find schools/cities */
$sql='select distinct `student_school` from `students` order by `student_school`';
$res=$mysqli_query( $conn, $sql );
/* process recordset and store options */
if( $res ){
while( $rs=mysqli_fetch_object( $res ) ){
$html[]="<option value='{$rs->student_school}'>{$rs->student_school}";
}
}
/* render menu */
echo "<select name='stu_city'>", implode( PHP_EOL, $html ), "</select>";
You need to refactor your code by moving the if (isset($_POST)) above the html:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Student";
// Create connection
$conn = new mysqli ( $servername, $username, $password, $dbname );
// Check connection
if ($conn->connect_error) {
die ( "Connection failed: " . $conn->connect_error );
}
$sql = "SELECT city_name FROM cities" ;
if ($conn->query ( $sql ) === TRUE) {
$cities = ... // build the cities from the query result
} else {
$cities = '<option value="none">No cities found</option>' ;
}
if (isset ( $_POST ["submit"] )) {
$sql = "INSERT INTO students (student_name, student_email, student_school)
VALUES ('" . $_POST ["stu_name"] . "','" . $_POST ["stu_email"] . "','" . $_POST ["stu_city"] . "')";
if ($conn->query ( $sql ) === TRUE) {
echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error . "');</script>";
}
$conn->close ();
}
?>
<html>
<head>
<title>!!!!!!!!!!!!!!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="main">
<h1>Insert data into database using mysqli</h1>
<div id="login">
<h2>Student's Form</h2>
<hr />
<form action="" method="post">
<label>Student Name :</label> <input type="text" name="stu_name"
id="name" required="required" placeholder="Please Enter Name" /><br />
<br /> <label>Student Email :</label> <input type="email"
name="stu_email" id="email" required="required"
placeholder="john123#gmail.com" /><br />
<br /> <label>Student City :</label> <select name="stu_city" multiple><?php echo $cities; ?>
</select>><br />
<br /> <input type="submit" value=" Submit " name="submit" /><br />
</form>
</div>
<!-- Right side div -->
</div>
</body>
</html>
Use the Select tag: Lets say you hav a column in your database with Student City, like this, lets say the database field is called city
City 1
City 2
City 3
Step 1: Query the database and fetch all the Cities
$sql = "SELECT city FROM table_name";
$result = $conn->query($sql);
Then you come to your dropdown:
<select name="stu_city" id="..." required>
<?php
while($cities = $conn->fetch_array($result){
extract($cities);
echo "<option value='...'>$city</option>";
}
?>
</select>
You need to refactor your code by moving the if (isset($_POST)) above the html:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Student";
// Create connection
$conn = new mysqli ( $servername, $username, $password, $dbname );
// Check connection
if ($conn->connect_error) {
die ( "Connection failed: " . $conn->connect_error );
}
$sql = "SELECT city_name FROM cities" ;
$result = $conn->query ( $sql );
if (isset ( $_POST ["submit"] )) {
$sql = "INSERT INTO students (student_name, student_email, student_school)
VALUES ('" . $_POST ["stu_name"] . "','" . $_POST ["stu_email"] . "','" . $_POST ["stu_city"] . "')";
if ($conn->query ( $sql ) === TRUE) {
echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error . "');</script>";
}
$conn->close ();
}
?>
<html>
<head>
<title>!!!!!!!!!!!!!!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="main">
<h1>Insert data into database using mysqli</h1>
<div id="login">
<h2>Student's Form</h2>
<hr />
<form action="" method="post">
<label>Student Name :</label> <input type="text" name="stu_name"
id="name" required="required" placeholder="Please Enter Name" /><br />
<br /> <label>Student Email :</label> <input type="email"
name="stu_email" id="email" required="required"
placeholder="john123#gmail.com" /><br />
<br /> <label>Student City :</label> <select name="stu_city" multiple>
<?php
if ($result == TRUE) {
while($cities = $conn->fetch_array($result)){
extract($cities);
echo "<option value=''>$city_name</option>";
}
}
else {
echo "<option value='none'>No cities found</option>";
}
?>
</select>><br />
<br /> <input type="submit" value=" Submit " name="submit" /><br />
</form>
</div>
<!-- Right side div -->
</div>
</body>
</html>
Ok so I have a registration form for users to register and it works fine in that when it submits it enters into my database. I want to add a feature that only users with a certain domain address can register and after looking this up the simplest way I can see to do it is to use a drop down menu with a list of the available domains accepted. My issue is that when I try and run the concatenation function to join them upon entry they are not being joined and added to the database correctly below is my HTML form and my php code.
<form name='registration' method="post" action="registerAdmin.php">
<label for="adminName"> Name: </label>
<input name="adminName" id="a" size="27" required/>
<br/>
<label for="adminEmail"> Email Address: </label>
<input type="text" name="adminEmail" id="a" size="15" required/> <select style="height:27px;width:5;" name="adminDomain"><option value="#ucc.ie">#ucc.ie</option></select>
<br/>
<label for="adminUsername"> Username: </label>
<input name="adminUsername" id="b" size="27" required/>
<br/>
<label for="password"> Password: </label>
<input type="password" name="adminPassword" id="b" size="27" required/>
<br/>
<br/>
<input id="boo" type="submit" name="button" value="Register" class="btn btn-danger btn-lg"/>
</form>
And my PHP code:
$servername = "localhost";
$username = "********";
$password = "********";
$dbname = "********";
// FORM HANDLING
$aName = $_POST["adminName"];
$aEmail = $_POST["'adminEmail"];
$aUsername = $_POST["adminUsername"];
$aPassword = $_POST["adminPassword"];
$aEmail .= $_POST["adminDomain"];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if (mysqli_connect_error()) {
die("Database connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO administrators (`adminName`, `adminEmail`, `adminUsername`, `adminPassword`)
VALUES ('".$aName."','".$aEmail."','".$aUsername."','".$aPassword."')";
if ($conn->query($sql) === FALSE) {
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
} else {
echo "Account has successfully been created, please click the link below to return to the login screen!";
}
$conn->close();
?>
Everything bar the email address gets entered into the database correctly.
There is an extra "'" in the below statement:
$aEmail = $_POST["'adminEmail"]; it has to be `$aEmail = $_POST["adminEmail"];`
This should sort out the issue.
I am making a PHP Journal through a form, but no matter what I do, it always comes up as successfully posted. I've tried using empty() and null but I'm not sure what I'm doing wrong.
Here is the HTML for the form:
<form action="journal_post.php" method="post">
<p>Give your entry a title.</p>
<input class="input" type="text" name="title" />
<p>What is your mood today?</p>
<input class="input" type="text" name="mood" />
<p>Now please tell me about your day.</p>
<textarea class="input" name="entry" rows="12" cols="75" type="text"> </textarea>
<br>
<br>
<input class="submit" type="image" src="submit.png" name="submit" value="Submit" />
<form>
Here is the PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "blahblah";
debug_to_console($password);
//Establishing Connection with Server
$connection = mysql_connect($servername, $username, $password);
//Selecting Database from Server
$journal_db = mysql_select_db("journal_db", $connection);
if(isset($_POST['submit'])){
//Fetching variables of the form which travels in URL
$title = $_POST['title'];
$mood = $_POST['mood'];
$entry = $_POST['entry'];
if($title !=''||$entry !=''){
//Insert Query of SQL
$query = mysql_query("insert into entrys(j_title, j_mood, j_entry) values ( '$title', '$mood', '$entry')");
echo "<br/><br/><span>Journal entry recorded..!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
//Closing Connection with Server
mysql_close($connection);
?>
Change:
if($title !=''||$entry !=''){
to:
if($title !=''&&$entry !=''){
You want to check that both $title and $entry aren't empty, not either-or.
You should definitely use isset() to check the field before insertion into database
the line
<textarea class="input" name="entry" rows="12" cols="75" type="text"> </textarea>
actually adds a space in the entry, change it to
<textarea class="input" name="entry" rows="12" cols="75" type="text"></textarea>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, while I was trying to get some data into my database, I came across this problem, of which I have no clue how to fix it. It just gives no output at all. I am a total newbie to php and database registering. I am able to do some sql.
Also, while I was testing some stuff I came to the conclusion that when I have a small database(just user, email and password) I am able to insert some data into the database. That's why I made two separate databases.
Info about the db:
- Called datingsite
- two tables: 'User' and 'Eigenschappen'
- Both tables have a 'Lidnummer'(INT. Max 255) and set to index and AI
I am using portable xampp 1.8.3
Code:
Connect.php:
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysqli_select_db($connection,'datingsite');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>
Register.php:
<?php
require('connect.php');
/* If the values are posted, insert them into the database.
$sql = "SELECT * FROM `user`";
$res = mysql_query($sql);
$row = mysql_fetch_array($res) or die(mysql_error());
echo $row['email']. " - ". $row['wachtwoord'];*/
if (isset($_POST['email']) && isset($_POST['wachtwoord'])){
$email = $_POST['email'];
$wachtwoord = $_POST['wachtwoord'];
$Voornaam = $_POST['Voornaam'];
$Tweedenaam = $_POST['Tweedenaam'];
$Achternaam = $_POST['Achternaam'];
$Ben = $_POST['Ben'];
$Zoek = $_POST['Zoek'];
$Woonplaats = $_POST['Woonplaats'];
$Provincie = $_POST['Provincie'];
$Hobby1 = $_POST['Hobby1'];
$Hobby2 = $_POST['Hobby2'];
$Dag = $_POST['Dag'];
$Maand = $_POST['Maand'];
$Jaar = $_POST['Jaar'];
$Opleiding = $_POST['Opleiding'];
$query = "INSERT INTO 'user' ('Email', 'Wachtwoord', 'Voornaam', 'Tweedenaam', 'Achternaam', 'Ben', 'Zoek', 'Ingelogd')
VALUES (
'$email',
'$wachtwoord',
'$Voornaam',
'$Tweedenaam',
'$Achternaam',
'$Ben',
'$Zoek')";
$query2 = "INSERT INTO 'Eigenschappen' ('Woonplaats', 'Provincie', 'Hobby1', 'Hobby2', 'Dag', 'Maand', 'Jaar', 'Opleiding')
VALUES (
'$Woonplaats',
'$Provincie',
'$Hobby1',
'$Hobby2',
'$Dag',
'$Maand',
'$Jaar',
'$Opleiding')";
$result = mysql_query($query);
$res = mysql_query($query2);
if(($result)&($res)){
$msg = "User Created Successfully.";
}
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8" />
<title>Registreren op Chives</title>
<link href="../Css/inlog.css" rel="stylesheet"/>
<link href="../Css/styles.css" rel="stylesheet" />
</head>
<body class="back">
<?php
if(isset($msg) & !empty($msg)){
echo $msg;
}
?>
<div id="Inlog-Container" align="center">
<form action="" method="post">
<H1> Registreren </H1>
<H2> Email:</H2>
<input name="email" type="email" class="Input-box" required/>
<H2> Wachtwoord:</H2>
<input name="wachtwoord" type="password" class="Input-box" required/>
<div class="Radiolabelbox">
<fieldset class="" id="" >
<H2>Ik ben een:</H2>
<div class="Radiolabel">
<label>
<input type="radio" name="Ben" class="styled-radio" value="Man" required/>
Man
</label> <br />
<label>
<input type="radio" name="Ben" class="styled-radio" value="Vrouw"/>
Vrouw
</label>
</div>
</fieldset>
<fieldset class="">
<H2 class="">Ik zoek een:</H2>
<div class="Radiolabel">
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Man" required/>
Man
</label>
<br />
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Vrouw"/>
Vrouw
</label>
<br />
<label>
<input type="radio" name="Zoek" class="styled-radio" value="Beide"/>
Beide
</label>
</div>
</fieldset>
</div>
<H2> Woonplaats:</H2>
<input name="Woonplaats" type="text" class="Input-box" required/>
<H2> Provincie:</H2>
<input name="Provincie" type="text" class="Input-box" required/>
<H2> Hobby 1:</H2>
<input name="Hobby1" type="text" class="Input-box" required/>
<H2> Hobby 2:</H2>
<input name="Hobby2" type="text" class="Input-box" required/>
<H2> Voornaam:</H2>
<input name="Voornaam" type="text" class="Input-box" required/>
<H2> Tweede naam:</H2>
<input name="Tweedenaam" type="text" class="Input-box" required/>
<H2> Achternaam:</H2>
<input name="Achternaam" type="text" class="Input-box" required/>
<H2> Geboortedag:</H2>
<input name="Dag" type="Number" class="Input-box" min="0" max="31" required/>
<H2> Geboortemaand:</H2>
<input name="Maand" type="Number" class="Input-box" min="0" max="12" required/>
<H2> Geboortejaar:</H2>
<input name="Jaar" type="Number" class="Input-box" min="1920" max="2000" required/>
<H2> Opleiding:</H2>
<input name="Opleiding" type="Text" class="Input-box" required/>
<input type="submit" value="GA VERDER" class="Roundbutton" id="Login" />
</form>
</div>
</body>
</html>
How can I get to fix my code so I can register into my database?
Any help is appreciated! Thanks in advance!
Ps. I'm sorry for the fact that most of the text in my code is in dutch.
First of all in insert statement use quotes only for text data, number don't need them, and neither table name need them
In if statement if(($result)&($res)) you are using bitwise operator rather you should use if(($result) && ($res)).
Similarly if(isset($msg) & !empty($msg)) here. It should be if(isset($msg) && !empty($msg))
Multiple problems seems in your code:
you are opening a mysqli_connection and using mysql_
$result = mysql_query($query); to run query. That is wrong.
It must be
$result = mysqli_query($connection, $query);
same for
$res = mysql_query($query2);
must be
$res = mysqli_query($connection, $query2);
php mysqli query : http://php.net/manual/en/mysqli.query.php
Check Procedural style in the above link for executing a php mysqli query.
Next:
You dont need ' (quotes) between your table field names when calling an insert query.
But your insert query contains quotes.
Please refer http://www.w3schools.com/php/php_mysql_insert.asp for php mysql insert statement.
Next:
Error in using AND operator
if(($result) & ($res))
Must be
if(($result) && ($res))
(Pointed out be Moid Mohd in his answer)
You have error in your first insert query.You mentioned eight columns but insert only seven values.
Please check and correct it.