martynball
New Member
- Messages
- 60
- Reaction score
- 0
- Points
- 0
I can read the values in my database which I manually added for testing, but I cannot add new values into the database... I am following this tutorial:
http://teamtutorials.com/web-develo...nserting-data-into-a-mysql-database-using-php
Here is my code (Password removed of course):
update.php:
Database Name: martynba_comments
Database User Name: martynba_martynba
Table Name: commentTable
Table Columns: ID, FNAME, LNAME, PHON
http://teamtutorials.com/web-develo...nserting-data-into-a-mysql-database-using-php
Here is my code (Password removed of course):
PHP:
<html>
<head>
<title>Database Test</title>
<?php
// Connect to the database server
mysql_connect('localhost', 'martynba_martynb', 'password') or die('Error connecting to the database, MySQL returned: ' . mysql_error());
// Select the database
mysql_select_db('martynba_comments') or die('Error selecting database, MySQL returned: ' . mysql_error());
//Build query
$query = mysql_query("SELECT * FROM commentTable");
//Display results
while ($row = mysql_fetch_array($query)) {
echo "<br /> ID: " .$row['ID'].
"<br /> First Name: ".$row['FNAME'].
"<br /> Last Name: ".$row['LNAME'].
"<br /> Phone Number: ".$row['PHON'];}
?>
</head>
<body>
<hr />
<form medthod="post" action="update.php">
First Name:<br />
<input type="text" name="FName" size="30" /><br />
Last Name:<br />
<input type="text" name="LName" size="30" /><br />
Phone Number:<br />
<input type="text" name="PHON" size="12" /><br />
<input type="submit" value="Update Database"/>
</form>
</body>
</html>
PHP:
<?php
$FNAME = $_POST['FName'];
$LNAME = $_POST['LName'];
$PHON = $_POST['PHON'];
mysql_connect ("localhost", "martynba_martynb", "password") or die ('Error: ' . mysql_error());
mysql_select_db ("martynba_comments");
$query="INSERT INTO commentTable (ID, FNAME, LNAME, PHON)
VALUES ('NULL','".$FName."','".$LName."','".PHON."')";
echo "Database Updated With: " .$FName. " ".$LName." ".$PHON ;
?>
Database Name: martynba_comments
Database User Name: martynba_martynba
Table Name: commentTable
Table Columns: ID, FNAME, LNAME, PHON