Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/142340-php-to-mysql-problem2/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.