2

I have to call this php file

<?php
session_start();
require 'connect.php';

//Prendo le tre variabili dalla form
if(isset($_POST['Titolo'])) {
    $title_rew = $conn->real_escape_string($_POST['Titolo']);
}

if(isset($_POST['Voto'])) {
   $voto_rew = $conn->real_escape_string($_POST['Voto']);
}

if(isset($_POST['Review'])) {
    $review_rew = $conn->real_escape_string($_POST['Review']);
}

if(isset($_POST['ID_locale'])) {
    $id_rew = $conn->real_escape_string($_POST['ID_locale']);
}

$current_date = date('Y-m-d');

$sql = "INSERT INTO recensione (Titolo_R, Voto_R, Commento_R, IDnegozio_R, Email_R, Utente_R, Data_R) 
        VALUES ('$title_rew', '$voto_rew', '$review_rew','$id_rew','".$_SESSION['emailSessione']."','".$_SESSION['usernameSessione']."','$current_date')";

$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
//Chiudo la connessione
$conn->close(); 

header("location:..\locals_page.php");
?>

I've tried with this

$("#submit_review").unbind().click(function() {
var chx = document.getElementsByName("Voto");
for (var i=0; i<chx.length; i++) {
   // If you have more than one radio group, also check the name     attribute
   // for the one you want as in && chx[i].name == 'choose'
   // Return true from the function on first match of a checked item
   $.post("php/insert_comment.php" );
     return true;

}
 // End of the loop, return false
 alert("Seleziona almeno il voto!");
return false;
});

But there it's not working. It's strange because with a button submit and a

 <form role="form" id="review-form" method="post" action="php/insert_comment.php">

It was working. But now I have to do this without a button type "Submit"

Thank you to all in advance

1
  • first of all your code is working on php or ajax? i think $.post("php/insert_comment.php" ); return true; is not working because on submit of your form action attribute redirect your data to that url then I think your click event not getting worked Commented Aug 4, 2017 at 10:37

3 Answers 3

2

just try this

$.ajax({
    url : "php/insert_comment.php",
    type : "post",
    data : $("#review-form").serialize();
    success : function(data){
        alert(data); // show when ajax return response from php script
    }
})
Sign up to request clarification or add additional context in comments.

Comments

0

for that registered onclick event on that button and send ajax request using jquery

$.ajax({
type:'POST',
url : "your url",
data : $('form').serializeArray(),
cache: false,
success:function(response){
console.log(response) // your result from php
}
})

Comments

0

Single quotes treat $ as a string

$sql = "INSERT INTO recensione (Titolo_R, Voto_R, Commento_R, IDnegozio_R, Email_R, Utente_R, Data_R) 
    VALUES ('".$title_rew."', '".$voto_rew."', '".$review_rew."','".$id_rew."','".$_SESSION['emailSessione']."','".$_SESSION['usernameSessione']."','$current_date')";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.