doctorbill
asked on
php and mysqli
This code is working:
What I need to do is add in another section from a second form on the same page which will add data to the same database fields
The field names for demo sake will be name1, name2, name3, name4
Can someone give me a pointer on how to add the second query
I just need the structure
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "xxxxxxx";
$dbname = "ticktock";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO itdocs (title, details, loc, Type)
VALUES ('".$_POST["doc_name"]."','".$_POST["doc_details"]."','".$_POST["doc_location"]."','".$_POST["doc_type"]."')";
if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
What I need to do is add in another section from a second form on the same page which will add data to the same database fields
The field names for demo sake will be name1, name2, name3, name4
Can someone give me a pointer on how to add the second query
I just need the structure
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I have so far:
The first set of code between the first php tags works from a form on the page
The second one from a second form on the page does not
The first set of code between the first php tags works from a form on the page
The second one from a second form on the page does not
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "ticktock";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO itdocs (title, details, loc, Type)
VALUES ('".$_POST["doc_name"]."','".$_POST["doc_details"]."','".$_POST["doc_location"]."','".$_POST["doc_type"]."')";
if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
<?php
if(isset($_POST["it_doc_name"])){
$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "ticktock";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO itdocs (title, details, loc, Type, file_view)
VALUES ('".$_POST["it_doc_name"]."','".$_POST["it_doc_details"]."','".$_POST["it_doc_location"]."','".$_POST["it_upload"]."','".$_POST["it_doc_type"]."')";
if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The second set of php code does not add the details to the database
ASKER
This is the error when I get when I submit the form using the second set of php code
array(0) { }
array(0) { }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it
There was a rogue form tag on my page
Sorry to have wasted everyone's time on such a small issue
working now
There was a rogue form tag on my page
Sorry to have wasted everyone's time on such a small issue
working now
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Really appreciate everyone's help
I learn so much from you guys
Good working with you all
I learn so much from you guys
Good working with you all
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all
ASKER
completed
ASKER
But what about my question - can I have a pointer please