|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. ![]() |
|
#2
|
|||
|
|||
|
Post your code and I will fix it.
|
|
#3
|
|||
|
|||
|
<!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> |
|
#4
|
|||
|
|||
|
PHP Code:
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#5
|
||||
|
||||
|
Left off the mysql_query() part, Wil. You just need to run mysql_query($sql,$db) (check the parameter order) after setting $sql.
|
|
#6
|
|||
|
|||
|
Quote:
Good catch D. |
|
#7
|
|||
|
|||
|
Thanks
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Variables in mysql_query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|