PHP receives post data and writes MySQL related issues

Source: Internet
Author: User
PHP receives post data and writes MySQL problem
Ask the Expert answer: How does PHP receive the TXT text content of the remote post and write to the MySQL database at the same time? Please complete the code! Fit to add points!
TXT text content field format:
Student ID, student name, student email, student address

------to solve the idea----------------------
Data sheet:

CREATE TABLE ' Student ' (
' id ' int (ten) unsigned not NULL auto_increment,
' XID ' varchar (not NULL),
' Name ' varchar (not NULL),
' Email ' varchar (+) not NULL,
' Address ' varchar (+) not NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT charset=latin1 auto_increment=1;


postdemo.php

Connecting to a database
[Email protected]_connect ("Database IP", "account Number", "password") or Die (Mysql_error ());
@mysql_select_db (' database name ', $conn) or Die (Mysql_error ());

$action = Isset ($_request[' action ')? $_request[' action ']: ';

if ($action = = ' Add ') {
$xid = isset ($_post[' XID ')? Mysql_escape_string ($_post[' XID '): ';
$name = isset ($_post[' name ')? Mysql_escape_string ($_post[' name '): ';
$email = isset ($_post[' email ')? mysql_escape_string ($_post[' email '): ';
$address = Isset ($_post[' address ')? Mysql_escape_string ($_post[' address '): ';

if ($xid = = "
------to solve the idea----------------------
$name = = "
------to solve the idea----------------------
$email = = "
------to solve the idea----------------------
$address = = ") {
echo ' please input data ';
Exit ();
}

$sqlstr = "INSERT into student (xid,name,email,address) VALUES ('". $xid. "', '". $name. "', '". $email. "', '". $address. "')";
mysql_query ($sqlstr) or Die (Mysql_error ());

Header (' location:postdemo.php ');

}else{
?>




<title>Demo</title>





$SQLSTR = "SELECT * from student order by id";
$query = mysql_query ($sqlstr) or Die (Mysql_error ());
$result = Array ();
while ($thread =mysql_fetch_assoc ($query)) {
$result [] = $thread;
}

if ($result) {
Echo '










'; Echo ' '; foreach ($result as $row) {echo ' '; Echo ' '; Echo ' '; Echo ' '; Echo ' '; Echo ' '; Echo ' '; } Echo '
NO Student ID Student Name Student Email student Address
'. $row [' id ']. ''. $row [' XID ']. ''. $row [' name ']. ''. $row [' email ']. ''. $row [' address ']. '
';
}

?>



}
?>
  • 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.