javascript - Get variable data from database and display in PHP -


i want pass value inputbox data in php, , display php sql not recognize

<form name="form1"/> <input type="text" name="code1" value="d50" size="7" maxlength="10" onblur="chkidpro(this.value,'provider1');" /> <input type="text" name="code2" value="" size="7" maxlength="10"/> <form/>  <script type="text/javascript">  var jvalue = form1.code1.value;  <?php $abc = "<script>document.write(jvalue)</script>"?>   </script>  <?php  $con = mysql_connect("localhost","abc_one","pass"); mysql_select_db("abc_one", $con);  echo $abc;// print d50  $c = 'd50';  //$c = $abc;  $result2 = mysql_query("select * tblmycode code='$c';");  $tab = mysql_fetch_array($result2);  if($result2 === false)  { die("database error"); }  if(mysql_num_rows($result2) == 0)  { die("no record found"); } 

echo $abc; print d50

if replace $c = $abc; no record found

if replace $c = 'd50'; record available

the code show working @ server side so:

 <?php $abc = "<script>document.write(jvalue)</script>"?>  

sets $abc "<script>document.write(jvalue)</script>"

the javascript wrote there work on client side, browser. not mix them...

ok clarify happening:

this text in server in php file when invoked:

line                                       action on server <form name="form1"/>                       //->sent client <input type="text" name="code1" value="d50"//->sent client <input type="text" name="code2" value=""   //->sent client <form/>                                    //->sent client  <script type="text/javascript">            //->sent client var jvalue = form1.code1.value;            //->sent client(will run on client)   <?php                                      //->php takes control on server   $abc = "<script>document.write(jvalue)</script>"; //php runs on server   //php sets $abc "<script>document.write(jvalue)</script>" on server...  //php not process javascript, php sees text...  ?>                                         //->ends php control  </script>                                  //->sent client  <?php                                      //->php takes control on server again  $con = mysql_connect("localhost","abc_one","pass"); // php runs on server mysql_select_db("abc_one", $con);                   // php runs on server  echo $abc;                                          // php echoes $abc 

meaning line containing

<script>document.write(jvalue)</script>  

is sent client.

it written client document...

it evaluated on client computer not on server.

and happen in near future, not yet....

why see d50 on browser ? lets have future :

so happens when client (browser) parses javascripts?

browser execute

var jvalue = form1.code1.value; 

line , set jvalue d50 , of course when browser encounters

<script>document.write(jvalue)</script> 

it run , show value of jvalue on client d50..

all happen on client computer not on server.

so happen in near future, not yet....

now php file

//$c = 'd50';    // lets ignore     $c = $abc;                                    // php runs on server.   // guess $c '<script>document.write(jvalue)</script>'       // php tries run this:  $result2 = mysql_query("select * tblmycode code='$c';"); 

now query became interesting :

select * tblmycode code='<script>document.write(jvalue)</script>'; 

i hope understand happening...

ps: mysql interface deprecated use mysqli or pdo please...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -