|
Posted by tomhughes_86 on 02/07/07 17:54
Hi,
I'm basically creating a system which add records to a pre made SQL
database built in SQLyog.
So far i'va had no problems actually connecting to the database and
displaying resulst but I just cannot make it add records. I know its
connected to the database as a I made a mistake with connection
details on purpose to see if it recognised it.
I just add data into a text field, click submit and the page goes to
a
new, blank page with no changes to the table when I check in SQLyog.
Any help would be much appreciated, as I am very new to PHP.
Thanks Tom.
Here is the code I have tried (simple add before I code the proper
system):
HTML page
<form action="script.php" method="post">
Test: <input type="text" name="test2"><br>
<input type="Submit">
</form>
and the PHP script to add data:
<?
$host="localhost"
$username="root";
$database="test";
$test2=$_POST['test2'];
mysql_pconnect($host,$username);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO test2 VALUES ('','$test2')";
mysql_query($query);
mysql_close();
?>
Navigation:
[Reply to this message]
|