The request to add from the combobox doesn’t work

Can’t add with combobox


<form method="kolstud" action="kolstud.php">
<select name="namebook">
 <option value="0"> </option>
<?
$res = mysql_query('select `idbook`, `name` from `book`');
while($row = mysql_fetch_assoc($res)){
    ?>
    <option value="<?=$row['idbook']?>"><?=$row['name']?></option>
    <?
}
?>
</select>
 <select name="FIOstud">
    <option value="0"> </option>
<?
$res = mysql_query('select `idstudent`, `FIO` from `student`');
while($row = mysql_fetch_assoc($res)){
    ?>
    <option value="<?=$row['idstudent']?>"><?=$row['FIO']?></option>
    <?
}
?>
</select>
 <input type="submit" name="Submit2" value=""/>
</form>
<?php
            $namebook = $_REQUEST['namebook'];
            $FIOstud = $_REQUEST['FIOstud'];
$insert = "INSERT INTO `kolstud` VALUES (
 ( SELECT `idbook` FROM `book` WHERE `name` = '$namebook' ),
( SELECT `idstudent` FROM `student` WHERE `FIO` = '$FIOstud' ))";
if($namebook != "")
                    {
                            mysql_query($insert,$dblink);
                    } 
?>

Answer 1

$insert = "INSERT INTO `kolstud` (`_1`, `_2`) VALUES (
 ( SELECT `idbook` FROM `book` WHERE `name` = '$namebook' ),
( SELECT `idstudent` FROM `student` WHERE `FIO` = '$FIOstud' ))";

Pay attention to the fields (_1and _2) that you want to fill in. Also, if there are more fields in the table (not including autoincrement), they should also be in the query.

Syntax INSERTwith examples

UPD:ok, then comment the result of this code (insert before $insert = ...)

echo '<pre>';
var_dump($namebook, $FIOstud, $_REQUEST, $insert);
echo '</pre>';

UPD2:I’m sorry, I didn’t notice right away)) You receive an idbook, not a namebook, so there is no need for the first SELECT, it is already selected. %) Sorry, idstudent has already been selected, why are you perverting at all?)

$insert = "
  INSERT INTO `kolstud` VALUES (
    $namebook,
    $FIOstud
    )
  ";

Rename variables only