QwaserBlitz
QwaserBlitz

Reputation: 21

Need help for my <select>

I create a form for PC Rigs, now the problem is, I want to make sure that the selected item be added to my localhost (PHPMyAdmin) and show the added info.

EDIT!!! How can i fix this, if i have Multiple <select>

  <form action="pcbuild.php" method="post">
                <div>
                    <label for="customer">Customer Name: </label>
                    <input type="text" id="customer" name="customer">
                </div>
                <br>
                <div>
                    <label for="email">Email Address: </label>
                    <input type="text" id="email" name="email">
                </div><label>Processor: </label>
            <select name="processor" id="processor">
            <option selected="select1">Please select...</option>
            <option value="intel_high">Intel i5</option>
            <option value="intel_mid">Intel Pentium</option>
            <option value="intel_low">Intel Core2Duo</option>
            <option value="amd_high">AMD A6</option>
            <option value="amd_mid">AMD Anthlon</option>
            <option value="amd_low">AMD Geode</option>
            </select>
  <label>Video Card: </label>
            <select name="gpu" id="gpu">
            <option selected="select2">Please select...</option>
            <option value="nvidia_high">Nvidia GTX 960</option>
            <option value="nvidia_mid">Nvidia GT 450</option>
            <option value="nvidia_low">Nvidia Quadro</option>
            <option value="ati_high">ATI Radeon R9 290X</option>
            <option value="ati_mid">ATI Radeon R7 260X</option>
            <option value="ati_low">ATI Radeon HD 6570</option>
            </select>
  <label>Processor Fan: </label>
            <select name="procfan" id="procfan"> 
            <option selected="select3">Please Select...</option>  
            <option value="proc_high">Deepcool Gammaxx 400</option>
            <option value="proc_mid">Sheen 775</option>
            <option value="proc_low">Stock Fan</option>
            </select> 

If i select Intel i5,GTX 960 and Deepcool Gammaxx it should be added to my server.

$customer = $_POST["customer"];
$email = $_POST["email"];
$selectOption = $_POST['processor'];
$selectOption1 = $_POST["gpu"];
$selectOption2 = $_POST["procfan"];
require ("connect.php");
$stmt = $conn->prepare("INSERT INTO pc_rig (customer,email,processor,gpu,procfan)
VALUES (:customer, :email, :processor,gpu,procfan)");
$stmt->execute ();
header ('Location:rig_finish_list.php');

and show here

require ("connect.php");
       $stmt = $conn->prepare("SELECT *
                              FROM pc_rig
                              ORDER BY customer, email");
       echo "<a href='php_pc_rig.php'>Back to form</a><br><br>" ;

       $stmt->execute();
       while($row=$stmt->fetch(PDO::FETCH_ASSOC))
       {
           echo "<tr>";
           echo "<td> ".$row["customer"]." </td>";
           echo "<td> ".$row["email"]." </td>";
           echo "<td> ".$row["processor"]." </td>";
           echo "<td> ".$row["gpu"]." </td>";
           echo "<td> ".$row["procfan"]." </td>";
           echo "</tr>";
       }

   ?>

Sadly, it seems that the code input cannot be seen on to the server.

Upvotes: 1

Views: 95

Answers (2)

Ikhlak S.
Ikhlak S.

Reputation: 9044

You need to bind the values to your prepared statement. You can bind them using $statement->bindValue(':placeholder', $value)

Your code would look something like this:

 $stmt = $conn->prepare("INSERT INTO pc_rig (customer,email,processor,gpu,procfan)
VALUES (:customer, :email, :processor, :gpu, :procfan)");

$stmt->bindValue(':customer', $customer);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':processor', $selectOption);
$stmt->bindValue(':gpu', $selectOption1);
$stmt->bindValue(':procfan',selectOption1);

$stmt->execute();

Upvotes: 1

channasmcs
channasmcs

Reputation: 1156

<form action ="pagename.php" name="formname" method = "POST">
<select name="processor" id="processor">
        <option selected="select1">Please select...</option>
        <option selected="select1">Please select...</option>
        <option value="intel_high">Intel i5</option>
        <option value="intel_mid">Intel Pentium</option>
        <option value="intel_low">Intel Core2Duo</option>
        <option value="amd_high">AMD A6</option>
        <option value="amd_mid">AMD Anthlon</option>
        <option value="amd_low">AMD Geode</option>
        </select>
      <input type="submit" name="submit" value="Insert">
</form>
<?php 
$selectOption = $_POST['processor'];
require ("connect.php");
$stmt = $conn->prepare("INSERT INTO pc_rig (processor)VALUES('$selectOption')");
$stmt->execute ();
header ('Location:rig_finish_list.php');
?>

for more http://indiainfotip.com/insert-drop-down-list-selected-value-to-mysql-db-using-php/

Upvotes: 0

Related Questions