Timma Posted March 25, 2007 Share Posted March 25, 2007 <html><head> <title>TEST THANKS</title> </head><body> <?php $thanks = 0; echo "<button onClick=$thanks++;> Thanks ME </button>"; echo "$thanks"; ?> </body></html> This is my script right now, but I'm trying to make it so that $thanks gets updated on the page, but I can't figure it out. Link to comment https://forums.phpfreaks.com/topic/44212-first-script-help/ Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 PHP is server side. Your code wont work. you need to do something like: <html><head> <title>TEST THANKS</title> </head><body> <?php if ($_GET['num']) { $thanks = $_GET['num']; $thanks++; } else { $thanks = 0; } echo '<a href="'.$_SERVER['PHP_SELF'].'?num='.$thanks.'"> Thanks ME </a>'; echo "$thanks"; ?> </body></html> Link to comment https://forums.phpfreaks.com/topic/44212-first-script-help/#findComment-214730 Share on other sites More sharing options...
Timma Posted March 25, 2007 Author Share Posted March 25, 2007 Thanks, but what I'd like to do is make it save what the number is in my database (called 'database' for now) instead of it being something which is changed by the url. Link to comment https://forums.phpfreaks.com/topic/44212-first-script-help/#findComment-214735 Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 There isnt any real way with just PHP to change the value of $thanks without reloading. What do you mean, do you want to click a link and then store the number? if so you will need something like this: <?php //db connection defined earlier if ($_GET['num']) { $thanks = $_GET['num']; $thanks++; mysql_real_escape_string($thanks); $sql = "insert into numbers (number) values ('{$thanks}')" mysql_query($sql); } else { $thanks = 0; } echo '<a href="'.$_SERVER['PHP_SELF'].'?num='.$thanks.'"> Thanks ME </a>'; echo "$thanks"; ?> Link to comment https://forums.phpfreaks.com/topic/44212-first-script-help/#findComment-214737 Share on other sites More sharing options...
Timma Posted March 25, 2007 Author Share Posted March 25, 2007 Alright, thanks. I've got it. I'll just edit that a bit, thanks! Link to comment https://forums.phpfreaks.com/topic/44212-first-script-help/#findComment-215005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.