Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271526-getting-div-content-to-php/
Share on other sites

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 by Christian F.

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 by JonathanAvfcJones

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.