Jump to content

Help ...Serious problem....


gtwaja

Recommended Posts

 

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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.