Problem with inserting values into database through php

From: Date: Fri, 06 Sep 2002 00:00:13 +0000
Subject: Problem with inserting values into database through php
Groups: php.general 
Request: Send a blank email to php-general+get-115364@lists.php.net to get a copy of this message
Hi, I´m having a weird problem with getting my forms work within php. I have a running MySQL server, php installed on a apache server and I can make SQL queries through php, but I´m unable to insert any data into it through forms. This is an example file that I´m using (it´s from http://hotwired.lycos.com/webmonkey/99/21/index3a_page4.html?tw=programming ) ______________________________ <html> <body> <?php if ($submit) { // process form $db = mysql_connect("localhost", "root", "mypassword"); mysql_select_db("mydb",$db); $sql = "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> First name:<input type="Text" name="first"><br> Last name:<input type="Text" name="last"><br> Address:<input type="Text" name="address"><br> Position:<input type="Text" name="position"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } // end if ?> </body> </html> ____________________________________ I have set the database in working order according to the manual, but after I enter some writing into the text fields and press submit: It refreshes the page and doesn't add any information into the db. I recon that the problem might be within the $php_self command, for I got all the previous php/mySQL tutorials working, but when this command appeared...problems started...or more accurate word would be: nothing happened. I have phpMyAdmin 2.3.0 running on my apache server and it can send/receive data from the db normally, so the problem shouldn't be in the db server or in the php, so it´s in me or in the code :) I have read through all the FAQ:s and manuals that I have found and I still can´t understand what is the problem in this one! -Olli

« previous php.general (#115364) next »