Using JS to invoke the background PHP data processing source code _php
Source: Internet
Author: User
The method has been part of the time method, where the key is also from the altar, I just digest it and then re-write a more comprehensive out. The announcement is that more novices can learn something from the middle school. If you have any comments on the code, please leave a message, but do not attack personally, I am a vegetable bird can only write this thing, every veteran has this process.
In view of the time issue, the Code submission section uses the traditional form post, and if you prefer, you can add the corresponding script according to the load process, but it seems only
I can use get. Listen to the fact that XML can really not be refreshed, if anyone has the hope to borrow to see.
In this thank QQ group of Blue Sword Snow Fox and Shelly Water on JS to give help, also the novice can write their own function code to paste out to everyone together to learn research.
The final enclosed is the demo address: http://lfox0002.dns0755.net/text_input.php Please enjoy your friends who are hack others, with a demo that allows friends to get to know the code faster.
/*
Affirmed
------------------------------
This demo file describes in detail the method of using js+php to read and write to a database in a similar way
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 the #123, and it was convenient to try.
?>
<title>Extract data from MySQL according to the number to edit and save back [demo]</title>
Header ("Cache-control:no-store, no-cache,must-revalidate");
Include ("Obj/financial_obj_free.inc"); The contents of this file are the statements that connect 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 value lest JS error.
if (strlen ($temdata [2]) <1| | $temdata [2]== "") $temdata [2]= "Empty";
$temdata [2]=htmlspecialchars ($temdata [2]);
if (strlen ($temdata [3]) <1| | $temdata [3]== "") $temdata [3]= "Empty";
$temdata [3]=htmlspecialchars ($temdata [3]);
if (strlen ($temdata [5]) <1| | $temdata [5]== "") $temdata [5]= "Empty";
$temdata [5]=htmlspecialchars ($temdata [5]);
}
Else
{
$temdata [2]= $temdata [3]= $temdata [5]=] "Query failed";
}
Switch ($num)//This is mainly used to check the number of columns (lines) passed over. Note that the value of the variable corresponds to the ID value of input. Otherwise 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 a database if you change it to a SQL statement
{
echo "Output data as follows, change to SQL statement and then can be saved";
echo "Number 1=". $_post["Name1"]. "
";
echo "Number 2=". $_post["Name2"]. "
";
echo "Name 1=". $_post["Type1"]. "
";
echo "Name 2=". $_post["Type2"]. "
";
echo "Date 1=". $_post["Date1"]. "
";
echo "Date 2=". $_post["Date2"]. "
";
echo "Quantity 1=". $_post["NUM1"]. "
";
echo "Quantity 2=". $_post["num2"]. "
";
echo "Back";
}
?>
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