The aray $_POST is always set, therefore isset($_POST) always return true, no need to check that.
What's
$insert;
supposed to do?
echo $display;
That will print the string currently stored in $display and that is
SELECT first_name, email FROM contacts. sql statements are just strings to php, they have no special meanings for it. You have to send your statements to the sql server. see
http://php.net/mysql_query.
The way you've placed your mysql operations suggest that you might not have grasped how php is working. There's no need to place the insert-code "within" the form element after the input elements. Neither will the browser execute the php code (it's been done server-side before the browser waits for the user input) nor will php wait for the user input and then (by magic) grab the values from the client.
try
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$user="#####";
$password="#####";
$host = "mysql.akimm.com";
$mysql = mysql_connect($host,$user, $password) or die(mysql_error());
mysql_select_db("akimm0co", $mysql) or die(mysql_error());
if ( isset($_POST['firstname'], $_POST['lastname'], $_POST['mailaddress']) ) {
/*
you might want to do more checkings here
apperently valid mail address
string length, whatever
important: secure parameters against sql injections
strings => mysql_real_escape_string
*/
$fname = mysql_real_escape_string($_POST['firstname'], $mysql);
$lname = mysql_real_escape_string($_POST['lastname'], $mysql);
$mail = mysql_real_escape_string($_POST['mailaddress'], $mysql);
$query = "INSERT INTO
contacts
(first_name, last_name, email)
VALUES
('$fname', '$lname', '$mail')";
$result = mysql_query($query, $mysql) or die(mysql_error());
echo '<pre>executed: ', htmlentities($query), '</pre>';
}
?>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST">
<table>
<tr>
<th>Your first name</th>
<td><input type="text" name="firstname" />
</tr>
<tr>
<th>Your last name</th>
<td><input type="text" name="lastname" />
</tr>
<tr>
<th>Your email address</th>
<td><input type="text" name="mailaddress" />
</tr>
<tr>
<td colspan="2"><input type="submit" /></td>
</tr>
</table>
</form>
<?php
$query = 'SELECT first_name, email FROM contacts';
$result = mysql_query($query, $mysql) or die(mysql_error());
echo '<table border="1"><tr><th>first name</th><th>email address</th></tr>', "\n";
while ( $row=mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo '<tr><td>', htmlentities($row['first_name']), '</td><td>', htmlentities($row['email']), "</td></tr>\n";
}
echo "<table>\n";
?>
(untested)