Reputation:
This is my code working on plugin need to insert 2 arrays into phpmyadmin but something wrong with forach loop of php...any solution.... any alternate solution how to insert?
if (isset($_POST['addvenue'])) {
<?php echo "<pre>".print_r($_POST['RoomTilte'],true)."</pre>";
echo "<pre>".print_r($_POST['Capacity'],true)."</pre>";
mysql_connect("localhost","root","");//database connection
mysql_select_db("ossd");
$a=array($_POST['RoomTitle']);
if (is_array($a))
{
echo"yes it is array";
foreach ($_POST['RoomTitle'] as $row=>$name)
{
$Roomtitle = $name;
$Capacity = $_POST['Capacity'][$row];
$RoomTitle= mysql_real_escape_string($name);
$Capacity = mysql_real_escape_string($_POST['Capacity'][$row]);
$order = "INSERT INTO wp_ossd_venue
(RoomTitle,Capacity)
VALUES
(".$RoomTitle.",".$Capacity.")";
$result = mysql_query($order);
}
}
if($result){
echo("<br>Succesfully Added");
} else{
echo("<br>Fail... Error");
}
}
Upvotes: 0
Views: 88
Reputation: 1662
Would be much easier if you use the wordpress $wpdb class to work with the database.
Refer the wordpress codex for following function:
<?php $wpdb->insert( $table, $data, $format ); ?>
http://codex.wordpress.org/Class_Reference/wpdb#INSERT_rows
Upvotes: 1