\n"; if (!empty($last) && !empty($first)) { $db = @new mysqli($dbhost, 'webapp', 'webapp', 'webapp'); # host, login, password, database if (mysqli_connect_errno()) { die ('Cannot connect to database: '.mysqli_connect_error().'('.mysqli_connect_errno().')'); } # Check if ID already present $sql = "SELECT * from names where last like '$last' and first like '$first'"; $result = $db->query($sql); if (!$result) { die ("Something's wrong with the query: ".$db->error); } if ( $result->num_rows > 0 ) { # Already there echo "last/first $last/$first already present, not added to DB!
\n";
} else {
# Not there - insert!
$sql="insert into names (last, first) values ('$last', '$first')";
if ($db->multi_query($sql) == FALSE) {
# failure
echo "DB insert FAIL: ".$db->error.",
SQL: $sql\n";
} else {
# success
echo "DB insert of last/first $last/$first success.\n";
}
}
$db->close();
} ?>
Showing table hf.names:
query($sql);
if (!$result) {
die ("Something's wrong with the query: ".$db->error);
}
#echo 'There are '.$result->num_rows." entries.
\n";
echo "
id | first | last |
---|---|---|
'.$row['id'].' | '; echo ''.$row['first'].' | '; echo ''.$row['last'].' | '; echo "