General mailing list question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

General mailing list question

Post by influx »

I am incorporating a mailing list feature for my blog users and I was wondering what I need to fix in the database query.

I have a page where my users can input up to 10 email addresses with 10 accompanying names. Everything in this code works fine except for the last two values I want inputted (SESSIONemail and SESSIONname).

There has to be something wrong because it is always inputting NULL instead of the name or the email.

Here is the code:

Code: Select all

for($k=1;$k<=10;$k++)
{
  if($_SESSION['email_'.$k])
  {
    $query = "INSERT INTO mail_list (m_id, m_username, m_email, m_name) VALUES ('$user_id','{$_SESSION['username']}', '{$_SESSION['email_{$k}']}', '{$_SESSION['name_{$k}']}')";
    mysql_query($query) or die(mysql_error());
  }
}
Thanks!
Last edited by influx on Mon Aug 29, 2005 11:17 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try a

Code: Select all

echo $query;
to see what's being inputted :wink:
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

Post by influx »

here is what it outputted:

INSERT INTO mail_list (m_id, m_username, m_email, m_name) VALUES ('862','johndoe', '', '')
INSERT INTO mail_list (m_id, m_username, m_email, m_name) VALUES ('862','johndoe', '', '')

Meaning, even though I inputted the last two things that should be inputted (SESSIONemail and SESSIONname), they still aren't being recognized...there is a problem with {$_SESSION['email_{$k}']} and {$_SESSION['name_{$k}']}...I just don't know how to fix it!

I'm sure I'm close but I've tried everything
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd suggest storing those variables in temporary ones so you can simply reference those instead of dealing with this stuff.
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

Post by influx »

Interesting...I'm just thinking of it as the most effecient way for the server I'm running.

You really think it's better to store it in temp variables? Why?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

for one, it's a bit easier for the compiler to translate, likely.. it's easier to read and understand quickly what's going on.
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

Post by influx »

Throughout building my site, I've been pretty careful to keep my code as short as possible. Is it really important to do this from my standpoint, you think?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

code being short as possible doesn't necessarily make the code run faster. There are many examples around where one code is far shorter than another doing the exact same thing, but the longer one's approach is far faster.

A recent illustration: viewtopic.php?t=36790
Post Reply