overlordofevil Posted April 8, 2008 Share Posted April 8, 2008 Hey all, I am trying to set up a script that will look for a enum variable in my db and if it finds it sets the variable to the next one. problem I am running into is it stops at the first option. function getwchar($uid) { $query = "SELECT * FROM characters where id='$uid'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); if ($row[wchar] = 'quinary') { header("Location: charerror.php"); } elseif ($row[wchar] = 'quaternary') { $wchar = 'quinary'; } elseif ($row[wchar] = 'tertiary') { $wchar = 'quaternary'; } elseif ($row[wchar] = 'secondary') { $wchar = 'tertiary'; } elseif ($row[wchar] = 'primary') { $wchar = 'secondary'; } else { $wchar = 'primary'; } } return $wchar; } I have moved the options around and it always stops at the first one. If someone could point me in the right direction I would appreciate it. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/ Share on other sites More sharing options...
duclet Posted April 8, 2008 Share Posted April 8, 2008 It is stopping at the first one because $row[wchar] is probably equaled to 'quinary'. The function header with the Location string will pretty much stop the execution of the script and redirect you to a different page. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-512271 Share on other sites More sharing options...
overlordofevil Posted April 8, 2008 Author Share Posted April 8, 2008 actually the files I am testing it on I know the wchar variable is only a primary and a secondary. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-512327 Share on other sites More sharing options...
duclet Posted April 9, 2008 Share Posted April 9, 2008 I can't see what is wrong with the code though I did clean it up a little: function getwchar($uid) { $query = "SELECT * FROM characters where id='$uid'"; $result = mysql_query($query) or die (mysql_error()); $wchar = NULL; while($row = mysql_fetch_assoc($result)) { if($row['wchar'] = 'quinary') { header("Location: charerror.php"); } elseif($row['wchar'] = 'quaternary') { $wchar = 'quinary'; } elseif($row['wchar'] = 'tertiary') { $wchar = 'quaternary'; } elseif($row['wchar'] = 'secondary') { $wchar = 'tertiary'; } elseif($row['wchar'] = 'primary') { $wchar = 'secondary'; } else { $wchar = 'primary'; } } return $wchar; } The only thing I can think of is that your query is only returning one row of data. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-513176 Share on other sites More sharing options...
GingerRobot Posted April 9, 2008 Share Posted April 9, 2008 You need to be using a double == sign. The single equals sign is the asignment operator, which will evaluate to true. You want the the double equals sign to compare two things. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-513180 Share on other sites More sharing options...
duclet Posted April 9, 2008 Share Posted April 9, 2008 Exactly right. I can't believe I missed that too. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-513199 Share on other sites More sharing options...
overlordofevil Posted April 15, 2008 Author Share Posted April 15, 2008 thanks so much I tried the double = and it works majority of the time so some more tinkering and I should have it. Link to comment https://forums.phpfreaks.com/topic/100191-solved-enum-verification/#findComment-517777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.