Re: Upload a file
Posted: Sun Nov 16, 2008 6:42 am
But I still get Errory: QUery Failed for the upload script....
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
mysql_query($query) or die('Error, query failed');Code: Select all
mysql_query($query) or die('Error: ' . mysql_error());Those characters are unreadble.....You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '����O�o�Ϥ�v� d� _�R�2\�N555555���p��B����'�����������?�笫Q�����?n�'�' at line 1
Are you sure the column type is blob for binary data?Aravinthan wrote:Ok this is what I get:Those characters are unreadble.....You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '����O�o�Ϥ�v� d� _�R�2\�N555555���p��B����'�����������?�笫Q�����?n�'�' at line 1
Code: Select all
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
http://php.net/mysql_real_escape_stringAravinthan wrote:I dont get it Syntac.... where to pu tthe mysql espace...
hmm, maybe that is it.If binary data is to be inserted, this function must be used.
Code: Select all
$link = mysql_connect ("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("aoe3clan_division1") or die(mysql_error());
$gameid = $_POST['gameid'];
$player1 = $_POST['player1'];
$player2 = $_POST['player2'];
$winner = $_POST['winner'];
$fileName= $player1 . ' vs ' . $player2 . ' on ' . $map;
$tmpName = mysql_real_escape_string($_FILES['uploaded_file']['tmp_name'], $Link);
$fileSize = mysql_real_escape_string($_FILES['uploaded_file']['size'], $Link);
$fileType = mysql_real_escape_string($_FILES['uploaded_file']['type'], $Link);
$sql="SELECT COUNT(*) AS count
FROM games
WHERE gameid='$gameid'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
if ($row['count']>0){
echo "There is already a game with this id. <a href='http://www.aoe3clan.com'>Home</a>";
}
else {
mysql_query("INSERT INTO games (gameid, player1, player2, winner, map) VALUES ('$gameid', '$player1', '$player2', '$winner', '$map')") or die(mysql_error());
print "Game $gameid has been successfully inserted into the database. Details:</br>GameId: $gameid</br> Player1: $player1</br> Player2: $player2</br> Winner:$winner</br> Map:$map</br>";
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
fclose($fp);
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error: ' . mysql_error());
include 'library/closedb.php';
echo "File $fileName uploaded<br>";
echo $size;
echo $type;
Code: Select all
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
fclose($fp);
include 'library/config.php';
include 'library/opendb.php';
$content1 = mysql_real_escape_string($content, $Link);
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content1')";
mysql_query($query) or die('Error: ' . mysql_error());
include 'library/closedb.php';
echo "File $fileName uploaded<br>";