i am having problems with this code when i try to insert $_SESSION[‘user_ref’] into my insert string. this stores the user id. the code works when this is removed from the string. the session works because i am displaying the username on the page. I am stumped any ideas?
[php]if (isset($_SESSION[‘user_ref’])){
$name=mysql_query(“select FirstName from users where UserID = “.$_SESSION[‘user_ref’].””);
}
while($row = mysql_fetch_array( $name )) {
if (isset($_POST[‘UserName’])) {
if (!$_POST[‘FirstName’] | !$_POST[‘LastName’] | !$_POST[‘Telephone’]) {
die(‘You did not complete all of the required fields’);
}
if (!get_magic_quotes_gpc()) {
$_POST[‘Telephone’] = addslashes($_POST[‘Telephone’]);
}
$usercheck = $_POST[‘Telephone’];
$check = mysql_query(“SELECT telephone FROM referral WHERE username = ‘$usercheck’”)
or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 != 0) {
die(‘Sorry, the ‘.$_POST[‘Telephone’].’ has already been referred.’);
}
$insert = “INSERT INTO referral (user_id, first_name, last_name, telephone, company)
VALUES (’”.$_SESSION[‘user_ref’]."’, ‘".$_POST[‘FirstName’]."’, ‘".$_POST[‘LastName’]."’, ‘".$_POST[‘Email’]."’, ‘".$_POST[‘Telephone’]."’, ‘".$_POST[‘Company’]."’)";
$add_member = mysql_query($insert);[/php]
I know this is long but I want you to see exactly what its doing.
Mod Edit: Added [php] tags for readability.