zetcoby Posted September 28, 2011 Share Posted September 28, 2011 hello, i have a small problem with this code <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? Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/ Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 so when you click on the submit button nothing happens? can you explain the situation a little more thorough. Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273637 Share on other sites More sharing options...
zetcoby Posted September 28, 2011 Author Share Posted September 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273642 Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 where are your <head></head> and <body></body> tags? Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273645 Share on other sites More sharing options...
zetcoby Posted September 28, 2011 Author Share Posted September 28, 2011 i put them but that is not the problem, still nothing is showed Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273647 Share on other sites More sharing options...
TOA Posted September 28, 2011 Share Posted September 28, 2011 Does anything get entered into the db? Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273739 Share on other sites More sharing options...
AyKay47 Posted September 29, 2011 Share Posted September 29, 2011 well obviously something is happening.. do you have error reporting on and display errors on? Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1273966 Share on other sites More sharing options...
Jacbey Posted September 29, 2011 Share Posted September 29, 2011 Ok, first thing I noticed when I saw it is; if($title&&$body) You have two variables but you're not comparing them to anything. It's like saying if apple and apple return this. But if apple and apple are what? You haven't specified the what. I'm thinking that it is making the php stop and die there. When php performs die() it stops anything else on the page from appearing. Since you haven't written anything else to the page before that you won't see if it's echoing anything. Now, if that isn't the problem, this might be. mysql_select_db ("phplogin") or die("table not found"); Databases are case sensitive and therefore if you have got any letter in the wrong case it wouldn't work. But saying that, if it didn't work it should say "table not found" as you have specified. I'll give you two tips here. First, put something just under the html tag and before the php tag and see if it shows that. Secondly, I use this method of connecting to a database. I find it easier and it looks better in my mind. <?php $myServer = "server"; $myUser = "username"; $myPass = "password"; $myDB = "database"; //connection to the database $dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mysql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); ?> Try correcting the things I have mentioned and see if that works. =] Jacob. Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1274039 Share on other sites More sharing options...
TOA Posted September 29, 2011 Share Posted September 29, 2011 @Jacbey: it depends on how he's using it. He could be checking for a "true" boolean value, or to see if it exists. I suspect he's not though so @OP, maybe you can clarify? Take this example: if ($title) { echo "Set or true"; } else { echo "Not set or not true"; } outputs "Not set or not true" Yet this: $title = "anything"; if ($title) { echo "Set or true"; } else { echo "Not set or not true"; } will output "set or true" Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1274050 Share on other sites More sharing options...
Jacbey Posted September 29, 2011 Share Posted September 29, 2011 @DevilsAdvocate; Aah, didn't think of that. Thanks for pointing that out bro. Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1274053 Share on other sites More sharing options...
TOA Posted September 29, 2011 Share Posted September 29, 2011 @DevilsAdvocate; Aah, didn't think of that. Thanks for pointing that out bro. That's what I saw at first too. @OP-does anything get entered into the database? Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1274054 Share on other sites More sharing options...
AyKay47 Posted September 29, 2011 Share Posted September 29, 2011 i think that once the OP responds to my last question we can proceed.. if he is receiving a blank page, there is a good probability that an error is being triggered here.. Quote Link to comment https://forums.phpfreaks.com/topic/248049-php-post/#findComment-1274056 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.