Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax with PHP and HTML
    primarykey
    data
    text
    <pre><code>&lt;input type="button" value="addkid " onClick="show()" /&gt; &lt;div&gt; &lt;div id="myTableData" style="display:none; width:800px; height:500px; background-color:yellow; margin:0 auto;"&gt; &lt;form action="javascript:insert()" method="get"&gt; &lt;table&gt; &lt;tr&gt; &lt;td width="175"&gt;NAME&lt;/td&gt; &lt;td width="245"&gt;&amp;nbsp;Gender&lt;/td&gt; &lt;td width="245"&gt;Date of Birth&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="175"&gt; &lt;input type="text" name="kid_name" id="kid_name" /&gt; &lt;/td&gt; &lt;td width="245"&gt;FEMALE &lt;input type="radio" name="gender" value="female" id="gender" /&gt;MALE &lt;input type="radio" name="gender" id="gender" value="male" /&gt; &lt;/td&gt; &lt;td width="245"&gt; &lt;?php for ( $i=1; $i&lt;13; $i++ ) { $month=d ate( 'm', mktime(0,0,0,$i,2,2000)); $sel=( $i==d ate( 'n') ? ' selected="selected"' : ''); $options1[]="&lt;option value=\" {$month}\ " {$sel}&gt;{$month}&lt;/option&gt;"; } $options_list1=j oin( "", $options1); echo "&lt;select name=\"month\ " id='month' &gt;{$options_list1}&lt;/select&gt;"; for ( $j=1; $j&lt;32; $j++ ) { $theday=d ate( 'd', mktime(0,0,0,0,$j,2000)); $sel=( $j==d ate( 'd') ? ' selected="selected"' : ''); $options2[]="&lt;option value=\" {$theday}\ " {$sel}&gt;{$theday}&lt;/option&gt;"; } $options_list2=j oin( "\r\n", $options2); echo "&lt;select name=\"day\ " id='day' &gt;{$options_list2}&lt;/select&gt;"; for ( $k=1960; $k&lt;2016; $k++ ) { $theyear=d ate( 'Y', mktime(0,0,0,1,1,$k)); $sel1=( $k==d ate( "Y") ? ' selected="selected"' : ''); $options3[]="&lt;option value=\" {$theyear}\ " {$sel1}&gt;{$theyear}&lt;/option&gt;"; } $options_list3=j oin( "\r\n", $options3); echo "&lt;select name=\"year\ " id='year' &gt;{$options_list3}&lt;/select&gt;"; ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" name="sub" value="add" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; function show() { document.getElementById("myTableData").style.display = "block"; } function createObject() { var request_type; var browser = navigator.appName; if (browser == "Microsoft Internet Explorer") { request_type = new ActiveXObject("Microsoft.XMLHTTP"); } else { request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); //value solve an Internet Explorer cache issue var nocache = 0; function insert() { // Optional: Show a waiting message in the layer with ID login_response document.getElementById('content02').innerHTML = "Just a second..." // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding. var kid_name = encodeURI(document.getElementById('kid_name').value); var gender = encodeURI(document.getElementById('gender').value); var month = encodeURI(document.getElementById('month').value); var day = encodeURI(document.getElementById('day').value); var year = encodeURI(document.getElementById('year').value); // Set te random number to add to URL request nocache = Math.random(); // Pass the login variables like URL variable http.open('get', '4.php?kid_name=' + kid_name + '&amp;gender=' + gender + '&amp;month=' + month + '&amp; day=' + day + '&amp;year=' + year + '&amp;nocache = ' + nocache); http.onreadystatechange = insertReply; http.send(null); } function insertReply() { if (http.readyState == 4) { var response = http.responseText; // else if login is ok show a message: "Site added+ site URL". document.getElementById('content02').innerHTML = 'Your contact was successfully added!' + response; } } &lt;/script&gt; </code></pre> <p><strong>4.php</strong></p> <pre><code>&lt;?php if(isset($_GET['kid_name']) &amp;&amp; isset($_GET['gender']) &amp;&amp; isset($_GET['year']) &amp;&amp; isset($_GET['day']) &amp;&amp; isset($_GET['month']) ) { echo $newFname = $_GET["kid_name"] ; echo $newLname = $_GET["gender"] ; echo $newPhone = $_GET["year"] ; echo $newEmail = $_GET["day"] ; echo $newAddress = $_GET["month"] ; //$insertContact_sql = "INSERT INTO `test`.`contacts` (`newFname`, `newLname`, `newPhone`, `newEmail`, `newAddress`, `group`) VALUES ('{$newFname}' , '{$newLname}' , '{$newPhone}' , '{$newEmail}' , '{$newAddress}' , '{$group}')"; //$insertContact= mysql_query($insertContact_sql) or die(mysql_error()); } else { echo 'Error! Please fill all fileds!'; } ?&gt; </code></pre> <p>I am working with php language. There is a addkid button, which, when the user clicks on the button a pop type window shows the form which has <strong>NAME , GENDER AND DOB</strong>. In the form action <code>javascript:insert()</code>. I am using ajax for the 1st time so I am not able to understand why it's not working. I guess it should redirect me to 4.php and in 4.php it will echo the values?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload