Inserting multiple values into relational database
Posted: Tue Jun 23, 2009 7:53 pm
Hey!
So- I'm trying to take data from a form and insert it into a few different tables. I'm also trying to use the auto incremented IDs that those inserts are generating to then insert into another table. Here's the code I'm using so far that isn't working.
I tried echoing out the variables $projectid and $keywordid and I get nothing. The data for the first 2 inserts is going in the database just fine, so I'm wondering where my error is...
can anybody help me out?
Thanks so much!
So- I'm trying to take data from a form and insert it into a few different tables. I'm also trying to use the auto incremented IDs that those inserts are generating to then insert into another table. Here's the code I'm using so far that isn't working.
Code: Select all
<?php
if(isset($_POST['addContent'])) {
require("sources/connection.php");
$title = $_POST['title'];
$content = $_POST['content'];
$thumbnail = $_FILES['thumbnail']['name'];
$date_posted = $_POST['timestamp'];
$keyword = $_POST['keyword'];
$sql = "INSERT INTO project VALUES ('', '$title', '$thumbnail', '$content', '$date_posted')";
$result = $conn->query($sql) or die(mysqli_error());
$projectid = mysql_insert_id();
$sql2 = "INSERT INTO keywords VALUES ('', '$keyword')";
$result2 = $conn->query($sql2) or die(mysqli_error());
$keywordid = mysql_insert_id();
$sql3 = "INSERT INTO keywordlink VALUES ('$projectid', '$keywordid')";
$result3 = $conn->query($sql2) or die(mysqli_error());
if($result && $result2){
header("location: addNewProject.php?message=1");
}
}
?>can anybody help me out?
Thanks so much!