Jump to content

PHP TO MYSQL PROBLEM(2)


DEVILofDARKNESS

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.