Sunday, 15 December 2019

php - How to handle multiple forms?, stop reloading page on submit?


  1. First form is where client can get all products by Make Model and Price as radio button with value of there id in database


  2. Client click submit.


  3. PHP ask isset name of submit button


  4. If isset it echos second form where client can add specifications for product that he or she choose. Form is input type text and textarea's



  5. Then php ask isset name of submit button for second form




but the problem is when client press submit for second form



If first form is unset then the rest of code should check that second form don't exist because both forms most exit for code to work and I can get that, if I don't find away to stop page reload on submit



I try using AJAX but the MySQL query throws an error that inputs are empty.



JavaScript code:








PHP code:



echo  "




";
$sql="select * from produkt ";

$rez=mysqli_query($db,$sql);
while($red = mysqli_fetch_object($rez))
{
echo " ". $red->marka." ". $red->naziv." ". $red->cena."
";
}
echo "





";

if (isset($_POST['btnsubmit1'])) {
$id = $_POST['proizvod'];

echo "






placeholder='Description Of The Motherboard ( ASUS H81M-R/C/SI )'>

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 "";
}
}
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...