Jump to content

[SOLVED] trouble outputting an array


dadamssg

Recommended Posts

writing a register script and im checking if the username and email they typed in already exists, if it does put an error message in an array, then on the form output those errors...i used the same method and it works but now its not. it just displays "array" instead of whats in the array

 

part in the register script

 

/* check whether email already exists */

$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); 
     $sql = "SELECT email FROM Member 
                    WHERE email = '$email'";  
     $result = mysqli_query($cxn,$sql)
               or die("Couldn't execute select query.");
     $num = mysqli_num_rows($result);                 
     if ($num > 0)                                    
     {
        $alert[] = "There is already an account under $email.<br>";
	extract($_POST);
        include("register_form.php");
        exit();
     }

 /* check whether login name already exists */
     $sql = "SELECT loginName FROM Member 
                    WHERE loginName = '$username'";  
     $result = mysqli_query($cxn,$sql)
               or die("Couldn't execute select query.");
     $num = mysqli_num_rows($result);                 
     if ($num > 0)                                    
     {
        $alert[] = "$username is already in use. 
                         Select another Username.<br>";
    extract($_POST);
        include("register_form.php");
        exit();
     }

 

and the part in displaying the form and error messages if set

if(isset($alert))
   {
   echo "$alert<br>";
   }

Link to comment
https://forums.phpfreaks.com/topic/151180-solved-trouble-outputting-an-array/
Share on other sites

oh forgot this part in the register script...kinda important haha

 

 if(@is_array($alert))
  {
    $aler_t = "";
    foreach($alert as $value)
     {
	 $aler_t .= $value;
	 }
   
          extract($_POST);
          include("register_form.php");
          exit();
      }

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.