Hi

Add records with this code.
<?php
$name=isset($_POST['name']) ? $_POST['name'] :'';
$address=isset($_POST['address']) ? $_POST['address'] :'';
if (!empty($name)) {
mysql_connect($server,$user,$pass) or die ("Error conecting");
mysql_select_db($dbnamn,$conection) or die ("no db ".$dbnamn);
$query = "insert into mytable (name, address) values ('$name', '$address')";
$result = mysql_query ($query) or die("bad query");
}
?>
<html>
<head></head>
<body>
<form action="" method="post">
name <input name="name">
address <input name="address">
<input type="submit" value="add record">
</form>
</body></html>

Hope this helps.
Jan


"Nicolai Elmqvist" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> Hi
>
> I have just started working with PHP and MySQL and have gone through 3
> tutorials on how to add and delete records from a database. Nearly
> everything is working, as it should except for the communication between
> HTML <form> and PHP. If I try to add a record to my database by pushing a
> "submit" the text in the textboxes are deleted but no record is inserted
in
> the database. I have copied the code directly form the tutorials so
spelling
> mistakes should not be the problem.
>
>
>
> It is possible to add records manually in the code so the connection to
and
> from the database is ok.
>
>
>
> So, does anybody know what I the problem might be?
>
>
>
> I'm using PHP 4.3.4, MySQL 4.0.17 and an Apache server.
>
>
>
> On before hand, thank you.
>
> Nicolai Elmqvist

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to