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
https://forums.phpfreaks.com/topic/28959-function-trouble/
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
https://forums.phpfreaks.com/topic/28959-function-trouble/#findComment-132782
Share on other sites

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.