JonathanAvfcJones Posted December 3, 2012 Share Posted December 3, 2012 Hello, I am new to php i was wondering if anyone can help me basically i have been assigned to create a database where you have four questions and four answers and the database should display the four questions and next to them would say "incorrect" or "correct" if you click on the button if this makes sense here is my html code but I have no idea on how get php to place it into the database, i tried to use Div/ID tags to help but i haven't got a clue what i am doing <img src="Images/Question1.png" usemap="#mainMap" id="main" style="position:absolute;display:none;left:0px;top:0px;" border="0" /> <map name="mainMap" id="mainMap"> <div id="Incorrectanswer1"><area shape="rect" coords="82,192,196,242" onclick="incorrectAnswer()" /></div> <div id="Incorrectanswer2"><area shape="rect" coords="83,254,197,300" onclick="incorrectAnswer()" /></div> <div id="Incorrectanswer3"><area shape="rect" coords="83,310,201,368" onclick="incorrectAnswer()" /></div> <div id="Correctanswer1"><area shape="rect" coords="84,373,205,430" onclick="correctAnswer()" /></div> </map> if anyone could help or point me in the right direction this would be helpful. Thanks, Jonathan Jones Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/ Share on other sites More sharing options...
Christian F. Posted December 3, 2012 Share Posted December 3, 2012 (edited) onclick calls a JS function, in this case incorrectAnswer () or correctAnswer (). If you want to communicate with PHP then you'll either need to use GET or POST. Considering your code above you can accomplish the first method quite easily: Just add a [ic]href[ic] attribute to the area tags. You can also, in addition to that, create those functions above to do some more fancy stuff; Like AJAX; If you want to. The main point is that you don't send the contents of HTML tags to PHP, as HTML is a static language. You can, however, use HTTP requests to the server to send data to PHP. Forms, hrefs (URLs) and AJAX are the three major ways to accomplish this. Edited December 3, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/#findComment-1397117 Share on other sites More sharing options...
JonathanAvfcJones Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) onclick calls a JS function, in this case incorrectAnswer () or correctAnswer (). If you want to communicate with PHP then you'll either need to use GET or POST. Considering your code above you can accomplish the first method quite easily: Just add a [ic]href[ic] attribute to the area tags. You can also, in addition to that, create those functions above to do some more fancy stuff; Like AJAX; If you want to. The main point is that you don't send the contents of HTML tags to PHP, as HTML is a static language. You can, however, use HTTP requests to the server to send data to PHP. Forms, hrefs (URLs) and AJAX are the three major ways to accomplish this. I understand where you are coming from, the thing im going to find hard is figuring out the functions as well as the GET or POST i now know aboyt tge html tags to php that was quite useful but i am still confused on the subject, i apologies for this as im just learning all of this, any more help on the subject/examples would help out, thanks for your comment. Edited December 3, 2012 by JonathanAvfcJones Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/#findComment-1397120 Share on other sites More sharing options...
Christian F. Posted December 3, 2012 Share Posted December 3, 2012 Quickest way to figure out how it works, is to replace the onclick attributes with a href, where you set answer=[in]correct as a URL parameter. Then, on the server side (in PHP) do a var_dump () on the $_GET superglobal array. For more information, I highly recommend the PHP Manual. Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/#findComment-1397139 Share on other sites More sharing options...
JonathanAvfcJones Posted December 3, 2012 Author Share Posted December 3, 2012 Quickest way to figure out how it works, is to replace the onclick attributes with a href, where you set answer=[in]correct as a URL parameter. Then, on the server side (in PHP) do a var_dump () on the $_GET superglobal array. For more information, I highly recommend the PHP Manual. Ah okay this is making sense a bit i didn't understand about the href or the server side but i am doing research on them and the PHP Manual helped a little bit but still confused, someone recommended that to do this use a forum and POST and the server checks to see weather it is correct or not i have no idea on how to test this as im still learning the lanuage, any help on this subject. Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/#findComment-1397150 Share on other sites More sharing options...
cyberRobot Posted December 3, 2012 Share Posted December 3, 2012 The following page of the PHP manual may help: http://php.net/manua...es.external.php Quote Link to comment https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/#findComment-1397167 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.