DEVILofDARKNESS Posted January 25, 2009 Share Posted January 25, 2009 What have I done wrong here! it always give me the message ERROR4 even if I don't fill in the form!. I used to work with [$_POST] but I read on an other website it should be with [$_GET], and ofcourse it didn't work either. <html> <head><title>Gedichten</title> </head> <body> <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $query = sprintf("SELECT COUNT(DISTINCT URL) FROM liefde"); $result = mysql_query($query); list($url) = mysql_fetch_row($result); $url = $url + 1; print "<form action='' method='GET'> Your Name: <input type='text' maxlenght='20' Name='UName'><br> Poem Name: <input type='text' maxlenght='25' Name='PName'><br> Poem Text: <textarea COLS='60' ROWS='5' Name='PText'></textarea> <input type='hidden' name='URL' Value='{$url}'><br> <input type='submit' Value='Add!' name='submit'> <input type='reset'> </form>"; if($_GET) { if(!IsSet($_GET['PName'])) { //print "<script type='text/javascript'>alert('You have not write a Poem Name!');</script>"; print "ERROR"; } elseif(!IsSet($_GET['UName'])) { //print "<script type='text/javascript'>alert('You have not write Your Name!');</script>"; print "ERROR2"; } elseif(!IsSet($_GET['PText'])) { //print "<script type='text/javascript'>alert('You have not write a Poem!');</script>"; print "ERROR3"; } else { $query = sprintf("INSERT INTO liefde(PName,UName,PText,URL) VALUES ('{$_GET['PName']}','{$_GET['UName']}','{$_GET['PText']}','liefde{$_GET['URL']}'"); $result = mysql_query($query); //print "<script type='text/javascript'>alert('Well done, the Poem is added to the love caegory');</script>"; print "ERROR4"; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/142340-php-to-mysql-problem2/ Share on other sites More sharing options...
DeanWhitehouse Posted January 25, 2009 Share Posted January 25, 2009 change if($_GET) to if(isset($_GET['submit'])) Quote Link to comment https://forums.phpfreaks.com/topic/142340-php-to-mysql-problem2/#findComment-745826 Share on other sites More sharing options...
GingerRobot Posted January 25, 2009 Share Posted January 25, 2009 When you submit a form, text inputs will always be set though they may be empty. You should use the empty function to find out if they've been left blank. And please don't make posts with the title in capitals. Quote Link to comment https://forums.phpfreaks.com/topic/142340-php-to-mysql-problem2/#findComment-745827 Share on other sites More sharing options...
DeanWhitehouse Posted January 25, 2009 Share Posted January 25, 2009 Also use trim to make sure they don't just have spaces Quote Link to comment https://forums.phpfreaks.com/topic/142340-php-to-mysql-problem2/#findComment-745828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.