php post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ZetCoby
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:07 pm

php post

Post 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?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php post

Post 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
ZetCoby
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:07 pm

Re: php post

Post 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
ZetCoby
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:07 pm

Re: php post

Post by ZetCoby »

what do you mean by quotes instead of double ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php post

Post 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).
ZetCoby
Forum Newbie
Posts: 10
Joined: Wed Sep 28, 2011 1:07 pm

Re: php post

Post 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
Post Reply