Jump to content

Bravono

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by Bravono

  1. Quote

    please what is wrong with this coding? am getting this error "Fatal error: Uncaught Error: Call to undefined function test_input() in C:\xampp\htdocs\Signup\www\index.php:30 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Signup\www\index.php on line 30"

     <!DOCTYPE html>
    <html>
    <head>
    <style>
        .error{color: red;}
    </style>
    </head>
    <body>
       <link rel="stylesheet" type="text/css" href="CSS/default.css">
        <?php
        ini_set('display_error', 1);
        // define variables and set to empty values
        $nameErr = $emailErr = $passwordErr = $websiteErr = $country = $state = $city ="";
        
        $name = $email = $password = $website = $country = $state = $city ="";
        
         function test_jnput($data)
            {
                $data = trim($data);
                $data = stripslashes($data);
                $data = htmlspecialchars ($data);
                return $data;
            } 
        
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            
            if(empty($_POST["name"])) {
                $nameErr = "Name is required";
            } else { 
               $name = test_input($_POST["name"]);
        // check if name only contains letters and white space
                       
        if (!preg_match("/^[a-zA-Z]*$/",$name)){
            $nameErr = "Only letters and white space allowed";
                }
            }
        }
         if(empty($_POST["email"])) {
          $emailErr = "Email is required";  
         } else { 
             $email = test_input($_POST["email"]);
          // check if e-mail address is well formed
            if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
              $emailErr = "invalid email format"; 
            }
        }
            
        if(empty($_POST["website"])) {
           $website = "";
        } else {
           $website = test_input($_POST["website"]);
        // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
            if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
                $websiteErr = "invalid URL";
            }
        }
            
        if(empty($_POST["country"])) {
           $country = "";
        } else {
           $country = test_input($_POST["country"]);
        }
        
        ?>
        
        <p><span class ="error">* required field.</span></p>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
        Name: <input type="text" name="name" value="<?php echo $name;?>">
        <span class="error">*<?php echo $nameErr;?></span>
        <br><br>
        E-mail: <input type="text" name="email" value="<?php echo $email;?>">
        <span class="error">*<?php echo $emailErr;?></span>
        <br><br>
        Website: <input type="text" name="website" value="<?php echo $website;?>">
        <span class="error"><?php echo $websiteErr;?></span>
        <br><br>
        Password: <input type="password" name="password" value="<?php echo $password;?>">
        <span class="error"><?php echo $passwordErr;?></span>
        <br><br>
        Country: <input type="text" name="country" value="<?php echo $country;?>">
        <span class="error"><?php echo $country;?></span>
        <br><br>
        State: <input type="text" name="state" value="<?php echo $state;?>">
        <span class="error"><?php echo $state;?></span>
        <br><br>
        City: <input type="text" name="city" value="<?php echo $city;?>">
        <span class="error"><?php echo $city;?></span>
        <br><br>
        <input type="submit" name="submit" value="submit">
        </form>
        
        <?php
        echo "<h2>Your Input</h2>";
        echo $name;
        echo "<br>";
        echo $email;
        echo "<br>";
        echo $website;
        echo "<br>";
        echo $password;
        echo "<br>";
        echo $country;
        echo "<br>";
        echo $state;
        echo "<br>";
        echo $city;
        echo "<br>";
        
        
        ?>
          
        <?php 
        $servername = "localhost";
        $username = "root";
        $password = "adeshina2344";
        
        // Create connection
        $conn = new mysqli($servername, $username, $password);
        
        // Check connection
        
        if ($conn->connect_error) {
            die("Connection failed: ". $conn->connect_error);
            
        }
        
        echo "Connection successful";
        ?> 
            
        
        
    </body>
    </html>

     

×
×
  • Create New...