PDA

View Full Version : Little MySQL help pretty please


Rune
05-14-2003, 04:58 AM
I know very little about MySQL and PHP ... but I'm trying. I'm working on something and have one last hurdle that I can't figure out. I'm assuming it's just the lack of MySQL knowledge and some guru can probably point me in the right direction without hesitation, so here goes.

Something's wrong with this code. I'm trying to grab data from a single table to see if these two values exist in any field together. I want to see if there's any occurance of X and Y in one field together, if so, give a comment and exit the rest of the code ... if not, execute the rest of the code. Where am I going wrong here?

//--------START CHECK FOR PREVIOUS BANVOTE BY THIS VOTER AGAINST THIS POSTER-------->
// check if banvote was already placed
$sql = "SELECT *
FROM " . BANVOTE_VOTERS_TABLE . "
WHERE banvote_user_id = $banvote_user_id
AND banvote_banner_id = $banvote_banner_id;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain banvote data for these users', '', __LINE__, __FILE__, $sql);
}
if ( $banvote_user_id=$poster_id && $banvote_banner_id=$user_id )
{
message_die(GENERAL_ERROR, 'You have already placed a ban vote against this user', '', __LINE__, __FILE__, $sql);
}
//--------END CHECK FOR PREVIOUS BANVOTE BY THIS VOTER AGAINST THIS POSTER-------->



P.S. The rest of the code not shown works perfectly ... this is the only part that doesn't.

nnichols
05-16-2003, 01:12 AM
It could be something to do with the use of '=' where it should probably be '==' -

if ( $banvote_user_id=$poster_id && $banvote_banner_id=$user_id )change toif ( $banvote_user_id==$poster_id && $banvote_banner_id==$user_id )If this is not the case please state what the code is doing that you don't expect it to.

Hope this helps

Rune
05-16-2003, 01:54 AM
Forgot I posted this here. :p

Thanks I ended up finally getting an answer:

//check for previous banvote against THIS poster by THIS user
$sql = "SELECT *
FROM " . BANVOTE_VOTERS_TABLE . "
WHERE banvote_user_id = $poster_id
AND banvote_banner_id = " . $userdata['user_id'];
if ( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain banvote data for these users', '', __LINE__, __FILE__, $sql);
}
if ( !$db->sql_numrows($result) > 0 )
{
(code to ban the user)
}
else
{
$message = $lang['Already_banvoted'];
$message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="javascript:history.back(1)">', '</a>');
message_die(GENERAL_MESSAGE, $message);
}


Thanks!:thumbsup:

This was the reason behind it btw:

http://www.phpbb.com/phpBB/viewtopic.php?t=101518

Jeewhizz
05-21-2003, 01:46 AM
Another PHP Post - boy does this forum need cleaning ;)

<gets out mod brush...>

Moving to PHP Forum for future reference :)

Rune
05-21-2003, 02:38 AM
nuh-uh ... it was accessing the MySQL database I was having a problem with. :D ;)

Jeewhizz
05-21-2003, 02:59 AM
I apologise... I have moved tonnes of posts today - seems to have got caught up in the moving-trolley!

Regards,

Jee

Rune
05-21-2003, 04:41 AM
heh ... no worries. :D