SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 30th, 2003, 02:23 PM
moose1226 moose1226 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 3 moose1226 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Variables in mysql_query

I have a mySQL table with fields called 'title', 'body', and 'ID'(auto incrementing).

Title ($title) and Body ($body) are input by the user on another page and the data is submitted to the page in question. Both $title and $body are strings.

what do I need to put in the mysql_query() function in order to make mySQL insert a row with the value of the variable $title in the field 'title' and the value of the variable $body in the field 'body'.

All my attempts so far have either done nothing, resulted in parse errors, or created a row with the variable names in the database, and not the actual values.




Reply With Quote
  #2  
Old December 30th, 2003, 09:20 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Post your code and I will fix it.

Reply With Quote
  #3  
Old December 30th, 2003, 09:49 PM
moose1226 moose1226 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 3 moose1226 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Thank You For Your Submission
<?php
//$sqluser and $sqlpass are in the code and are correct, I just
//chose not to include it in the forums.
$database = 'groeneman_com_-_news'; //your database name

$db = mysql_connect("localhost","$sqluser","$sqlpass");
@mysql_select_db($database,$db) or die(mysql_errno() . ": " . mysql_error(). "");
$sql = 'INSERT INTO `test` ( `title` , `BODY` , `ID` ) '
. 'VALUES ( \'$title\', \'$body\', \'\' );'
. '';

?>
</body>
</html>

Reply With Quote
  #4  
Old December 31st, 2003, 12:11 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
PHP Code:
<?php
//$sqluser and $sqlpass are in the code and are correct, I just
//chose not to include it in the forums.
$database 'groeneman_com_-_news'//your database name

$db mysql_connect("localhost","$sqluser","$sqlpass");
@
mysql_select_db($database,$db) or die(mysql_errno() . ": " mysql_error(). "");
$sql 'INSERT INTO `test` ( `title` , `BODY` ) ' "VALUES ( '$title', '$body' )";
mysql_query($sql,$db) or die(mysql_errno() . ": " mysql_error(). ""); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Thank You For Your Submission
</body>
</html>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #5  
Old December 31st, 2003, 06:41 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Left off the mysql_query() part, Wil. You just need to run mysql_query($sql,$db) (check the parameter order) after setting $sql.

Reply With Quote
  #6  
Old December 31st, 2003, 12:08 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Talking

Quote:
Left off the mysql_query() part,
LOL... I would, wouldn't I... Good catch D.

Reply With Quote
  #7  
Old January 4th, 2004, 12:06 PM
moose1226 moose1226 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 3 moose1226 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Variables in mysql_query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway