How to insert data in framework 7

i am looking for framework 7 data insert into database

using php database and i am using ajax to pass the data

demo.js

function save()
{

                var name = $$('.page').find('input[name="name"]').val();
                var email = $$('.page').find('input[name="email"]').val();

        $.ajax({  
             url:"insert.php",  
             method:"POST",  
             data:{name:name, email:email},  
             dataType:"text",  
             success:function(data)  
             {  
                  alert("success") ;
             }  
        });  
    }        

insert.php

$connect = mysqli_connect("localhost", "root", "", "demo-app");

if(isset($_GET['add'])) {

$name = mysqli_real_escape_string($connect, $_POST['name']); $email = mysqli_real_escape_string($connect, $_POST['email']);

echo $sql ="INSERT INTO register(name, email) VALUES ('".$name."','".$email."')"; $result = mysqli_query($connect,$sql) ;

if($result){
    echo '<script type="text/javascript">alert("Successfully Add.")</script>';
    echo "<meta http-equiv='refresh' content='0;url=index.html'>";    
}
}

anyone help me

thanks & regards, Darshan

1 Like

You need to understand how the F7 request works first, then you need to see your php better, with this function it will not work, sending ajax per post and getting caught in the first if not right

1 Like

I replied that in another post, your transaction should be all in JSON …

the return of your PHP should be JSON.