Jump to content

[SOLVED] Need help with UPDATE blah SET blah


jeger003

Recommended Posts

hello,

I'm trying to create a button where if clicked by the user it would change the value of a mysql table.

 

works like a switch when clicked it would change the field in mysql 1 = on clicked again would change it to 0 = off it displays an image.

 

i want the user to be able to click image and it would UPDATE the table....so if it was 1 it would change it to 0 if it was 0 it would change it to 1

 

my only issue is making it into a button.

 

here is what i have so far which is nothing but a start:


$Sold_button = "<img src='Sold_button.png' alt='Sold' border='0'/>";
$Sold_button_Sold = "<img src='Sold_button_Sold.png' alt='Sold' border='0'/>";

mysql_query("SELECT display_sold FROM listings")


   if ($Sold_displayed == 1)
   {
   echo "<td bgcolor='$color' ><div align='center' class='FontColorsData'>$Sold_button_Sold</a></div></td>";
   }
   else
   {
   	echo "<td bgcolor='$color' ><div align='center' class='FontColorsData'>$Sold_button</div></td>";   	
   }


//where do i use this to work as a button?
mysql_query("UPDATE listings SET display_sold = 0")



 

 

When using $_GET you don't need a form to be submitted.

 

For example :

 

Make your image a link :

 

<a href="the_file?update=1"><img src="blah" /></a>

 

I used the_file for the name of your query file which will update the sql.

the ?update=1 means :

 

?    => you want to give a variable through the url

update=1  =>  that variable name is "update" and its value is "1".

 

if you need to send more than 1 variable, it will be like this :

the_file?update=1&second=45

 

now how to get it in your script?

you can access the update variable by :

$_GET['update'] , which its value is 1 in the above exampe.

$_GET['second'] , which its value is 45 in the above example.

 

now use these $_GET in your sql query.

 

Just note, Always validate your data coming from $_GET.  (Always validate any data coming to your site, either it is POST or GET, But put twice notice on GETs)

thats actually a good idea but im not able to use that technique cause my url's are already in that format.......this is wat they look like

 

 

sitename.com/index.php?a=23b=34

 

is there another way to make it work?

 

i would use this way but im afraid of it conflicting with my current setup

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.