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 '
| NO |
Student ID |
Student Name |
Student Email |
student Address | '; foreach ($result as $row) {echo '
'; Echo '
| '. $row [' id ']. ' | '; Echo '
'. $row [' XID ']. ' | '; Echo '
'. $row [' name ']. ' | '; Echo '
'. $row [' email ']. ' | '; Echo '
'. $row [' address ']. ' | '; Echo '
'; } Echo '
';
}
?>
}
?>