MySQL Forums
Forum List  »  PHP

Re: insert array
Posted by: Stephen Van Tuyl
Date: February 26, 2017 11:28AM

OOPS! Sorry. Wrong code. Couldn't figure out how to delete or edit so here's the code I meant to put up.

<?php
$servername = "localhost";
$username = "evensteven";
$password = "RuffleFrump";
$dbname = "hosts";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$client = array(
"0" => array("name" => "Peter Maxx", "ip" => "193.169.5.16"),
"1" => array("name" => "Ravi Shankar", "ip" => "193.169.5.17")
);

if(is_array($client)) {
$DataArr = array();
foreach($client as $row) {

$DataArr[] = "('". mysqli_real_escape_string($conn, $row["name"]) ."', '". mysqli_real_escape_string($conn, $row["ip"]) ."')";
}
$sql = "INSERT INTO ip_data (name, ip)
VALUES
('Peter Maxx', '193.169.5.16'),

('Ravi Shankar', '193.169.5.17'),";

$sql .= implode(", " , $DataArr);
mysqli_query($conn, $sql);

}
?>

Options: ReplyQuote


Subject
Written By
Posted
February 26, 2017 11:23AM
Re: insert array
February 26, 2017 11:28AM
February 26, 2017 12:02PM
February 26, 2017 12:56PM
February 26, 2017 01:19PM
February 26, 2017 02:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.