Click here to Skip to main content
15,889,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it a bit complicated for me cause i still new...i using the new phpmyadmin and what i learn at school is the old version..i try to use the coding and learn from other website and that make me more confusing..i wanna insert my data to database by using dropdown coding..i try using the same coding with string but its don't work..can somebody help me? This is my coding (sorry its pretty mess and maybe there a typing error) - the upper one its just bootstrap.

What I have tried:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="\Project\bootstrap.min.css">
</head>
  <body style="background:silver;">
<div class="container">
      <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="Gaming.html" style="font-family:verdana,arial;">GamerCen</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
          aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>

          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
              <li class="nav-item active">
                <a class="nav-link" href="Gaming.html">
                  Home<span class="sr-only">(current)</span></a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="product.html">
                  Product</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="logsign in.php">
                  Log In/Sign Up</a>
              </li>
          </div>
        </nav>
        <br>
        <hr>
        <h1 style="text-align:center;">Order</h1>
        <hr>
        <table width="684" height="336" align="center">
          <form method="post">
            <tr>
              <td width="120">Item_Name </td>
              <td width="12">:</td>
              <td width="267"><input name="Item_Name" type="text" size="50" /></td>
           	</tr>
            <tr>
              <td>Price </td>
              <td>:</td>
              <td>
                RM  
                <select name="price">
                <option value="100 (Ori)">100 (Ori)</option>
                <option value="200 (Ori + DLC)">200 (Ori + DLC)</option>
                <option value="300 (Ori + DLC + Mod)">300 (Ori + DLC + Mod)</option>
              </select></td>
            </tr>
            <tr>
              <td>Quantity </td>
              <td>:</td>
              <td colspan="2">
              <select name="quantity">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
              </select></td>
            </tr>
            <tr>
              <td>Address</td>
              <td>:</td>
              <td><textarea name="Address" cols="53"></textarea> </td>
            </tr>
            <tr>
              <td align="center" colspan="3"><input type="submit" name="submit"></td>
            </tr>
          </form>
        </table>
        <?php
        $conn = mysqli_connect("localhost","root","","project");
        if($conn === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
        }
        if (isset($_REQUEST['save'])) {
          $Item_Name = real_escape_string($_REQUEST['Item_Name']);
          $price = real_escape_string($_REQUEST['price']);
          $quantity = real_escape_string($_REQUEST['quantity']);
          $Address = real_escape_string($_REQUEST['Address']);
          $sql = "INSERT INTO order(Item_Name,price,quantity,Address) VALUES ('$Item_Name', '$price', '$quantity', '$Address')";
        }
            if(mysqli_query($conn, $sql)){
            echo "Records added successfully.";
            } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
            }
            mysqli_close($conn);
         ?>
  </body>
</html>
Posted
Updated 29-Sep-18 17:36pm

1 solution

There is full working PHP code to connect to a database and enter stuff in my "Some Simple PHP Classes for Managing PayPal Instant Payment Notifications[^]" article that might be useful. It doesn't address the data source side of your problem, but takes care of the rest. Of course, you will have to modify it to write to the correct tables and columns for your case.
 
Share this answer
 
Comments
Member 13997743 2-Oct-18 0:29am    
thanks david

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900