Jump to content

function trouble


chriscloyd

Recommended Posts

i have a function and the code is below
[code]
<?php
function 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]<?php
session_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 field
by i know for a fact its being called up

Link to comment
Share on other sites

Try doing this:

[code]
<?php
function 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.