I'm building a simple bug tracker tool, but I have a problem.
When you create a new project, you get redirected to the project page, there you can add a new bug to the project. You have a 'projects' table and a 'bugs' table in the MySQL db (phpmyadmin).
The new bug will be added in the 'bugs' table, but how can I add the project id to the bugs table?
I already added 'fk_project_id' as a foreign key to the 'bugs' table.
this is a code snippet from the project page (here, you select all the info from the project):
$id = $_GET['id'];
$con=mysqli_connect("localhost","root","","bugslap");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM projects where projects_id = $id");
mysqli_close($con);`
and here you will be redirected to a form where you can add a new bug:
<a href="newbug.php">add a new bug</a>
when you submit the form, it will run this script (bug.class.php):
$name = $_POST['name'];
$descr = $_POST['description'];
$leader = $_POST['leader'];
$img = $_POST['img'];
$sql="INSERT INTO bugs (name, description, leader, img, registration_date,fk_project_id)
VALUES ('$name', '$descr', '$leader', '$img', NOW())";
$result = mysql_query($sql);
if($result){
header('Location: ../projectpage.php');
}
else {
echo "Oops, there is something wrong. Try again later.";
}
mysql_close();
Then you should be redirected to the project page, where the bug is added to the project. I want to show all the bug info (description,image,...) on this project page.
You have to provide the project id to the newbug.php page; for example with a GET parameter. Then you can easily fetch it from newbug.php and pass it on to your class.