Jump to content

[SOLVED] Problem defining variables from GET param


DjMikeWatt

Recommended Posts

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.

 

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 ;
}
?>

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 */
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.