PHP_CHILD Posted February 7, 2013 Share Posted February 7, 2013 i have a form. if user enter the data, the db table display. but i want the table to get displayed when the user logins for the first time. simple one but i can't get it how... aa.html <html> <body> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var age = document.getElementById('age').value; var wpm = document.getElementById('wpm').value; var sex = document.getElementById('sex').value; var name = document.getElementById('name').value; var queryString = "?age=" + age + "&wpm=" + wpm + "&sex=" + sex + "&name=" + name; $a=ajaxRequest.open("GET", "ss1.php" + queryString, true); ajaxRequest.send(null); } //--> </script> <form name='myForm'> Name:<input type='text' id='name' /> <br /> Age: <input type='text' id='age' /> <br /> WPM: <input type='text' id='wpm' /> <br /> Sex: <select id='sex'> <option value='m'>m</option> <option value='f'>f</option> </select> <input type='button' onclick='ajaxFunction()' value='Insert New row' /> </form> <div id='ajaxDiv'>Your result will display here</div> </body> </html> ss1.php $age = $_GET['age']; $sex = $_GET['sex']; $wpm = $_GET['wpm']; $name= $_GET['name']; // Escape User Input to help prevent SQL Injection $a=isset($_GET['age']) && $_GET['age']; $b=isset($_GET['sex']) && $_GET['sex']; $c=isset($_GET['wpm']) && $_GET['wpm']; $d=isset($_GET['name']) && $_GET['name']; $age = mysql_real_escape_string($age); $sex = mysql_real_escape_string($sex); $wpm = mysql_real_escape_string($wpm); $name = mysql_real_escape_string($name); //build query $query = "INSERT INTO `ajax_example`(`ae_name`, `ae_age`, `ae_sex`, `ae_wpm`) VALUES ('$name','$age','$sex','$wpm')"; $qry = mysql_query($query) or die(mysql_error()); $a="SELECT `ae_name`, `ae_age`, `ae_sex`, `ae_wpm` FROM `ajax_example`"; $qry_result=mysql_query($a) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Age</th>"; $display_string .= "<th>Sex</th>"; $display_string .= "<th>WPM</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[ae_name]</td>"; $display_string .= "<td>$row[ae_age]</td>"; $display_string .= "<td>$row[ae_sex]</td>"; $display_string .= "<td>$row[ae_wpm]</td>"; $display_string .= "</tr>"; } $display_string .= "</table>"; echo $display_string; ?> if u could tell me show good websites to practice javascript. woulg b gr8.. thank u in advances. Quote Link to comment https://forums.phpfreaks.com/topic/274140-php-javascript-beginner-update-mysql/ Share on other sites More sharing options...
Christian F. Posted February 7, 2013 Share Posted February 7, 2013 (edited) You have to add a field to the table, where you save a boolean that tells whether or not this is the first time the user has logged on. Set it to 0 (false) by default. Then, when the user logs in, retrieve the flag with the rest of the details. If it's set to 0 then show the form, and update the flag to read 1 (true) at the same time as you save the other details from the form. Edited February 7, 2013 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/274140-php-javascript-beginner-update-mysql/#findComment-1410735 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.