Nuzzy Posted June 8, 2014 Share Posted June 8, 2014 I ve been having trouble processing form data to the same page as the do on facebook comments. Can php scripts do that. Help me guys!! Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/ Share on other sites More sharing options...
Barand Posted June 8, 2014 Share Posted June 8, 2014 If the page your form's action attribute is blank, or the action is omitted, then it will post to itself by default Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482186 Share on other sites More sharing options...
Nuzzy Posted June 8, 2014 Author Share Posted June 8, 2014 Would you mind sending me an example snippet. I d totally appreciate that. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482199 Share on other sites More sharing options...
Barand Posted June 8, 2014 Share Posted June 8, 2014 <?php if (isset($_POST['name']) && !empty($_POST['name'])) { $message = "Your name is " . $_POST['name']; } else { $message = "Please enter a name and click \"Submit\" "; } ?> <html> <head> <title>Example</title> </head> <body> <?php echo $message; ?> <hr/> <form method="post" action=""> Name <input type='text' name='name' placeholder="Enter your name"> <br/> <br/> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482200 Share on other sites More sharing options...
Nuzzy Posted June 8, 2014 Author Share Posted June 8, 2014 Thanks worked really well for me best straight forward but when it only allows one line of comment how do I make the comment stay part of the page. Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482207 Share on other sites More sharing options...
Barand Posted June 8, 2014 Share Posted June 8, 2014 I haven't a clue what you are talking about. Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482211 Share on other sites More sharing options...
Nuzzy Posted June 8, 2014 Author Share Posted June 8, 2014 (edited) Like these posts here do they get loaded into a database so that everytime a user opens a page like this one, they see them. Edited June 8, 2014 by Nuzzy Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482219 Share on other sites More sharing options...
Barand Posted June 8, 2014 Share Posted June 8, 2014 Yes. For the following example to work you would need a database schema called "test" containing a table "person" CREATE TABLE `person` ( `id` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 then a simple example would be <?php // connect to database server $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); // use your credentials error_reporting(-1); $message = ''; if (isset($_POST['name']) && !empty($_POST['name'])) { // sanitize the input $name = $db->real_escape_string($_POST['name']); // insert into the database $sql = "INSERT INTO person (name) VALUES ('$name')"; $db->query($sql); } // list current names from database $sql = "SELECT name FROM person"; $res = $db->query($sql); // are there currently any names? if ($res->num_rows > 0) { $message = '<h3>Current Names</h3>'; while ($row = $res->fetch_assoc()) { $message .= $row['name'] . '<br>'; } } $message .= "<br>Please enter another name and click \"Submit\" "; ?> <html> <head> <title>Example 2</title> </head> <body> <?php echo $message; ?> <hr/> <form method="post" action=""> Name <input type='text' name='name' placeholder="Enter your name"> <br/> <br/> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482221 Share on other sites More sharing options...
Nuzzy Posted June 8, 2014 Author Share Posted June 8, 2014 I dont know what to say Guru Barand you the best!! You re just too good that I cant stop myself from asking you the next question i have! Keep well!! Quote Link to comment https://forums.phpfreaks.com/topic/289058-how-can-i-enable-posting-form-data-on-to-the-same-page/#findComment-1482226 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.