表1:
Countries:
country_id
country
表2:
User:
user_id
country_id
first_name
infix
last_name
user_name
password
表3:
train_information:
train_id
country_id
user_id
train_name
etc.
当我创建新用户时,我只需选择国家/地区的号码(手动进入)。
但是当用户登录并添加火车时。信息转到train_information
。但是它将country_id和user_id保留为NULL。如何让登录用户自动填写?
编辑:
add_train.php
<?php
require 'top.php';
?>
<div id="left">
left
</div>
<div id="center">
<div id='toevoegen_trein'>
<form action="add_train_send.php" method="post">
<table>
<tr>
<td>Train Name:</td>
<td><input type="text" name="train_name" required><br></td>
</tr>
<tr>
<td>Tare Weight:</td>
<td><input type="text" name="tare_weight" required><br></td>
</tr>
<tr>
<td>Number of Bogies:</td>
<td><input type="text" name="number_of_bogies" required><br></td>
</tr>
<tr>
<td>Number of Axles:</td>
<td><input type="text" name="number_of_axles"><br></td>
</tr>
<tr>
<td>Wheel Diameter Minimal:</td>
<td><input type="text" name="wheel_diameter_min"><br></td>
</tr>
<tr>
<td>Wheel Diameter Maximal:</td>
<td><input type="text" name="wheel_diameter_max"><br></td>
</tr>
<tr>
<td><input type="submit" name="toevoegen" value="Next"></td>
</tr>
</table>
</form>
</div>
</div>
<div id="right">
right
</div>
<?php
require 'bottom.php';
?>
add_train_send.php
<!--This is the header of the site-->
<?php
require 'top.php';
?>
<!--This is the left side of the page-->
<div id="left">
left
</div>
<!--This is the center of the page (Where the most content is)-->
<div id="center">
<?php
//Train is send here//
$add_train = $database->train_add();
?>
Train: <?php echo $_POST['train_name']; ?>
<!--Here we make the number of fields based on the number of axles-->
<div id="axle_bogie_border">
<!--The image of the train-->
<img src="Images/axle_train.png" alt="train">
<!--The show axles are the number of checkboxes (Filled in by a user)-->
<div id="show_axles">
<?php
$_POST['number_of_axles'];
if(isset($_POST['number_of_axles'])){
for($i=0; $i<$_POST['number_of_axles']; $i++){
echo "<div id='axle_figure'>" . $i . "</div>";
}
}
?>
</div>
<br /> <br />
<div id="show_bogies">
<?php
$_POST['number_of_bogies'];
if(isset($_POST['number_of_bogies'])){
for($i=0; $i<$_POST['number_of_bogies']; $i++){
echo "<input type='checkbox' name='bogies[$i]'>";
}
}
?>
</div>
</div>
</div>
<!--This is the right side of the page-->
<div id="right">
right
</div>
<!--This is the footer of the website-->
<?php
require 'bottom.php';
?>
功能:
function train_add() {
$sql = "INSERT INTO train_information "
. "(train_name, tare_weight, number_of_bogies, number_of_axles, wheel_diameter_min, wheel_diameter_max)"
. "VALUES (:train_name, :tare_weight, :number_of_bogies, :number_of_axles, :wheel_diameter_min, :wheel_diameter_max) ";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(':train_name', $_POST['train_name'], PDO::PARAM_STR);
$sth->bindParam(':tare_weight', $_POST['tare_weight'], PDO::PARAM_STR);
$sth->bindParam(':number_of_bogies', $_POST['number_of_bogies'], PDO::PARAM_STR);
$sth->bindParam(':number_of_axles', $_POST['number_of_axles'], PDO::PARAM_STR);
$sth->bindParam(':wheel_diameter_min', $_POST['wheel_diameter_min'], PDO::PARAM_STR);
$sth->bindParam(':wheel_diameter_max', $_POST['wheel_diameter_max'], PDO::PARAM_STR);
$sth->execute();
}