cornishmouse Posted August 11, 2007 Share Posted August 11, 2007 I'm only a beginner at php and i don't know alot yet so what i'm asking is probably shockingly simple so please bear with me. i'm making a text based game and what i'm stuck on is making a button click change a value in a variable ive tried looking at tutorials but i cant find anything helpful if you could explain it to me or give me an example that would be great or a link to a tutorial that you think will help Quote Link to comment https://forums.phpfreaks.com/topic/64386-solved-how-do-i-change-variables-with-button-clicks/ Share on other sites More sharing options...
Fadion Posted August 11, 2007 Share Posted August 11, 2007 Consider the following code: $myVar = 'sword'; echo "<a href=\"mypage.php?myvar=axe\">Change my var</a>"; if(isset($_GET['myvar']) and $_GET['myvar'] == 'axe'){ $myVar = mysql_real_escape_string($_GET['axe']); echo $myVar; //it will print 'axe' } What im doing with that code is initialize $myVar with the value 'sword'. The "<a href ..." part prints a link with a url variable which then i check if it is set. If so $myVar will become as the url variable, 'axe'. The $_GET is the key to capture url variables. Hope its clear. Quote Link to comment https://forums.phpfreaks.com/topic/64386-solved-how-do-i-change-variables-with-button-clicks/#findComment-321080 Share on other sites More sharing options...
cornishmouse Posted August 11, 2007 Author Share Posted August 11, 2007 I understand everything except the mysql_real_escape_string what is that doing exactly? ??? is it possible to put this in a buttton? i know it has a onclick="" feature but im not sure how to put anything inside can i just put it in as code or do i need to make a function and call it? Quote Link to comment https://forums.phpfreaks.com/topic/64386-solved-how-do-i-change-variables-with-button-clicks/#findComment-321169 Share on other sites More sharing options...
Fadion Posted August 11, 2007 Share Posted August 11, 2007 From php manual: Escapes special characters in the unescaped_string, taking into account the current character set of the connection so that it is safe to place it in a mysql_query(). If binary data is to be inserted, this function must be used. mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a. This function must always (with few exceptions) be used to make data safe before sending a query to MySQL. The onclick event is used to call javacript code or functions. Make an html link as in the sample code and when u click it, it sends to the url the variable which can be captured with $_GET. Hope its clear now. Quote Link to comment https://forums.phpfreaks.com/topic/64386-solved-how-do-i-change-variables-with-button-clicks/#findComment-321309 Share on other sites More sharing options...
cornishmouse Posted August 12, 2007 Author Share Posted August 12, 2007 yeah i think im getting there slowly lol i might be slightly out of my depth but ill get there thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/64386-solved-how-do-i-change-variables-with-button-clicks/#findComment-321651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.