parabolate Posted November 1, 2011 Share Posted November 1, 2011 I manage a simple website for a small business - nothin fancy. I'm interested using some php to enhance the site a bit. I'm looking to accept some user input and put it into a database then display it back to them on another page. What php functions would be best to use to accomplish this? Thanks for the input! Link to comment https://forums.phpfreaks.com/topic/250217-accepting-user-input-question/ Share on other sites More sharing options...
seany123 Posted November 1, 2011 Share Posted November 1, 2011 The code ive posted shows example of how to connect to db, have a post form, insert form value into database, retrieve database rows and echo them. PLEASE NOTE- i have done NO security its completely raw and vulnerable but it shows you an example which you can work on. <?php //===== This code connects to database ======= $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'TEST'; //this is the name of the database mysql_select_db($dbname); //============================================ //============================================ //This code handles the form and inserting into the text into the database if(isset($_POST['submit'])){ $text = $_POST['text']; //Adding security checks here is essential! //Inserts Data into Database mysql_query("INSERT INTO users_input set text='$text'"); } //============================================= ?> <html> <form method="POST"> <input type="text" name="text"/> <input type="submit" name="submit" value="Submit"/> </form> <?php //========================================== // This code selects all rows from db and echos them out $query = mysql_query("SELECT * FROM users_input ORDER BY text"); while ($response=mysql_fetch_array($query)){ echo $response['text']."<br/>"; } //========================================== ?> </html> Link to comment https://forums.phpfreaks.com/topic/250217-accepting-user-input-question/#findComment-1283896 Share on other sites More sharing options...
jotorres1 Posted November 1, 2011 Share Posted November 1, 2011 Take a look at this post I have wrote a few weeks ago. It talks about how to grab user input, and display it back to the user. http://www.jotorres.com/2011/10/learn-basics-for-php-part-2/ Link to comment https://forums.phpfreaks.com/topic/250217-accepting-user-input-question/#findComment-1283981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.