Hi i want to find a way to create a page html that can insert data into table that has foreign key (drop-down value) the value will get from the other primary table so i try with simple table to test but with no luck it show the page but when the submit button enter their are no data insert
can anyone help me please
so first the table i do something like this
Table Name : proj
proj_id int(15) PK + AI
proj_name varchar(30)
Table Name : user
user_id int(15) PK + AI
user_name varchar(30)
proj_id int(15) FK
the code
Folder Name :input.php
<html>
<head>
<title>
INPUT INTO PROJ
</title>
</head>
<body>
<form name="form1" method="post" action="insert.php">
User ID: <input type="text" name="user_id" size="50"><br>
User Name: <input type="text" name="user_name" size="50"><br>
Proj ID: <input type="text" name="proj_id" size="50"><br>
<input type="submit" name="button" value="save">
</form>
</body>
</html>
Folder Name : insert.php
<?php
$severname = "localhost";
$username = "root";
$password = "";
$dbname = "proj";
//Create connection
$conn = new mysqli($severname, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
session_start();
include('input.php');
$user_id=$_POST['user_id'];
$user_name=$_POST['user_name'];
$proj_id=$_POST['proj_id'];
$qry="SELECT * FROM proj WHERE proj_id=$proj_id";
$result = mysqli_query($qry);
$num_rows = mysqli_num_rows($result);
if($num_rows > 0){
mysqli_query("INSERT INTO user(user_id, user_name, proj_id) VALUES('$user_id', '$user_name', $proj_id)");
}else{
echo "Team is not valid!!!";
}
mysqli_close($con);
header("location: input.php?remarks=success");
mysqli_error($con);
?>
i try insert data manually from phpmyadmin it work and it event show the drop down list i not sure how to do it with html and php.
i hope someone can tell me what should i do, i really new to this php and mysql. thank you