Monday, April 23, 2007

Code to insert car tables

$db = new mysqli('sql4.phpnet.us', 'pn_461233', 'student1','pn_461233_test');

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$Name = 'Mahogany';
$Size = '25g';
$Cost = 90;
$Quantity = 12;

//if ($mysqli->query("INSERT into myCity (Name) VALUES ('$city')")) {
// printf("%d Row inserted.\n", $mysqli->affected_rows);

if (mysqli_query($db, "INSERT into plants (Name, Size, Cost, Quantity) VALUES ('Mahogony', 'Size', 23, 22)")) {
printf("%d Row inserted.\n", mysqli_affected_rows($db));
}

$result = mysqli_query($db, 'SELECT * FROM plants');
while ($row = mysqli_fetch_object($result)) {
printf(
htmlspecialchars($row->Name)
);
}
mysqli_close($db);

No comments: