chriscloyd Posted November 30, 2006 Share Posted November 30, 2006 i have a function and the code is below[code]<?phpfunction check_city($name){ $checkname = mysql_query("SELECT * FROM users WHERE cityname = '$name'"); $namecheck = mysql_num_rows($checkname); if ($namecheck > 0){ $reason = "-The name of the city you choose have been taken already<br>"; header("Location: index.php?page=register&reason=$reason"); } elseif ($name == NULL){ $reason = "-Your City must have a name, please fill in the City name field<br>"; header("Location: index.php?page=register&reason=$reason"); }}?>[/code]and the code that calls the function is below[code]<?phpsession_start();include("db.php");include("functions.php");if (isset($_POST['register'])){$first = $_POST['first'];$last = $_POST['last'];$email = $_POST['email'];$email2 = $_POST['email2'];$password = $_POST['password'];$password2 = $_POST['password2'];$emperorname = $_POST['emperorname'];$cityname = $_POST['cityname'];$key = $_POST['key'];$keyc = $_POST['keyc'];$ip = $_POST['ip'];check_email($email, $email2);first_last($first, $last);check_passwords($password, $password2);check_emperorname($emperorname);check_city($cityname);check_keys($key, $keyc);}?>[/code]im getting the error-Your City must have a name, please fill in the City name fieldby i know for a fact its being called up Link to comment https://forums.phpfreaks.com/topic/28959-function-trouble/ Share on other sites More sharing options...
btherl Posted November 30, 2006 Share Posted November 30, 2006 How do you know it is properly set? Try printing it out just before your "if", inside check_city(). Link to comment https://forums.phpfreaks.com/topic/28959-function-trouble/#findComment-132624 Share on other sites More sharing options...
CheesierAngel Posted November 30, 2006 Share Posted November 30, 2006 Try doing this:[code]<?phpfunction check_city($name = null){ if(!empty($name)) { $checkname = mysql_query("SELECT * FROM users WHERE cityname = '$name'"); $namecheck = mysql_num_rows($checkname); if ($namecheck > 0){ $reason = "-The name of the city you choose have been taken already<br>"; header("Location: index.php?page=register&reason=$reason"); } // What if the name does not exists ? return; } $reason = "-Your City must have a name, please fill in the City name field<br>"; header("Location: index.php?page=register&reason=$reason");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28959-function-trouble/#findComment-132782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.