[advanced search]
Results from the most recent live auction are here.
20 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 04-15-2006, 12:00 PM   · #1
snike
NamePros Regular
 
snike's Avatar
 
Location: USA
Trader Rating: (15)
Join Date: Mar 2006
Posts: 472
NP$: 7.68 (Donate)
snike has a spectacular aura aboutsnike has a spectacular aura about
Save a Life
PHP post to MySQL

How do I make PHP echo the data in a MySQL database? How does PHP post into MySQL?


Please register or log-in into NamePros to hide ads
__________________
Online Multimedia Awards - Nominate your own webhost and win glory!
Emerald Feathers - Indie Films, Graphics, Funny Videos, and More! Version 4 is out!
Snike loves HostingRegion! No seriously. They are the best.
Cheap, Quality, Paid Posting Service - Starts at $3.30
snike is offline   Reply With Quote
Old 04-15-2006, 12:25 PM   · #2
Constantin
DNOA Member
 
Constantin's Avatar
 
Trader Rating: (63)
Join Date: Jan 2006
Posts: 1,069
NP$: 181.75 (Donate)
Constantin is a splendid one to beholdConstantin is a splendid one to beholdConstantin is a splendid one to beholdConstantin is a splendid one to beholdConstantin is a splendid one to beholdConstantin is a splendid one to beholdConstantin is a splendid one to behold
You have to use more functions from here http://www.php.net/mysql

mysql_connect - to connect to MySQL server
mysql_select_db - to select required database
mysql_query - to runa query on MySQL server.
Constantin is offline  
  Reply With Quote
Old 04-15-2006, 12:49 PM   · #3
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
An example.

Database:
messages

Table:
messages
Code:
CREATE TABLE `messages` ( `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `message` LONGTEXT NOT NULL, PRIMARY KEY (`id`) ) Type = MyISAM;


Example form + inserting data:
PHP Code:
<html>
<
head>
<
title>Example</title>
</
head>

<
body>

<
form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Your Name:<br />
<
input type="text" name="name"><br /><br />
Your E-mail:<br />
<
input type="text" name="email"><br /><br />
Your Message:<br />
<
textarea rows="5" cols="40" name="message"></textarea><br /><br />
<
input type="submit" name="submit" value="Submit">
</
form>

<?
php

//Connect to mysql
$db = mysql_connect('localhost', 'dbusername', 'dbpassword') or die("Couldn't connect:<br />".mysql_error());
mysql_select_db('messages', $db) or die("Couldn't select database:<br />".mysql_error());

if(isset(
$_POST['submit']))
{
  
$name = trim(strip_tags(mysql_real_escape_string($_POST['name'])));
  
$email = trim(strip_tags(mysql_real_escape_string($_POST['email'])));
  
$messages = trim(strip_tags(mysql_real_escape_string($_POST['message'])));
  
  if(!empty(
$name) && !empty($email) && !empty($message))
  {
    
$sql = mysql_query("INSERT INTO messages (id, name, email, message) VALUES('', '$name', '$email', '$message')");
    
    if(
$sql)
    {
      
//Entered successfully
    
}
    else
    {
      die(
mysql_error());
    }
  }
}

?>
</body>
</html>


Displaying the data:
PHP Code:
<?php

//Connect
$db = mysql_connect('localhost', 'dbusername', 'dbpassword') or die("Couldn't connect:<br />".mysql_error());
mysql_select_db('messages', $db) or die("Couldn't select database:<br />".mysql_error());

$sql = mysql_query("SELECT * FROM messages") or die(mysql_error());

while(
$row = mysql_fetch_array($sql))
{
  echo
'Name: '.stripslashes($row['name']).'<br /><br />
  E-mail: '
.stripslashes($row['email']).'<br /><br />
  Message: <br />'
.stripslashes(nl2br($row['message'])).'<hr>';
}

?>
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!
SecondVersion is offline   Reply With Quote
Old 04-15-2006, 01:14 PM   · #4
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
Sv, you always beat me to it, although im not on np 24/7
Xyzer is offline   Reply With Quote
Old 04-15-2006, 04:23 PM   · #5
BillyConnite
 
BillyConnite's Avatar
 
Name: Rhett
Location: Coffs H, Australia
Trader Rating: (77)
Join Date: Jul 2005
Posts: 3,106
NP$: 47.00 (Donate)
BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future
Wildlife Parkinson's Disease Parkinson's Disease
Originally Posted by webmonkey
Sv, you always beat me to it, although im not on np 24/7


I'm pretty sure SV is some sort of AI robot, first of its kind .
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline   Reply With Quote
Old 04-16-2006, 04:35 PM   · #6
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!
SecondVersion is offline   Reply With Quote
Old 04-16-2006, 06:00 PM   · #7
BillyConnite
 
BillyConnite's Avatar
 
Name: Rhett
Location: Coffs H, Australia
Trader Rating: (77)
Join Date: Jul 2005
Posts: 3,106
NP$: 47.00 (Donate)
BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future
Wildlife Parkinson's Disease Parkinson's Disease
Originally Posted by SecondVersion



lol, I knew it, it's speechless, its been found out
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Buy Flash Arcade Game Script Website Header Design Hunting Moon
Advertise your business at NamePros
All times are GMT -7. The time now is 09:10 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0