Current location: Hot Scripts Forums » Programming Languages » PHP » Retreive info from Database?


Retreive info from Database?

Reply
  #1 (permalink)  
Old 08-14-03, 11:24 AM
EST EST is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Retreive info from Database?

How can i get the information from the MySQL database and display it through the Text box?
Reply With Quote
  #2 (permalink)  
Old 08-15-03, 03:43 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
hi there,

you really need to learn SQL in order to build upon the code i've written below, but here is an example of how to pull text from a database and place it into a text box, and a text area.

your database needs to have three fields:

id,title,content

as an example, we will just be printing the title of an article, and the article text.

first of all, we have a basic HTML page with a link, we add a variable called 'linkID' to that link so we can pull a certain record out of the database, here is what the link should look like in your page:-

Code:
<a href="print_text.php?linkID=1">Link 1</a>
so, this link is telling our script to grab the data for record number 1, in the script below you will see that we search the database and grab the record depending on this number.

print_text.php

PHP Code:



<?php

// Define MySQL connection settings - Edit them!

$host "localhost"
$username "username"
$password "passwords"
$database "database"

//Select the relevant data from the table, based on the ID passed
//through the link

mysql_connect($host,$username,$password) or die("Unable to connect to database");

@
mysql_select_db("$database") or die("Unable to select database $database");

//Edit this to match your database table!

$sqlquery "SELECT title,content FROM your_table WHERE id='$linkID'";

//Put the data from the SQL query into a variable called $result

$result mysql_query($sqlquery) or die("Unable to perform query");

//Take the data from the SQL query and put it into seperate 
//variables

$rows mysql_fetch_array($result);
$title $rows['title'];
$content $rows['content'];        

//Form to print the title and content. The variables used here are 
//the ones that we specified above, based on the data we pulled 
//from the database.    

print "<form>
<br>Edit Selected Record<br>
<br>
<input type=\"text\" size=\"50\" value=\"
$title\"><br>
<br>
<textarea cols=\"40\" rows=\"8\">
$content</textarea><br>
<br>
</form>"
;

?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Share database over the Internet nitinkedia The Lounge 2 11-20-03 02:07 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
tracking down a database problem ... bjmcintosh ASP 1 08-29-03 07:52 AM
Share database over the internet nitinkedia PHP 0 07-11-03 12:22 AM
Share database over the Internet nitinkedia New Members & Introductions 1 07-10-03 02:50 PM


All times are GMT -5. The time now is 05:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.