DjMikeWatt Posted July 20, 2009 Share Posted July 20, 2009 Ok, so I'm pretty new at this, but I'm really frustrated with myself right now because I can't figure out what is going on here. I've got the code below up near the very top inside the <body> tag. <?php { $success = ('<p class="style2">The user account was successfully created.</p>') ; $duplicate = ('<p class="style2">The username supplied already exists within the system.</p>') ; } { if ($_GET['msg']=('duplicate')) $msg = $duplicate ; elseif ($_GET['msg']=('success')) $msg = $success ; } ?> Then, farther down the page, it calls for the $msg variable... <?php echo $msg ; ?> The page always returns the text from $duplicate no matter what the $_GET['msg'] is set as in the URL. It even shows that when there is NO "?msg=" in the URL. I tried adding a if(isset($_GET['msg'] line, and that stopped it from showing when there was no "?msg=" in the URL, but it also forced the same response no matter what (which I understand, because it's just looking to see if it's set then setting the variable.) Anyway, I'm rambling - can anyone tell me what I'm doing wrong? The page is located at http://www.radioimaging101.com/new_user.php Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/ Share on other sites More sharing options...
Coreye Posted July 20, 2009 Share Posted July 20, 2009 Hey Mike, What happens if you try this code: <?php $success = '<p class="style2">The user account was successfully created.</p>'; $duplicate = '<p class="style2">The username supplied already exists within the system.</p>'; if($_GET['msg'] == 'duplicate') { $msg = $duplicate; } elseif($_GET['msg'] == 'success') { $msg = $success ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/#findComment-878425 Share on other sites More sharing options...
DjMikeWatt Posted July 20, 2009 Author Share Posted July 20, 2009 That worked perfectly... so besides cleaning it up a little, the main thing you did was "==" instead of "=". Is that determining factor here? How do I know when to use "==" and when to use "="? Thank you, by the way. Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/#findComment-878440 Share on other sites More sharing options...
trq Posted July 20, 2009 Share Posted July 20, 2009 = is an assignment operator, use it when you want to assign the value on the right to the variable on the left. == is an comparison operator, used to compare to things. Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/#findComment-878450 Share on other sites More sharing options...
KevinM1 Posted July 20, 2009 Share Posted July 20, 2009 Also, you should double-check the position of your brackets. Brackets denote the beginning and end of a block structure. These structures include function definitions, loops, and conditional statements. Writing something like: { if(/* some conditional statement */) /* action */ else /* another action */ } Is wrong. Instead, it's: if(/* some conditional statement */) { /* action */ } else { /* another action */ } The same thing goes for loops and function definitions: while(/* some condition is true */) { /* stuff to do */ } function myFunction($arg) { /* do something with $arg */ } Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/#findComment-878547 Share on other sites More sharing options...
DjMikeWatt Posted July 21, 2009 Author Share Posted July 21, 2009 COREYE, THORPE, and NIGHTSLYR, Thank you... all very useful and constructive info... This is by far one of the best PHP boards to ask questions in... thank you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/166587-solved-problem-defining-variables-from-get-param/#findComment-879281 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.