I have a form that gathers the user’s data and inputs them into the database. There is specifically an id variable that is defined before inputting all the different data in table 1. But I also need to input this id variable, with the same value from table 1, INTO table 2. The code is below:
function random_num($length)
{
$text = "";
if($length < 5)
{
$length = 5;
}
$len = rand(4,$length);
for ($i=0; $i < $len; $i++) {
$text .= rand(0,9);
}
return $text;
}
$id = random_num(20);
$query = "insert into firsttable (id) values ('$id')";
mysqli_query($connection, $query);
$query2 = "insert into secondtable (id) values ('$id')";
mysqli_query($connection, $query2);
But when I go look into both tables, the id being sent in both is different. But that doesn’t make sense since I defined the variable only once, to then send the same value to both tables.
I just needed the value to be the same on both.. I’m quite new to php, so possibly this is some dumb error.