Call a PHP function after onClick HTML event

前端 未结 4 1460
迷失自我
迷失自我 2021-02-08 15:16

Purpose: Call a PHP function to read data from a file and rewrite it. I used PHP only for this purpose - FileIO - and I\'m new to PHP.

Solution

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-08 15:45

    You don't need javascript for doing so. Just delete the onClick and write the php Admin.php file like this:

    
    alert('Data not existed!')";
            } 
        else{
            $contact_list = $contact_list . addNewContact();
            file_put_contents("data/data.json", $contact_list);
            }
        fclose($datafile);
        }
    
    // Call the function saveContact()
    saveContact();
    echo "Thank you for joining us";
    }
    else //If the form is not submited or not all the required fields are filled
    
    { ?>
    
    
    Add New Contact


    Thought I don't like the PHP bit. Do you REALLY want to create a file for contacts? It'd be MUCH better to use a mysql database. Also, adding some breaks to that file would be nice too...

    Other thought, IE doesn't support placeholder.

提交回复
热议问题