如何将客户端表单中的数据添加到数据库中的不同表中?
我的情况是这样的,我有三种形式的客户端,第一种是用于书籍项目(精装本、杂志等),第二种是用于音乐项目(CD、磁带等),第三种是用于电影项目(DVD、VHS 等) .)。
用户应该能够在任何表单中输入详细信息,然后数据应该填充到数据库中的正确表中。
任何想法家伙或脚本随时可用?我需要它是可扩展的,因此它应该处理多个请求而不会减慢或导致许多错误(我不介意调试一些:))。我还必须考虑谁发布了使系统可扩展的内容。
哦,我是前端设计师,而不是 exp 核心软件应用程序网络程序员工程师编码器。
设置:PHP mySQL JS HTML
欢迎大家帮忙。
我很抱歉,伙计们!书籍的当前代码如下,音乐和电影的代码相同:
<?php
//Start session
session_start();
//Include database connection details
require_once('../config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$isbn = clean($_POST['isbn']);
$bookTitle = clean($_POST['bookTitle']);
$author = clean($_POST['author']);
$genre = clean($_POST['genre']);
$year= clean($_POST['year']);
//Input Validations
if($isbn == '') {
$errmsg_arr[] = 'ISBN missing';
$errflag = true;
}
if($bookTitle == '') {
$errmsg_arr[] = 'Book Title missing';
$errflag = true;
}
if($author == '') {
$errmsg_arr[] = 'author missing';
$errflag = true;
}
if($genre == '') {
$errmsg_arr[] = 'Genre missing';
$errflag = true;
}
if($year == '') {
$errmsg_arr[] = 'Year missing';
$errflag = true;
}
//Check for duplicate login ID
if($isbn != '') {
$qry = "SELECT * FROM books WHERE isbn='$isbn'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'Book and ISBN ID already in system';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die('Query Failed: ' . mysql_error());
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
die('Query Failed: ' . mysql_error());
header("location: addMedia.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO books(isbn, title, author, genre, year) VALUES('$isbn','$bookTitle','$author','$genre','$year')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: bookAdded.php");
exit();
}else {
die('Query Failed: ' . mysql_error());
} ?>