Jump to content

update the php variable in hidden field to database table


srk2010

Recommended Posts

hai everybody :D,

 

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 ::)

 

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?

thankyou  Tazerenix ;D

 

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. :D

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.