Using JS to call the background PHP data processing source code

Source: Internet
Author: User
Tags date form post header sql mysql php code query strlen
js| Background | Data The method is already in the past, where the key is also from the altar, I just digested it and then wrote it back more fully. The announcement is just a hope that more beginners can learn something from it. If you have any comments on the code, you can leave a message, but please do not do personal attacks, I am a bird can only write this thing, every veteran has such a process.

In view of the time issue, the submission section of the code uses a traditional form post, and if you like, you can add the corresponding script according to the load process, but it seems only
can use get. Listen to the fact that XML can actually be really refreshing, and if anyone has a wish to lend a look.

Thanks to the QQ group in the Blue Sword Snow Fox and Shelly Water in JS to give help, but also the novice can write their own functions of the code posted to everyone together to learn research.

Last attached demo address: http://lfox0002.dns0755.net/text_input.php please enjoy the hack of other people's robots, and attach a demo to let friends know the code faster.


Input.php[html] accepts user input data.


PHP Code:--------------------------------------------------------------------------------

<?php
/*
Affirmed
------------------------------
The demo file describes in detail the method of using js+php to do similar refreshing read writes to a database

February 14, 2004
by L.fox
*/

Header ("Cache-control:no-store, no-cache,must-revalidate"); These two lines can be canceled to save the file as HTML
echo $_post["name1"]; I did it for #123.
?>
<meta http-equiv= "Content-type" content= "text/html; charset=?????? " >
<title> retrieve data from MySQL to edit and save according to number [demo]</title>
<script language= "JavaScript" id= "LOADDATASRC" ></script>
<style>
Body {
font-family: "Verdana", "Arial", "Helvetica", "Sans-serif";
font-size:12px;
line-height:17px;
Scrollbar-base-color: #BBBBBB;
Scrollbar-shadow-color: #BBBBBB;
Scrollbar-highlight-color: #FFFFFF;
Scrollbar-3dlight-color: #000000;
Scrollbar-darkshadow-color: #000000;
Scrollbar-arrow-color: #FFFFFF;
}
Table {
border:0;
font-size:12px;
Cursor:default;
}
TD {
Text-align:left;
height:20;
}
Input {
width:100;
height:18;
border:0px solid #666666;
Text-align:left;
}
</style>
<script>
var objinput = null;
var objtd = null;
var num =null;
function Autoedit (obj,id)
{
if (objinput = null)
{
OBJTD = obj;
obj.innerhtml = "<input size=\" 10\ "maxlength=\" 10\ "type=\" text\ "value=\" "+ Obj.innertext +" \ "
Id=\ "objinput\" onblur=\ "objtd.innertext=this.value; LoadData (objtd.innertext,num); objinput=null;\ "style=\" overflow:
Visible;border:none;background-color: #EFEFEF ">";
Objinput = document.getElementById ("Objinput");
Objinput.focus ();
}
}

function LoadData (loadindex,loadobj)
{
var loadfilename= "load.php?action=" + Loadindex + "&num=" + loadobj;
document.getElementById ("loaddatasrc"). src = loadfilename;
}
function Outputdata (obj)
{
if (form1.num1.value.length<1) {alert ("Please enter quantity 1");
if (form1.num2.value.length<1) {alert ("Please enter quantity 2");
if (document.getElementById ("name1"). innerhtml.length<1) {alert ("name1 null"); return false;}
if (document.getElementById ("name2"). innerhtml.length<1) {alert ("name2 null"); return false;}
Obj.innerhtml= "<input type=\" hidden\ "name=\" name1\ "value=\" "+ document.getElementById (" name1 "). InnerHTML +" \ " > ";
obj.innerhtml+= "<input type=\" hidden\ "name=\" name2\ "value=\" "+ document.getElementById (" name2 "). InnerHTML +" \ " > ";
obj.innerhtml+= "<input type=\" hidden\ "name=\" type1\ "value=\" "+ document.getElementById (" Type1 "). InnerHTML +" \ " > ";
obj.innerhtml+= "<input type=\" hidden\ "name=\" type2\ "value=\" "+ document.getElementById (" type2 "). InnerHTML +" \ " > ";
obj.innerhtml+= "<input type=\" hidden\ "name=\" date1\ "value=\" "+ document.getElementById (" Date1 "). InnerHTML +" \ " > ";
obj.innerhtml+= "<input type=\" hidden\ "name=\" date2\ "value=\" "+ document.getElementById (" Date2 "). InnerHTML +" \ " > ";
Obj.innerhtml+=form1.submit ();
}
function PostData ()
{
Form1.submit ();
}
</script>
<body>
<form name= "Form1" method= "Post" action= "Load.php?action=outputdata" >
<table width= "cellpadding=" 0 "cellspacing=" 1 "align=" center "bgcolor=" #999999 ">
<tr bgcolor= "#EFEFEF" >
&LT;TD onclick= "Autoedit (this,num=1)" style= "Width:200px;overflow:visible;word-break:break-all"; ><div></div></td>
&LT;TD onclick= "Autoedit (this,num=2)" style= "Width:200px;overflow:visible;word-break:break-all"; ><div></div></td>
</tr>
<tr bgcolor= "#EFEFEF" >
<td><div id= "name1" style= "Width:200px;overflow:visible;word-break:break-all;" >a</div></td>
<td><div id= "name2" style= "Width:200px;overflow:visible;word-break:break-all;" >b</div></td>
</tr>
<tr bgcolor= "#EFEFEF" >
<td><div id= "type1" style= "Width:200px;overflow:visible;word-break:break-all;" >a</div></td>
<td><div id= "type2" style= "Width:200px;overflow:visible;word-break:break-all;" >b</div></td>
</tr>
<tr bgcolor= "#EFEFEF" >
<td><div id= "Date1" style= "Width:200px;overflow:visible;word-break:break-all;" ></div></td>
<td><div id= "Date2" style= "Width:200px;overflow:visible;word-break:break-all;" ></div></td>
</tr>
<tr bgcolor= "#EFEFEF" >
<td><div><input type= "text" name= "NUM1" "value=" "></div></td>
<td><div><input type= "text" name= "num2" "value=" "></div></td>
</tr>
<div id= "Outputdata" ><a href= "#" onclick= "Java Script:outputdata (this);" > Output </a></div></form>
</body>
--------------------------------------------------------------------------------

load.php

PHP Code:--------------------------------------------------------------------------------

<?php
Header ("Cache-control:no-store, no-cache,must-revalidate");
Include ("Obj/financial_obj_free.inc"); The content in this file is a statement that connects to MySQL.
$str =$_get["Action"];
$num =$_get["num"];
if ($str = = "Outputdata") outputdata ();
Else
{
Linkdata ("financial", 1);
$sql = "SELECT * from table where id= ' $str '";
if ($query =mysql_query ($sql))
{
$temdata =mysql_fetch_row ($query); See if it is empty, if it is attached to the value to avoid JS error.
if (strlen ($temdata [2]) <1| | $temdata [2]== "] $temdata [2]=];
$temdata [2]=htmlspecialchars ($temdata [2]);
if (strlen ($temdata [3]) <1| | $temdata [3]== "] $temdata [3]=];
$temdata [3]=htmlspecialchars ($temdata [3]);
if (strlen ($temdata [5]) <1| | $temdata [5]== "] $temdata [5]=];
$temdata [5]=htmlspecialchars ($temdata [5]);
}
Else
{
$temdata [2]= $temdata [3]= $temdata [5]= query failed];
}
Switch ($num)//This is mainly used for inspection from the first few columns (lines) passed over. Note that the value of the variable should correspond to the ID value of input. Otherwise, an error
{
Case 1:
$diva = "Name1";
$DIVB = "Type1";
$DIVC = "Date1";
Break
Case 2:
$diva = "Name2";
$DIVB = "type2";
$DIVC = "Date2";
Break
Default
$diva = "Name1";
$DIVB = "Type1";
$DIVC = "Date1";
Break
}
Determine node, output $TEMDATA[X] to node $divx;
echo "document.getElementById" (". $diva."). Innerhtml= ' ". $temdata [2]." '; ";
echo "document.getElementById" (". $divb."). Innerhtml= ' ". $temdata [3]." '; ";
echo "document.getElementById" (". $divc."). Innerhtml= ' ". $temdata [5]." '; ";
}


function Outputdata ()//This can be written into the database if you change it to a SQL statement
{
echo "Output data as follows, change to SQL statement and then save it";
echo "Number 1=". $_post["Name1"]. " <br> ";
echo "Number 2=". $_post["Name2"]. " <br> ";
echo "Name 1=". $_post["Type1". " <br> ";
echo "Name 2=". $_post["type2". " <br> ";
echo "Date 1=". $_post["Date1". " <br> ";
echo "Date 2=". $_post["Date2". " <br> ";
echo "Quantity 1=". $_post["NUM1"]. " <br> ";
echo "Quantity 2=". $_post["num2"]. " <br> ";
echo "<a href=\" Text_input.php\ "> Return </a>";
}
?>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.