gtwaja Posted July 13, 2007 Share Posted July 13, 2007 Dear all, below is my code which I'm trying to pass the value g into the mysql query but it won't display the name from the table user_track. I'm getting no anwser from this query. Is my syntax correct or is there something wrong here. <script language="JavaScript"> var g = "750802-12-5271"; var a1 = '<?php echo include "open_db.inc"; ?>'; var b1 = '<?php echo $sqlx ="SELECT * from user_track where ic = 'g' "; ?>'; var c1 = '<?php echo $sql_resultx=mysql_query($sqlx,$connection) or die ("Could not execute query"); ?>'; var d1 = '<?php echo $row=mysql_fetch_array($sql_resultx) ?>'; var ee1 = '<?php echo $logout_ = $row["name"]; ?>'; var g1 = '<?php echo mysql_free_result($sql_resultx); ?>'; var h1 = '<?php echo mysql_close($connection); ?>'; var name_login = ee1; document.write("<br>Name Login: " + name_login); </script> Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 13, 2007 Share Posted July 13, 2007 why are you using java script? You're printing echo statements from a client-interpreted language which means the code has been parsed by the PHP engine, then downloaded and then you're trying to parse it on the local machine after download - that won't work. just do this: <?php $g='750802-12-5271'; include "open_db.inc"; $sqlx ="SELECT * from user_track where ic = 'g' "; $sql_resultx=mysql_query($sqlx,$connection) or die ("Could not execute query"); $row=mysql_fetch_array($sql_resultx); $logout_ = $row["name"]; mysql_free_result($sql_resultx); mysql_close($connection); echo 'Name Login: '.$logout_; I think that's what you need. Quote Link to comment Share on other sites More sharing options...
gtwaja Posted July 13, 2007 Author Share Posted July 13, 2007 gerkintrigg , thanx for your help...I should have explained a bit more details...my mistake..ok here it is...what I'm trying to do is that when the user type something in a textfield (the event i'm using onblur), it will automatically upload the data from mysql in other textfield. Thats what I'm trying to do with this code...But the funny thing is that when I do not use the 'where ic = 'g' ' it will get the data from the mysql but of course only 1 data...is there any ways on how to achieve this task I mentioned just now? Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 gerkintrigg , thanx for your help...I should have explained a bit more details...my mistake..ok here it is...what I'm trying to do is that when the user type something in a textfield (the event i'm using onblur), it will automatically upload the data from mysql in other textfield. Thats what I'm trying to do with this code...But the funny thing is that when I do not use the 'where ic = 'g' ' it will get the data from the mysql but of course only 1 data...is there any ways on how to achieve this task I mentioned just now? PHP is a preprocessor, you can't process PHP after the page is loaded. If I understand what you're trying to do correctly, you'll have to use AJAX to do a query whenever the textbox loses focus. edit: function getpage(page,div) { var xmlhttp /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp=false; } } @else xmlhttp=false @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } } if (!xmlhttp && window.createRequest) { try { xmlhttp = window.createRequest(); } catch (e) { xmlhttp=false; } } var url=page; xmlhttp.open("GET",url,true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { document.getElementById(div).value = xmlhttp.responseText; } } xmlhttp.send(null); } Have that function included on your page (it's Javascript) then when you want to update the other textbox you can do: <input type="text" id="textbox1" value="ducks"> getpage("page.php?query="+document.getElementById("textbox1").value,"textbox2"); <input type="text" id="textbox2"> This will query page.php and make textbox2 display the result. In the code above, it would go to "page.php?query=ducks" and set the value of "textbox2" to the result. And if I misunderstood your question, I'm an idiot. Quote Link to comment Share on other sites More sharing options...
gtwaja Posted July 13, 2007 Author Share Posted July 13, 2007 infid3l ....thanx so much man....I'm going to explore this AJAX thing...I'll get back to you all...... Quote Link to comment 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.