jeger003 Posted January 20, 2009 Share Posted January 20, 2009 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") Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/ Share on other sites More sharing options...
revraz Posted January 20, 2009 Share Posted January 20, 2009 What you can do is have the URL send a variable like ?display=0 or ?display=1 and then use $_GET['display'] to set the new status. Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741380 Share on other sites More sharing options...
jeger003 Posted January 20, 2009 Author Share Posted January 20, 2009 but would that update the database? would i be able to just use <form> and have it process.php as UPDATE table? like how would i use your code in mine? Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741422 Share on other sites More sharing options...
asmith Posted January 20, 2009 Share Posted January 20, 2009 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) Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741447 Share on other sites More sharing options...
jeger003 Posted January 20, 2009 Author Share Posted January 20, 2009 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 Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741474 Share on other sites More sharing options...
asmith Posted January 20, 2009 Share Posted January 20, 2009 There's no conflict. They're just plain variables. add your own variable with the & sign. sitename.com/index.php?a=23b=34&you_own_variable=value Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741478 Share on other sites More sharing options...
revraz Posted January 20, 2009 Share Posted January 20, 2009 sitename.com/index.php?a=23&b=34&update=1 Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741479 Share on other sites More sharing options...
jeger003 Posted January 20, 2009 Author Share Posted January 20, 2009 oh your right!!!!! i havent been able to test it and wasnt sure if it would be safe to do.... thanks for the help guys!!!!! Link to comment https://forums.phpfreaks.com/topic/141636-solved-need-help-with-update-blah-set-blah/#findComment-741527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.