<!doctype html>
<?php
mysql_connect("127.0.0.1","root@localhost","");
mysql_select_db("reco");
if(isset($_POST['submit'])) {
$soundcard_title = $_FILES['file']['name'];
$upload_tmp = $_FILES['file']['tmp_name'];
$upload_type = $_FILES['file']['type'];
$upload_name = preg_replace("#^a-z0-9.#i","", $soundcard_title);
if(!$soundcard_title) {
echo "No file selected";
} else{
move_uploaded_file( $upload_tmp, "soundcards/".$soundcard_title);
echo "<br />".$soundcard_title." has been uploaded";
}
$path= "http://127.0.0.1/upload-playback/soundcards/$soundcard_title";
$query = "INSERT INTO 'soundcards' VALUE('','','$soundcard_title','$path','','','')";
$query1 = mysql_query($query);
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Upload screen</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload_screen.php" method="post">
Browse:<br>
<input name="file" type="file" size="80"> <br>
<input type="submit" name="submit" id="upload_btn" value="Upload">
</form>
</body>
</html>
我想使用mysql数据库在php中创建一个简单的上传回放。因为我用xampp来创建apache服务器。 现在我可以将文件上传到指定的文件夹,但是mysql数据库不会更新与上传文件相关的条目。请注意,我以后无法播放文件。
我的数据库架构:
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jan 03, 2017 at 08:49 AM
-- Server version: 10.1.13-MariaDB
-- PHP Version: 5.6.23
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `reco`
--
-- --------------------------------------------------------
--
-- Table structure for table `soundcards`
--
CREATE TABLE `soundcards` (
`s_id` int(10) NOT NULL,
`u_id` int(11) NOT NULL,
`soundcard_title` varchar(20) NOT NULL,
`path` varchar(100) NOT NULL,
`date-time` varchar(20) NOT NULL,
`no_plays` int(11) NOT NULL,
`no_reco` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`u_id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`username` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `soundcards`
--
ALTER TABLE `soundcards`
ADD PRIMARY KEY (`s_id`);
--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`u_id`),
ADD UNIQUE KEY `username` (`username`),
ADD UNIQUE KEY `email` (`email`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `soundcards`
--
ALTER TABLE `soundcards`
MODIFY `s_id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `user`
--
ALTER TABLE `user`
MODIFY `u_id` int(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
答案 0 :(得分:0)
我认为你的sql以错误的格式编写,insert的格式应该像
let ProtoBuf = protobuf;
let Message;
let messageFile = ProtoBuf.load('./message.proto', (err, root) => {
Message = root.lookup('message.Message');
console.log("Built Message: ",Message);
loadMessage();
});
let loadMessage = () => {
axios.get('/api/messages', {responseType: 'arraybuffer'})
.then((response) => {
console.log('Response from server: ', response);
let message = Message.decode(response.data);
console.log('Decoded Message ', message);
document.getElementById('content').innerHTML = JSON.stringify(message, null, 2)
})
.catch((error) => {
console.log("Error while getting messages, ",error)
})
};
答案 1 :(得分:0)
<!doctype html>
<?php
mysql_connect("127.0.0.1","root@localhost","");
mysql_select_db("reco");
if(isset($_POST['submit'])){
$soundcard_title = $_FILES['file']['name'];
$upload_tmp = $_FILES['file']['tmp_name'];
$upload_type = $_FILES['file']['type'];
$upload_name = preg_replace("#^a-z0-9.#i","", $soundcard_title);
if(!$soundcard_title){
echo "No file selected";
}
else{
move_uploaded_file( $upload_tmp, "soundcards/".$soundcard_title);
echo "<br />".$soundcard_title." has been uploaded";
}
$path= "http://127.0.0.1/upload-playback/soundcards/$soundcard_title";
$query = "INSERT INTO 'soundcards' VALUES('','$soundcard_title','$path','','','')";
$query1 = mysql_query($query);
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Upload screen</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload_screen.php" method="post">
Browse:<br>
<input name="file" type="file" size="80"> <br>
<input type="submit" name="submit" id="upload_btn" value="Upload">
</form>
</body>
</html>
答案 2 :(得分:0)
插入查询中出现错误:
$path= "http://127.0.0.1/upload-playback/soundcards/$soundcard_title";
$query = "INSERT INTO 'soundcards' VALUE('','','$soundcard_title','$path','','','')";
$query1 = mysql_query($query);
<强> 解决方案: 强>
$query = "INSERT INTO 'soundcards' **VALUES**('','','$soundcard_title','$path','','','')";
$query1 = mysql_query($query) or die('Error is='.mysql_error());
您使用的是VALUE而不是VALUES。