vonKristoff Posted October 4, 2011 Share Posted October 4, 2011 Hi there, Im new here .. I have been trying for hours to just pass a variable from my HTML to a JQuery post which connects to my PHP file, reading the variable sent in the POST, and updating my database. Basically - my PHP is not getting the variable im sending to it - though it is definitely going as my HTML says so. my HTML click function says: $.post("setDB.php",{id:$('#myTxt').val()}); my PHP - connects to its DB with its new MySQLi set to $mysqli - says: $id = $_POST['id']; $query = "INSERT videos SET src = $id"; $result = $mysqli->query($query) or die($mysqli_error($mysqli)); ok - but no way is anything working ...... I have no hair left - if anyone else has some spare - please be my guest Link to comment https://forums.phpfreaks.com/topic/248395-jquery-post-to-my-php-file-to-read-its-variable/ Share on other sites More sharing options...
gristoi Posted October 5, 2011 Share Posted October 5, 2011 <?php $query = "INSERT INTO videos (`src`) VALUES ('$id')"; Link to comment https://forums.phpfreaks.com/topic/248395-jquery-post-to-my-php-file-to-read-its-variable/#findComment-1276099 Share on other sites More sharing options...
cybernet Posted October 7, 2011 Share Posted October 7, 2011 <?php $query = "INSERT INTO videos (`src`) VALUES ('$id')"; your signature fits the reply ) sorry for offtopic but i had to say it Link to comment https://forums.phpfreaks.com/topic/248395-jquery-post-to-my-php-file-to-read-its-variable/#findComment-1276736 Share on other sites More sharing options...
Andy-H Posted October 7, 2011 Share Posted October 7, 2011 Your MySQLi INSERT query is formatted as an update query, change it from $id = $_POST['id']; $query = "INSERT videos SET src = $id"; $result = $mysqli->query($query) or die($mysqli_error($mysqli)); to $id = (int)$_POST['id']; $query = "INSERT INTO videos ( $id )"; $result = $mysqli->query($query) or die($mysqli_error($mysqli)); or $id = (int)$_POST['id']; $query = "INSERT INTO videos ( id ) VALUES ( $id )"; $result = $mysqli->query($query) or die($mysqli_error($mysqli)); Link to comment https://forums.phpfreaks.com/topic/248395-jquery-post-to-my-php-file-to-read-its-variable/#findComment-1276737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.