This topic is locked

Help.... Whats wrong with my code

7/28/2006 6:29:02 AM
PHPRunner General questions
P
pdherring author

Hi i am really new to this PHP stuff and am trying my best but having problems,
this is my code i am having problems with
$strSQLExists = "select * from dbo.WEBUsers where Username='$_SESSION[UserID]' and CustomerID='125'";
can anyone see what is wrong here, what i am trying to do is check that it the username field in WEBUsers table and the CustomerID=125
hope this makes sense
PLEASE HELP ME
Thanks in advance

Alexey admin 7/28/2006

Hi,
here is the correct line of code:

$strSQLExists = "select * from dbo.WEBUsers where Username='".$_SESSION[UserID]."' and CustomerID='125'";

P
pdherring author 7/28/2006

thanks for that unfortunatly it still doesnt work

the whole code i have is
function AfterSuccessfulRegistration()

{

//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from dbo.WEBUsers where Username='".$_SESSION[UserID]."' and CustomerID='125'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

//** Redirect to another page ****

header("Location: http://www.google.co.uk");;)

exit();
}

else

{

// if dont exist do something else

}
}
Thanks again for your quick response

Alexey admin 7/28/2006

I'm sorry, here is the correct line:

$strSQLExists = "select * from dbo.WEBUsers where Username='".$_SESSION["UserID"]."' and CustomerID='125'";


If it still doesn't work please post the full error message here

P
pdherring author 7/28/2006

dosnt work im afraid just takes me straight to the main page rather than redirecting me to the http://www.google.co.uk that i am using for testing,
i have even taken out the and customerID='125' part to see if that makes a difference but it doesnt if i hard code the username it works fine but obvoisly that isnt going to help becuase i want it to redirect depending on the current logged on username.
thansk again for your help
Pete

Alexey admin 7/31/2006

Pete,
just found one thing.

You use $_SESSION["UserID"] in After Register event. However this variable is filled after logging in only.

To access the username entered by the user dusring registration use $strUsername variable.

So here is your code modified:

function AfterSuccessfulRegistration()

{

//** Check if specific record exists ****

global $conn;

global $strUsername;

$strSQLExists = "select * from dbo.WEBUsers where Username='".[b]$strUsername[/b]."' and CustomerID='125'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

//** Redirect to another page ****

header("Location: http://www.google.co.uk");;)

exit();
}

else

{

// if dont exist do something else

}
}

P
pdherring author 7/31/2006

thats great guys and girls thanks for you help.

ended up me being stupid i had put the code in the wrong place.