srk2010 Posted January 5, 2010 Share Posted January 5, 2010 hai everybody , i am on my way to create a counter i.e as soon as the user clicks the image, count should be incremented and sent to the respected database table. here i am using javascript to increase the count using the javascript and the following <span id="increment"><?php echo $data1[id]?></span> as soon as the user click the image the value of <?php echo $data1[id]?> increments and i need to send this value to database table. To get the incremented value i use <input type="hidden" name="catch" value=<?php $_GET['$data[id]'] /> then i should post this using $get=trim($_POST['catch']; mysql_query("update table set id=$get"); the problem is if i refresh the page the counter is initialized to zero can anyone correct me so that i can update the value to the table? am i wrong anywhere? Any help is highly appreciated Link to comment https://forums.phpfreaks.com/topic/187226-update-the-php-variable-in-hidden-field-to-database-table/ Share on other sites More sharing options...
Tazerenix Posted January 5, 2010 Share Posted January 5, 2010 So why are you using javascript to increment like this? <span id="increment"><?php echo $data1['id']; ?></span> You could just create a form: <form action="page that processes and sends to db" method="post"> <?php echo $data1['id']; ?> <input type="hidden" name="current_id" value="$data1[id]" /> <br /> <input type="image" src="directory/of/image.png" alt="imagename" /> </form> and then in the page that processes it <?php $id = $_POST['current_id']; ++$id; $update = "UPDATE your_table SET id = '$id' WHERE something = something"; if (!mysql_query($update)) { echo "Error in mysql query"; } else { echo "Query success"; } ?> I might be mistaken but i think that is the kind of script you want? Link to comment https://forums.phpfreaks.com/topic/187226-update-the-php-variable-in-hidden-field-to-database-table/#findComment-988718 Share on other sites More sharing options...
srk2010 Posted January 5, 2010 Author Share Posted January 5, 2010 thankyou Tazerenix you are amazing! i am quite excited because i am searching in google for this code with both php and javascript yeterday . but you solved the problem with php.That's great. once again thankyou.Bye for now my friend. Link to comment https://forums.phpfreaks.com/topic/187226-update-the-php-variable-in-hidden-field-to-database-table/#findComment-988769 Share on other sites More sharing options...
Tazerenix Posted January 5, 2010 Share Posted January 5, 2010 xD, glad i could help you Link to comment https://forums.phpfreaks.com/topic/187226-update-the-php-variable-in-hidden-field-to-database-table/#findComment-989155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.