0

This is my HTML code

<div class="control-group">
    <div class="controls form-inline">
    <input type="text" name="plot_id" class="form-control" disabled="true" value="<?php echo $plot_id; ?>" style="width: 50px;" />
    <input type="text" name="khasra_id" class="form-control" disabled="true" value="<?php echo $khasra_id; ?>" style="width: 50px;"/>
    Plot Number : <input type="text" name="plot[]" class="form-control" placeholder="Ex 113A/113B/113C"/>
    Area : <input type="text" name="plot[]" class="form-control" required="required" placeholder="Ex 1000 sq ft "/>
    <input type="text" name="tot" class="form-control" disabled="true" value="<?php echo $tot; ?>" style="width: 50px;"/>
    Facing : <input type="text" name="plot[]" class="form-control" required="required" placeholder="Ex North/East" />
    Type : <input type="text" name="plot[]" class="form-control" required="required" placeholder="Ex Ressidental/Comm" />
    Status : <select class="form-control" name="plot[]">
    <option value="Available">Available</option>
    <option value="Book">Book</option>
    </select>
    </div>
</div>
<br/>

This is my php code

if(isset($_POST['final_split'])){
                       $con=mysqli_connect("localhost","******","******","********");
                       if (mysqli_connect_errno()){
                         echo "Failed to connect to MySQL: " . mysqli_connect_error();
                       }
                       foreach ($_POST as $key => $value) {
$insert_into  = mysqli_query($con,"INSERT INTO plot_deatils(plot_id,khasra_id,plot_number,area,tot,facing,typee,statuss) VALUES(
 '$_POST[plot_id]','$_POST[khasra_id]','$_POST[plot][0]','$_POST[plot][0]','$_POST[tot]','$_POST[plot][0]','$_POST[plot][0]','$_POST[plot][0]',   
 )");
                       }
                   }

This is my code where i have wrote the db connection. please some one can help me to solve the above problem which i want to insert the above code to db through the post array data

7
  • You never create a database connection. You are going to need a database, MySQL is a good free option that interacts well with PHP. Commented Apr 3, 2014 at 14:08
  • 1
    please post all relevant Code. I see no <form> tag here, did you forget to put it here, or don't you have it in your page ? As such, it will actually never post anything... and if it does, I see no database connection neither so it wouldn't insert anything. Commented Apr 3, 2014 at 14:08
  • Is your database table called TABLE? Commented Apr 3, 2014 at 14:09
  • 2
    The code fragments you posted are incomplete in several ways, as noted above. You should research getting started with MySQL, and then how to interact with your tables using PHP. Also, writing queries that way (with $_POST vars directly in the string) is a HUGE security hole. Commented Apr 3, 2014 at 14:14
  • You should create a database connection as @mituw16 said. Check for mysqli_* or PDO functions in the php documentation. Commented Apr 3, 2014 at 14:15

1 Answer 1

1

You're just echoing your INSERT statement, if you want it to write in your DB you need to establish a database connection with MySQLi and write your insert as a query, eg:

$db = new mysqli('127.0.0.1', 'user', 'password', 'database_name');

$stmt = $db->prepare("YOUR INSERT STATEMENT HERE");
$stmt->bind_param( BIND YOUR POST PARAMETERS HERE );
$stmt->execute();
$stmt->close();

This is a pretty technical task and doing it wrong can break things in so many ways so I recommend you thoroughly read the documentation before attempting this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.