Page 1 of 1

php post

Posted: Wed Sep 28, 2011 1:13 pm
by ZetCoby
hello, i have a small problem with this code

Code: Select all

<html>

<hr>
<?php
if (isset($_POST['post']))
	{
		$title = $_POST['title'];
		$body = $_POST['body'];
		if($title&&$body)
			{
				$connect= mysql_connect ("localhost","root","951623") or die ("error");
				mysql_select_db ("phplogin")  or die("table not found"); 
				$date = date("Y-m-d");
				$insert = mysql_query(" INSERT INTO news VALUES ('','$title','$body','$date')");
			}
		else
			{
				echo " Va rog umpleti toate casutele";
			}
	}
?>
<form action='post.php'method='POST'>
Titlul:<br>
<input type="text" name='title'><p>

Tutorial:<br>
<textarea rows='6' cols='70' name='body'></textarea><p>

<input type="submit" name="post" value="Post">
</form>
<hr>
</html>

The problem is that the post action will not even appear on the site, i log on my site and no thing happens, no post action there, can someone tell me is there something wrong with my code?

Re: php post

Posted: Wed Sep 28, 2011 2:22 pm
by twinedev
What do you mean by "The post action will not even appear"?

What is wrong with this has many levels, here is what I would change...

1. The page isn't valid HTML format (ie, no <body> tag
2. You have attributes wrapped with single quotes instead of double
3. You do no have a space between action="post" and method="post"
4. You have no protection against SQL injection

So anyhow, the more details you can give of what you are expecting (or prefer) vs. what you are actually getting, the more we can help.

-Greg

Re: php post

Posted: Wed Sep 28, 2011 2:32 pm
by ZetCoby
i mean it wont show nothing, not eaven the submit button, not eaven the body textarea, nothing, it is like that form action does not exist
i did the body, and corrected the st space between action am method , still does not work

Re: php post

Posted: Wed Sep 28, 2011 2:35 pm
by ZetCoby
what do you mean by quotes instead of double ?

Re: php post

Posted: Wed Sep 28, 2011 2:35 pm
by Celauran
ZetCoby wrote:what do you mean by quotes instead of double ?
' instead of "

I copy/pasted the code from your OP and it displays fine in my browser. The form seems to work, also (died on sql authentication, for obvious reasons).

Re: php post

Posted: Wed Sep 28, 2011 2:39 pm
by ZetCoby
i found the problem, when i included the file post.php it was Post.php i see that linux is case sensitive, did not have this problem on windows, but still te me what u mean about quotes instead of double ?, i am new to php :D