WarMad Posted September 11, 2021 Share Posted September 11, 2021 (edited) i am using php 8 & PDO but i am trying to select enum from the database for friends and enemys list and im not getting an error but i can only get it to say that i am friends with them so it just says remove friends i have tried several different things to get it to select if your friends or enemys but it will not let me do it here is my code $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch_row(); if(!$row) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } else { if($row['type'] = 'friend') { $fri = 'remove friend'; $ene = ''; } else if($row['type'] = 'enemy') { $fri = ''; $ene = 'Remove enemy'; } } Edited September 11, 2021 by WarMad Changed name because realized it’s an sql problem Quote Link to comment Share on other sites More sharing options...
AdamHull Posted September 11, 2021 Share Posted September 11, 2021 If you are doing if statements for comparisons you should be using at least == operator if($row['type'] = 'enemy') That is your is statements which is setting the variables to enemy as you are only using single = 2 Quote Link to comment Share on other sites More sharing options...
WarMad Posted September 11, 2021 Author Share Posted September 11, 2021 I have also tried == when I do that it acts like $row doesn’t exist so I basically see what’s inside of the if(!$row) func Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted September 11, 2021 Share Posted September 11, 2021 i will say its not an enum error should be an sql use == no just one and !$row use the count function in pdo rowCount() Quote Link to comment Share on other sites More sharing options...
URBANZ Posted September 11, 2021 Share Posted September 11, 2021 (edited) $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch_row(); $fri = (!$row ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($row['type'] == 'enemy' ? '' : ($row['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$row ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($row['type'] == 'friend' ? '' : ($row['type'] == 'enemy' ? 'Remove Enemy' : ''))); i would use this cuts down the code alot and does the same thing. 55 minutes ago, ags_cs4 said: i will say its not an enum error should be an sql use == no just one and !$row use the count function in pdo rowCount() missed you are using MySQLi prepared statements and not PDO Edited September 11, 2021 by URBANZ Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted September 11, 2021 Share Posted September 11, 2021 42 minutes ago, URBANZ said: missed you are using MySQLi prepared statements and not PDO I believe he's using a PDO wrapper I released a few years ago 1 Quote Link to comment Share on other sites More sharing options...
URBANZ Posted September 11, 2021 Share Posted September 11, 2021 (edited) 35 minutes ago, Magictallguy said: I believe he's using a PDO wrapper I released a few years ago Solved lol ↓ Edited September 11, 2021 by URBANZ Quote Link to comment Share on other sites More sharing options...
WarMad Posted September 11, 2021 Author Share Posted September 11, 2021 8 minutes ago, Magictallguy said: I believe he's using a PDO wrapper I released a few years ago yes i am I found out that the sql is not working for some reason I double checked everything and I dont see anything wrong with it. 47 minutes ago, URBANZ said: Solved lol ↓ How is it solved? Quote Link to comment Share on other sites More sharing options...
URBANZ Posted September 11, 2021 Share Posted September 11, 2021 (edited) 1 hour ago, WarMad said: yes i am I found out that the sql is not working for some reason I double checked everything and I dont see anything wrong with it. How is it solved? i mean the wrapper part not the actual sql lol was wondering if you was using a wrapper as thats not the correct way PDO does things thats MySQLi. try this, not sure it will work, @Magictallguy will know more as he made the wrapper but im going by MySQLi prepared statments based on you using fetch_row(); MySQLi Version $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?"); $lists->bind_param('ii', $i['userid'], $u['userid']); $lists->execute(); $list = $lists->fetch_row(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); PDO Version $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person"); $lists->bindParam(':user', $i['userid'], PDO::PARAM_INT); $lists->bindParam(':person', $u['userid'], PDO::PARAM_INT); $lists->execute(); $list = $lists->fetch(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); Edited September 11, 2021 by URBANZ Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted September 11, 2021 Share Posted September 11, 2021 as i suck on sql i will move to the side and let the expers talk 😄 Quote Link to comment Share on other sites More sharing options...
WarMad Posted September 11, 2021 Author Share Posted September 11, 2021 2 hours ago, URBANZ said: i mean the wrapper part not the actual sql lol was wondering if you was using a wrapper as thats not the correct way PDO does things thats MySQLi. try this, not sure it will work, @Magictallguy will know more as he made the wrapper but im going by MySQLi prepared statments based on you using fetch_row(); MySQLi Version $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?"); $lists->bind_param('ii', $i['userid'], $u['userid']); $lists->execute(); $list = $lists->fetch_row(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?"); $lists->bind_param('ii', $i['userid'], $u['userid']); $lists->execute(); $list = $lists->fetch_row(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); PDO Version $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person"); $lists->bindParam(':user', $i['userid'], PDO::PARAM_INT); $lists->bindParam(':person', $u['userid'], PDO::PARAM_INT); $lists->execute(); $list = $lists->fetch(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); $lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person"); $lists->bindParam(':user', $i['userid'], PDO::PARAM_INT); $lists->bindParam(':person', $u['userid'], PDO::PARAM_INT); $lists->execute(); $list = $lists->fetch(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : ''))); I will give this a try I’m trying to wait and see if mtg reply’s first sense he did make the wrapper Quote Link to comment Share on other sites More sharing options...
InverTed Posted September 11, 2021 Share Posted September 11, 2021 (edited) You're using MTGs wrapper? I think the issue has just been overlooked, I use this wrapper for pretty much every PHP project i do. I'm not sure if yours is any different than mine but I see you did this here: $row = $db->fetch_row(); His wrapper is meant to handle most of this for you, just try switching that particular line to: $row = $db->fetch(); I ran into this issue once and I swear that's how it was solved. Edited September 11, 2021 by InverTed Quote Link to comment Share on other sites More sharing options...
WarMad Posted September 29, 2021 Author Share Posted September 29, 2021 Been trying several different things and still can’t get it working maybe it’s a xampp issue…. Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted September 30, 2021 Share Posted September 30, 2021 $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch(true); if(empty($row)) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } elseif($row['type'] === 'friend') { $fri = 'Remove Friend'; $ene = ''; } else if($row['type'] === 'enemy') { $fri = ''; $ene = 'Remove enemy'; } Quote Link to comment Share on other sites More sharing options...
WarMad Posted October 6, 2021 Author Share Posted October 6, 2021 On 9/30/2021 at 5:44 PM, Magictallguy said: $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch(); if(empty($row)) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } elseif($row['type'] === 'friend') { $fri = 'Remove Friend'; $ene = ''; } else if($row['type'] === 'enemy') { $fri = ''; $ene = 'Remove enemy'; } $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch(true); if(empty($row)) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } elseif($row['type'] === 'friend') { $fri = 'Remove Friend'; $ene = ''; } else if($row['type'] === 'enemy') { $fri = ''; $ene = 'Remove enemy'; } I will give that a try Quote Link to comment Share on other sites More sharing options...
WarMad Posted March 16, 2022 Author Share Posted March 16, 2022 On 9/30/2021 at 12:44 PM, Magictallguy said: $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch(true); if(empty($row)) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } elseif($row['type'] === 'friend') { $fri = 'Remove Friend'; $ene = ''; } else if($row['type'] === 'enemy') { $fri = ''; $ene = 'Remove enemy'; } $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?'); $db->execute([$i['userid'], $u['userid']]); $row = $db->fetch(true); if(empty($row)) { $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>'; $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>'; } elseif($row['type'] === 'friend') { $fri = 'Remove Friend'; $ene = ''; } else if($row['type'] === 'enemy') { $fri = ''; $ene = 'Remove enemy'; } That didn’t work I ended up just canceling the whole thing and giving it 1000 different tries to get the wrapper to work and I can’t seem to get it I can get it to not display any errors but when it’s not then it still doesn’t send the query to the database it acts as if the query is not there but with that being said it will pull from the database just not update it it…. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.