Uncaught Error: Call to undefined function

Alastair

It was working but now it stops working why? it soppiest to write into a file and save it. it was working yesterday but today it stops and I can't figure out why a search the internet but still nothing I can't .

Thanks in advanced

<!DOCTYPE html>
<html>
<head>
    <title>Contact us</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-default">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li><a href="aboutus.html">About US</a></li>
            <li><a href="contactus.php">Contact Us</a></li>
            <li><a href="property.php">Propertys</a></li>
          </ul>

        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>

    <h1>Contact us</h1>

    <form  method="post" action="contactus.php" >

        <label>Email</label>
        <input type="text" name="email" required>
        <br>
        <label>Mobile number</label>
        <input type="number" name="number" required>
        <br>
        <textarea name="comments" required></textarea>

        <button name="submit" type="submit"> submit</button>


    </form>

    <?php

            if(isset($_POST['submit'])){
        $number = $_POST["number"];
        $email = $_POST["email"];

        $trueemail;


        $massage = $_POST["comments"];


        if(isset($number)){



            if (strlen($number) == 8) {

                $truenumber = true;
            }else{

                echo "Input your mobile number";

            }
        }   


        if(isset($email)){
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            echo "<br>";
            echo "Enter a valid email";
        }else{
            $trueemail = true;
        }
    }

    if($trueemail == true && $truenumber == true){
    writeToFile($email,$number,$massage);


    function writeToFile($trueemail,$truenumber,$massage)   
    {

            $myfile = fopen("contectus.txt", "w") or die("Unable to open file!");
            fwrite($myfile, $trueemail . PHP_EOL);
            fwrite($myfile, $truenumber . PHP_EOL);
            fwrite($myfile, $massage . PHP_EOL);
            fclose($myfile);
    }
}
}



    ?>

</body>
</html>
Ahmed Ginani

Try below code:

  1. put submit event starting of the page.

  2. you cann't call function without defining before calling.

     <?php
    
        function writeToFile($trueemail,$truenumber,$massage)   
    {
    
            $myfile = fopen("contectus.txt", "w") or die("Unable to open file!");
            fwrite($myfile, $trueemail . PHP_EOL);
            fwrite($myfile, $truenumber . PHP_EOL);
            fwrite($myfile, $massage . PHP_EOL);
            fclose($myfile);
    }
    
    
            if(isset($_POST['submit'])){
        $number = $_POST["number"];
        $email = $_POST["email"];
    
        $trueemail;
    
    
        $massage = $_POST["comments"];
    
    
        if(isset($number)){
    
    
    
            if (strlen($number) == 8) {
    
                $truenumber = true;
            }else{
    
                echo "Input your mobile number";
    
            }
        }   
    
    
        if(isset($email)){
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            echo "<br>";
            echo "Enter a valid email";
        }else{
            $trueemail = true;
        }
    }
    
    if($trueemail == true && $truenumber == true){
    writeToFile($email,$number,$massage); 
    }  } ?>
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Uncaught Error: Call to undefined function bindValue() in

Uncaught Error: Call to undefined function NOW()

Uncaught Error: Call to undefined function each()

Fatal error: Uncaught Error: Call to undefined function mysql_connect()

Fatal error: Uncaught Error: Call to undefined function - have to use $this

Fatal error: Uncaught Error: Call to undefined function bcadd()

Fatal error: Uncaught Error: Call to undefined function get_option()

Fatal error: Uncaught Error: Call to undefined function mysql_close()

Fatal error: Uncaught Error: Call to undefined function mysqli_connect()

curl_init() error Uncaught Error: Call to undefined function

Fatal error: Uncaught Error: Call to undefined function header() - Beginner question

Fatal error: Uncaught Error: Call to undefined function get_header()

PHP 7.4.1 Uncaught Error: Call to undefined function mysqli_connect()

Uncaught Error: Call to undefined function mysql_select_db()

Uncaught Error: Call to undefined function stats_cdf_t()

Uncaught Error: Call to undefined function mysql_connect() - WordPress Setup

Uncaught Error: Call to undefined function GuzzleHttp\default_user_agent()

Uncaught Error: Call to undefined function get_file_html()

Uncaught Error: Call to undefined function mysql_connect()

Uncaught Error: Call to undefined function mysql_escape_string()

Uncaught Error: Call to undefined function mysqli_result() does not work

Uncaught Error: Call to undefined function getUserInformation() - PHP MySQLi

Uncaught Error: Call to undefined function sqlsrv_connect()

Uncaught Error: Call to undefined function sql_regcase()

Uncaught Error: Call to a member function

Fatal error: Uncaught Error: Call to undefined function redirect() PHP logout session

Fatal error: Uncaught Error: Call to undefined function wp_get_current_user()

Fatal error: Uncaught Error: Call to undefined function curl_version() - Localhost Dev

Fatal error: Uncaught Error: Call to undefined function mb_detect_encoding()