Mysql database update with ajax php not working

2016-05-21T22:23:19

I am trying to update mysql database table with button click. But database is not getting updated...

HTML Code :

<tr >
<td>Advt Heading :</td>
<td>
<input type="hidden" name="idnew" id="idnew" value="<?=$member_data['id']?>"> //retrieved from mysql database 

<input type="text" name="advt_headingnew" id="advt_headingnew" value="<?=stripslashes($member_data['advt_heading']);?>" /> //retrieved from mysql database ...**I want to edit its previus retreived value...and update database**

<input name="submit" type="button" id="submit" value="Update" />

</td>
</tr>

SCRIPT :

<script src="http://code.jquery.com/jquery.min.js"></script>  
<script>
$(document).ready(function () { 
$('#submit').click(function(){
var advt_headingnew = $("#advt_headingnew").val();
var idnew = $("#idnew").val();


$.ajax({
     type:'POST',
     url:'update-advt-heading.php',
     data: "advt_headingnew="+advt_headingnew+"&idnew="+idnew,

     success:function( msg ) {
     alert( "Data Saved: " + msg );
        }

 });
});
});


</script>

PHP - update-advt-heading.php CODE :

<?
$user_name = "databaseusername";
$password = "databasepassword";
$database = "databasename";
$server = "localhost";

mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database);

$heading = $_POST['advt_headingnew'];
$id=$_POST["idnew"];

if (isset($_POST['submit'])){


   $queryStr = "UPDATE tablename SET advt_heading='$heading' WHERE id='$id'";
    if ( mysql_query($qyeryStr)){
        return "success!";
    }else{
        return "failed!";
    }
}

?>

Copyright License:
Author:「Dr Manish Lataa-Manohar Joshi」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/37364112/mysql-database-update-with-ajax-php-not-working

About “Mysql database update with ajax php not working” questions

I am trying to update mysql database table with button click. But database is not getting updated... HTML Code : &lt;tr &gt; &lt;td&gt;Advt Heading :&lt;/td&gt; &lt;td&gt; &lt;input type=&q
I recently create a web project. I want to update a mysql query through ajax and PHP. I created the code but I had problems. My server uses PHP 5.2*. When I press the button to update the database
i have this script which updates a counter in a mysql database but it's not working at all and i can't see what wrong as i am new into php and ajax: $(function () { $('.press_me').click(fu...
I have the following script: $(function (){ $('.press_me').click(function(){ var request = $.ajax({ type: "POST", ...
I think this is simple question. I'm new to jQuery. I'm trying to make script, so that when you click on image, ajax will call php file which will update mySQL database.My script: &lt;script&gt;
How do i update mysql database with ajax and php with no page refresh
This is my first ajax attempt. I want to pass id variable to ajax function and update my database. When I run this code everything looks fine. Id in alert is correct but my database is not updated.
I've read through a number of similar questions and tried my hand at putting it to work on my website, but it is not working (when you click the link there is no response on the console and the dat...
I am a beginner and I am trying to learn how to add, delete, retrieve and update a database using PHP and Ajax. At this time I have accomplished how to retrieve and delete so I am trying to update...
this question is relevant to Error in ajax insert database. Many advices, but none of them helps. You can see a demo: http://phppot.com/php/php-mysql-inline-editing-using-jquery-ajax/ I have troubl...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.