Я пытаюсь использовать оператор подготовки MySQLi для вставки значений в мою таблицу OpenJobs.У меня есть 4 флажка, приравнивающих к 4 различным работам.Если один или несколько флажков помечены, я хочу, чтобы соответствующий идентификатор вакансии был вставлен в таблицу.Вот код, который я написал до сих пор:
<form id="frmSelStore" method="post" action ="<?php
$restaurantid = $_POST['ddlStore'];
$jobtype = $_POST['jobs'];
if($stmt = mysqli_prepare($mysqli,'Insert into OpenJobs values $restaurantid, $jobtype'))
{
mysqli_stmt_bind_param($restaurantid,$jobtype);
mysqli_stmt_execute($stmt);
echo '$jobtype was posted for Store $restaurantid';
mysqli_stmt_close($stmt);
}
?>">
Остальная часть формы:
<fieldset><?php
$query=('SELECT restaurantid,location from restaurant');
$result = mysqli_query($mysqli,$query);
echo '<select name="ddlStore">';
while($row=mysqli_fetch_array($result))
{
echo '<option value="' . htmlspecialchars($row['restaurantid']) . '">' .
htmlspecialchars($row['location']) .
'</option>';
}
echo '</select>';
?>
<h2>Step 2: Please Select the Jobs to be Posted</h2>
<input type="checkbox" name='[jobs]' id="cbJobs1">Host/Hostess
</input><br/>
<input type="checkbox" name='[jobs]' id="cbJob2">Bartender</input><br/>
<input type="checkbox" name='[jobs]' id="cbJob3">Server</input><br/>
<input type="checkbox" name='[jobs]' id="cbJobs4">Cook</input><br/>
<input type="submit" id="submit"/>
</fieldset>
Когда я поставлю флажок и нажму "Отправить", я ожидаю, что сообщение будет повторено, чтомои вакансии были опубликованы.Однако ничего не происходит и никакие записи не записываются в таблицу.Как это исправить?
Обновление: я немного отполировал свой код следующим образом:
<form id="frmSelStore" method="post" action ="<?php
$restaurantid = $_POST['ddlStore'];
$jobtype = $_POST['jobs'];
$stmt = mysqli_statement_init($mysqli);
if(mysqli_stmt_prepare($stmt,'Insert into `OpenJobs` (`restaurantid`,`jobtype`)
values ($restaurantid, $jobtype'))
{
mysqli_stmt_bind_param($stmt,$restaurantid,$jobtype);
mysqli_stmt_execute($stmt);
printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));
mysqli_stmt_close($stmt);
}
?>">
Когда я просматриваю свою страницу, я вижу следующие ошибки:
Warning</b>: mysqli_stmt_bind_param() expects
parameter 1 to be mysqli_stmt, null given in
<b>/path/to/page</b> on line
<b>23</b><br /><br /><b>Warning</b>: mysqli_stmt_execute() expects parameter 1 to be
mysqli_stmt, boolean given in <b>/path/to/page</b>
on line <b>24</b><br />$jobtype was posted for Store
$restaurantid<br /><b>Warning</b>:
mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in
<b>/path/to/page</b> on line <b>26</b><br /> was not
found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
Я следую ручным примерам процедурного метода, но мне нужно немного советов, как исправить вышеуказанные ошибки.