Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-15-2009, 06:02 PM INSERT problem
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
OK, I'm 100% new to php. I won't even lie. I'm creating a very basic, insecure guestbook. Having troubles though.
http://codingasylum.freehostia.com/g.../guestbook.htm

Code:
<?php
if(isset($_POST['process']) && $_POST['process']==1)
{
$con = mysql_connect("XXXXX","XXXXXXXX","XXXXXXX");
if(!$con)
{
    die("Connection Failed" . mysql_error());
}

mysql_select_db("guestbook", $con);

$query ="INSERT INTO guestbook
(email, message, ip, date)
VALUE  //THIS IS WHERE MY PROBLEM IS!!!!
('$_POST[email]','$_POST[message]','$_SERVER['REMOTE_ADDR'], NOW())";

if(mysql_query($query))
{
    echo "Success!";
}
else
{
    echo "Failed";
}

}
else
{
    echo "Denied Access!";
}
mysql_close($con);
?>
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein

Last edited by NewBreed; 04-15-2009 at 06:05 PM..
NewBreed is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-15-2009, 06:32 PM Re: INSERT problem
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
http://dev.mysql.com/doc/refman/5.1/en/insert.html

PHP Code:
$email $_POST['email']; //validate this
$msg $_POST['message']; //validate this too
$addr $_SERVER['REMOTE_ADDR'];

$query "INSERT INTO guestbook (email, message, ip, date)
                    VALUES( '
$email' , '$msg' , '$addr' , NOW());"
You were using VALUE not VALUES, also $_SERVER['REMOTE_ADDR'] won't be parsed in quotes ($_SERVER[REMOTE_ADDR] will).
Personally I try to stay away from parsing complex variables (ie arrays) in quotes.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-15-2009 at 06:35 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-15-2009, 06:52 PM Re: INSERT problem
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Personally I try to stay away from parsing complex variables (ie arrays) in quotes.
Or embed them between { and }
PHP Code:
$query ="INSERT INTO guestbook
(email, message, ip, date)
values
('
{$_POST['email']}','{$_POST['message']}','{$_SERVER['REMOTE_ADDR']}', NOW())"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-15-2009, 06:57 PM Re: INSERT problem
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
Code:
$query ="INSERT INTO guestbook
(email, message, ip, date)
VALUES
('".$_POST[email]."', '".$_POST[message]."', '".$_SERVER['REMOTE_ADDR']."', NOW() )";
syntax fixed... still won't work... Maybe because of the remote addr and the now()?
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein
NewBreed is offline
Reply With Quote
View Public Profile
 
Old 04-15-2009, 07:26 PM Re: INSERT problem
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What is the error, and what is your table structure?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-15-2009, 07:43 PM Re: INSERT problem
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
For some reason it didn't like it when i did.
mysql_select_db(db,$con);
So i did it without the $con and bam! thanks all for the help.
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein
NewBreed is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to INSERT problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24564 seconds with 12 queries