0

I'm trying to pass a variable from javascript to php using this simple code and then I want to put it into my database:

<?php
 mysql_select_db($database_Connessione_server,$Connessione_server); //connection to db
 $ind = 1;

<script>
var i = 10;

<?php
    $ind = $GET['i'];
    mysql_query("INSERT INTO table1 VALUES (".$ind.")");                
?> </script>

but I keep getting the same error: Uncaught SyntaxError: Unexpected token < The connection to the db works, but the GET method doesn't get the value 'i'. Getting the type of the variable 'ind' I get undefined index i. Can someone help me to solve the problem? Is there another method to insert variables into database using javascript?

--EDIT--- What I want is to understand why my code doesn't work and what that error means in my case. I already read the answers to the other questions but couldn't find a solution.

  • 1
    Please do some research before posting a question, next time. The linked question appeared in the suggestions, and should have been visible while you were writing the question. – Cerbrus Sep 17 '14 at 09:38
  • the unexpected token is `<` in ` – andrew Sep 17 '14 at 09:58
  • @andrew Thank you for your help, I solved one problem but I'm still getting this: " Notice: Undefined index:i " on line 9 ($ind = $GET['i'];). Can you please explain me why? – Shazije Mustabelli Sep 17 '14 at 10:04

0 Answers0