Current location: Hot Scripts Forums » Other Discussions » Database » Noobie Mistake I assume


Noobie Mistake I assume

Reply
  #1 (permalink)  
Old 03-02-07, 06:07 AM
Ryouko Ryouko is offline
New Member
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Noobie Mistake I assume

I have a mysql database named joostinvites and in it I have a table named users. This table has the fields email addresses, firstname, last name and an integer set to 0 or 1 to " check off" if they have been invited.
I am trying to do this all from scratch and I made up a simple way to do it using PHP and mysql querys.

Here is my code that doesn't work:
PHP Code:

<?php
$link 
mysql_connect ("mysql.joostswap.net""ryouko""MYPASS");
$sql_query "insert into users (email, firstname, lastname, invited) values ($_POST[email]$_POST[firstname]$_POST[lastname], 0)";
mysql_query($sql_query);
mysql_close($link);
echo 
"User added correctly. Please wait patiently for your response!";
?>
it doesn't seem to get a parse error, it just doesn't add the information to the table. But it does when I run :
insert into users (email, firstname, lastname, invited) values ("my@email.com", "Joey", "poops", 0);
as an SQL query, someone please help me out here

Last edited by Nico; 03-02-07 at 06:22 AM. Reason: Please use [php] wrappers when posting PHP code.
Reply With Quote
  #2 (permalink)  
Old 03-02-07, 06:18 AM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$sql_query "insert into users (email, firstname, lastname, invited) values ($_POST[email]$_POST[firstname]$_POST[lastname], 0)"
should be

PHP Code:

$sql_query "insert into users (email, firstname, lastname, invited) values (".$_POST['email'].", ".$_POST['firstname'].", ".$_POST['lastname'].", 0)"
Thats just to get it working.... you really need to screen you user input before putting it directly into a query string.
__________________
"BTW, I can't program at all the only thing I figured out is how to upload templates to my server."
Reply With Quote
  #3 (permalink)  
Old 03-02-07, 06:21 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You have to put single quotes around strings.

PHP Code:


$sql_query 
"
    insert into users
       (email, firstname, lastname, invited)
    values
       (
          '"
mysql_real_escape_string($_POST['email']) ."',
          '"
mysql_real_escape_string($_POST['firstname']) ."',
          '"
mysql_real_escape_string($_POST['lastname']) ."',
          0
       )"

You can also add OR die( mysql_error() ); behind mysql_query() to get the exact error.

PHP Code:

mysql_query($sql_query) OR die( mysql_error() ); 

EDIT:

And I'm moving this topic to database...

Last edited by Nico; 03-02-07 at 06:24 AM.
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
Mistake in JS syntax with FireFox ferenczi JavaScript 9 10-22-06 01:00 PM
Little Mistake Can Cost You Thousands.Cash For Structured Settlement settlement General Advertisements 1 11-17-05 06:35 PM
Big mistake eddyvlad The Lounge 2 03-08-05 07:26 PM


All times are GMT -5. The time now is 04:57 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.