\n"; #echo "first: $first
\n"; #echo "last: $last
\n"; #echo "

\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 "\n"; echo "\n"; while ($row = $result->fetch_assoc()) { // NULL is equivalent to false // $row is an array with all the values echo ""; echo ''; echo ''; echo ''; echo ""; echo "\n"; } $db->close(); echo "
idfirstlast
'.$row['id'].''.$row['first'].''.$row['last'].'
\n"; ?>


Enter new values:
first:
last: