TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-01-2007, 09:37 PM   #1 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default Query Confusion

Hey,

I'm pretty sure this can be classed more as a MySQL problem than a PHP one.

Check out this bit of code:

PHP Code:
<?php
// If submit was pressed, send PM
if(isset($_POST['submit_send_pm'])) {
    
// Put in variables
    
extract($_POST);
        
    
// Get the recipitent's ID
    
$recepID mysql_query("SELECT id, pm_notify FROM members, settings
    WHERE username = '"
.$to."'
         AND pm_notify = '0'||'1'
    "
);
    
// Grab ID
    
$recepRow mysql_fetch_object($recepID);
        
    
// Insert new info into database
    
$query mysql_query(sprintf("INSERT INTO private_msg SET
     subject = '%s',
      message = '%s',
      date = UNIX_TIMESTAMP(),
      sent_from = '%d',
      sent_to = '%d'"
,
        
// Values
        
escape($subject),
        
$message,
        
escape($_COOKIE['userID']),
        
escape($recepRow->id)
    )) or die(
mysql_error());
        
    
// Check if users wants to be notified, if so, send them an e-mail
    
if($recepRow->pm_notify == 1) {
        echo(
'Mail Sent');
    }
}
?>
Once the query has does it's work, I want to check if the user who it was sent to, has their 'pm_notify' selection set to 'yes' (or in the database, '1') If the option is set to '1', it will send an e-mail, though I just echo'd some text for testing purposes.

I can't seem to grab the 'pm_notify' row from the user to check if it is set to 0 or 1, can anyone think what might be the problem with my query?

Thanks.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 10-01-2007, 11:36 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

At line 10, change:
PHP Code:
AND pm_notify '0'||'1' 
To:
PHP Code:
AND pm_notify OR pm_notify 
Presumably the pm_notify column is BOOLEAN meaning that it can only have a value of 0 or 1, in which case there's no point checking if it is set to either 0 or 1. Because of that I don't see why you need to check the pm_notify value in the WHERE clause at all.
Salathe is offline  
Reply With Quote
Old 10-07-2007, 12:56 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Nor do I. Seems absurd because omitting the WHERE clause will return exactly the same as having the WHERE clause.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design