第一種形式就是客戶可以得到所有產品的品牌型號和價格爲單選按鈕與有ID的值在數據庫如何處理多個表單?,提交時停止重新加載頁面?
客戶端點擊提交。
PHP要求提交按鈕
如果isset它回聲第二種形式,其中客戶端可以爲產品,他或她選擇添加規格isset名。形式是輸入型文本和文本區域的
那麼PHP請求第二種形式
提交按鈕isset名字,但問題是,當客戶按提交第二種形式
如果第一種形式是未設置那麼代碼的其餘部分應該檢查,第二種形式不存在,因爲這兩種形式的代碼大部分退出工作,我可以得到,如果我沒有發現停止頁面重新加載提交
我嘗試使用AJAX但MySQL查詢會拋出一個輸入爲空的錯誤。
JavaScript代碼:
<script>
$(document).ready(function() {
$('.link').click(function(){
$.post('ajax1.php?strana='+$(this).attr('strana'), function(odgovor) {
$('#odgovor').html(odgovor);
});
});
});
</script>
PHP代碼:
echo "<div class='container' id='cars'>
<div class='row'>
<div class='col-md-4 col-md-offset-4 text-center'>
<form action='' method='post' class='loginForm' id='cmsC' name='cmsC' enctype='multipart/form-data'>
<div class='input-group'>";
$sql="select * from produkt ";
$rez=mysqli_query($db,$sql);
while($red = mysqli_fetch_object($rez))
{
echo "<input type='radio' name='proizvod' value='$red->id'> ". $red->marka." ". $red->naziv." ". $red->cena."<br>";
}
echo "<input type='submit' id='btnsubmit1' name='btnsubmit1' class='form-control' value='Chouse Product' >
</div>
</form>
</div>
</div>
</div>";
if (isset($_POST['btnsubmit1'])) {
$id = $_POST['proizvod'];
echo "<div class='container'>
<div class='row'>
<div class='col-md-4 col-md-offset-4 text-center'>
<form action='' method='post' class='loginForm' id='cms' name='cms' enctype='multipart/form-data'>
<div class='input-group clear'>
<input type='text' id='dotm' name='dotm' class='form-control'
placeholder='Description Of The Motherboard (ASUS H81M-R/C/SI)'>
<input type='text' id='top' name='top' class='form-control'
placeholder='Type Of Processor (Intel® Core™ i3 Processor)'>"; // there is bunch more of this type for input type
if (isset($_POST['submit'])) {
// Variable with data from form
$description_of_the_motherboard = $_POST['dotm'];
$type_of_processor = $_POST['top'];
$processor_description = $_POST['pd'];
$type_of_graphics_card = $_POST['togc'];
if(strlen($description_of_the_motherboard)!="") {
if(!preg_match("/[^\w\s,.\\\'\"\-\/]/", $description_of_the_motherboard) {
$sql = "insert query";
mysqli_query($db, $sql);
} else echo "<script>
alert('Your input can not have special characters ');
</script>";
}
}
}