php-windows Digest 14 Feb 2005 02:45:17 -0000 Issue 2573
Topics (messages 25570 through 25574):
getting error after filling out form
25570 by: Patrick Roane
25571 by: Mikey
BLOBS problem
25572 by: Patrick Roane
code isn't parsing mysql ...
25573 by: Patrick Roane
fopen + wmv
25574 by: Rudi Starcevic
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
The php $_SERVER['PHP_SELF'] form comes up fine, I can
fill it out, but when I click 'submit' I get the
following error:
The requested URL
/php_excercises/{/php_excercises/schedule.php} was not
found on this server.
..and my database table is ignored. This was all
working just fine before and I don't remember changing
anything.
Here is my code:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Listing 13.1 Opening a Connection to a
Database</title>
</head>
<body>
<?php
if ( ! empty( $_REQUEST['sound'] )&&
! empty( $_REQUEST['equip'] )&&
! empty( $_REQUEST['food'] )&&
! empty( $_REQUEST['drink'] )&&
! empty( $_REQUEST['comp'] ) ){
// check user imput here!
$dberror = "";
$ret = add_to_database( $_REQUEST['sound'],
$_REQUEST['equip'],
$_REQUEST['food'],
$_REQUEST['drink'],
$_REQUEST['comp'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n";
} else {
print "Thank you very much<br />\n";
}
} else {
write_form();
}
function add_to_database( $sound, $equip, $food,
$drink, $comp, &$dberror ) {
$sound = mysql_real_escape_string( $sound );
$equip = mysql_real_escape_string( $equip );
$food = mysql_real_escape_string( $food );
$drink = mysql_real_escape_string( $drink );
$comp = mysql_real_escape_string( $comp );
$link = mysql_pconnect( "localhost", "", "" );
if ( ! $link ) {
$dberror = mysql_error();
return false;
}
if ( ! mysql_select_db( "schedule05", $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO specs( sound, equip, food,
drink, comp )
values('$sound', '$equip', '$food', '$drink',
'$comp' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}
return true;
}
function write_form() {
print '
<form method="post" action="{' .
$_SERVER['PHP_SELF'] . '}">
<p><input type="text" name="sound" />
Does venue have mixer?</p>
<p><input type="text" name="equip" />
Does venue have its own equipment?</p>
<p><input type="text" name="food" />
What kind of food deal?</p>
<p><input type="text" name="drink" />
What kind of drink deal?</p>
<p><input type="text" name="comp" />
What is our compensation?</p>
<p><input type="submit" value="submit!" /></p>
</form>
</FORM> ';
}
?>
</form>
</BODY>
</HTML>
=====
Patrick Roane
Web design and development
www.franklin-band.com
Fox River Grove, Il.
--- End Message ---
--- Begin Message ---
> The requested URL
> /php_excercises/{/php_excercises/schedule.php} was not found
> on this server.
Prolly because you are telling PHP to put the braces in for you:
> print '
> <form method="post" action="{' .
----------------------------------------^
> $_SERVER['PHP_SELF'] . '}">
--------------------------^
HTH,
Mikey
--- End Message ---
--- Begin Message ---
I am trying to load some jpgs etc. into mysql but my
code does not seem to want to communicate with the
database. I'm not even getting any (database, parse or
syntax) errors.
There has to be a simple explanation for this. Here is
my code.
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Listing 13.1 Opening a Connection to a
Database</title>
</head>
<body>
<?php
if ( ! empty( $_REQUEST['strDesc'] )&&
! empty( $_REQUEST['fileUpload'] ) ){
// check user input here!
$dberror = "";
$ret = add_to_database( $_REQUEST['strDesc'],
$_REQUEST['fileUpload'],
$_REQUEST['fileUpload_type'],
$_REQUEST['fileUpload_name'],
$_REQUEST['fileUpload_size'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n";
} else {
print "Thank you very much<br />\n";
}
} else {
write_form();
}
function add_to_database( $strDesc, $fileUpload,
$fileUpload_name, $fileUpload_size, $fileUpload_type,
&$dberror ) {
$strDesc = mysql_real_escape_string( $strDesc );
$fileUpload = mysql_real_escape_string(
$fileUpload );
$fileUpload_name = mysql_real_escape_string(
$fileUpload_name );
$fileUpload_size = mysql_real_escape_string(
$fileUpload_size );
$fileUpload_type = mysql_real_escape_string(
$fileUpload_type );
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$link = mysql_pconnect( "localhost", "", "" );
if ( ! $link ) {
$dberror = mysql_error();
return false;
}
if ( ! mysql_select_db( "myfiles", $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO myblobs( strDesc, fileUpload,
fileUpload_name, fileUpload_size, fileUpload_type )
values('$strDesc', '$fileUpload',
'$fileUpload_name', '$fileUpload_size',
'$fileUpload_type' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}
echo "<h1>File Uploaded</h1>";
echo "The details of the uploaded file are shown
below:<br><br>";
echo "<b>File name:</b> $fileUpload_name <br>";
echo "<b>File type:</b> $fileUpload_type <br>";
echo "<b>File size:</b> $fileUpload_size <br>";
echo "<b>Uploaded to:</b> $fileUpload <br><br>";
echo "<a href='uploadfile.php'>Add Another File</a>";
return true;
}
function write_form() {
print '
<form method="post" enctype="multipart/form-data"
name="frmUploadFile" action="{' . $_SERVER['PHP_SELF']
. '}">
<p><input type="text" name="strDesc" size="20"
maxlength="50" />
file Description:</p>
<p><input type="file" name="fileUpload" size="20" />
Choose a file</p>
<input type="submit" value="Upload this file"
name="Submit" /></p>
</form>
</FORM> ';
}
?>
</form>
</BODY>
</HTML>
=====
Patrick Roane
Web design and development
www.franklin-band.com
Fox River Grove, Il.
--- End Message ---
--- Begin Message ---
Can anyone take a look at my code to see why the mysql components are being
ignored?
-------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Listing 13.1 Opening a Connection to a Database</title>
</head>
<body>
<?php
global $strDesc;
global $fileUpload;
global $fileUpload_name;
global $fileUpload_size;
global $fileUpload_type;
if ( ! empty( $_REQUEST['strDesc'] )&&
! empty( $_REQUEST['fileUpload'] ) ){
// check user input here!
$dberror = "";
$ret = add_to_database( $_REQUEST['strDesc'],
$_REQUEST['fileUpload'], $_REQUEST['fileUpload_type'],
$_REQUEST['fileUpload_name'], $_REQUEST['fileUpload_size'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n";
} else {
echo "<h1>File Uploaded</h1>";
echo "The details of the uploaded file are shown below:<br><br>";
echo "<b>File name:</b> $fileUpload_name <br>";
echo "<b>File type:</b> $fileUpload_type <br>";
echo "<b>File size:</b> $fileUpload_size <br>";
echo "<b>Uploaded to:</b> $fileUpload <br><br>";
echo "<a href='uploadfile.php'>Add Another File</a>";
}
} else {
write_form();
}
function add_to_database( $strDesc, $fileUpload, $fileUpload_name,
$fileUpload_size, $fileUpload_type, &$dberror ) {
$strDesc = mysql_real_escape_string( $strDesc );
$fileUpload = mysql_real_escape_string( $fileUpload );
$fileUpload_name = mysql_real_escape_string( $fileUpload_name );
$fileUpload_size = mysql_real_escape_string( $fileUpload_size );
$fileUpload_type = mysql_real_escape_string( $fileUpload_type );
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$link = mysql_pconnect( "localhost", "", "" );
if ( ! $link ) {
$dberror = mysql_error();
return false;
}
if ( ! mysql_select_db( "myfiles", $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO myblobs( strDesc, fileUpload, fileUpload_name,
fileUpload_size, fileUpload_type )
values('$strDesc', '$fileUpload', '$fileUpload_name', '$fileUpload_size',
'$fileUpload_type' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}
return true;
}
function write_form() {
print '
<form method="post" enctype="multipart/form-data" name="frmUploadFile"
action="' . $_SERVER['PHP_SELF'] . '">
<p><input type="text" name="strDesc" size="20" maxlength="50" />
file Description:</p>
<p><input type="file" name="fileUpload" size="20" />
Choose a file</p>
<input type="submit" value="Upload this file" name="Submit" /></p>
</form>
</FORM> ';
}
?>
</form>
</BODY>
</HTML>
Patrick Roane
Web design and development
www.franklin-band.com
Fox River Grove, Il.
--- End Message ---
--- Begin Message ---
Hi,
I'm using fopen() and fpassthru()/feof() to read Windows Media Video,
.wmv, files of a Win2003 server with Apache and PHP.
The file is opened and downloaded OK but is somehow corrupted.
The Windows Media Player says the file is not the correct format.
Can you see something I am missing in my code?
@ini_set("zlib.output_compression", "Off");
@ignore_user_abort();
@set_time_limit(0);
header("Content-type: application/octet-stream\n");
header("Content-disposition: attachment; filename=\"$myMediaName\"\n");
header("Content-transfer-encoding: binary\n");
header("Content-length: $myMediaSize\n");
$fp=fopen($myMediaPath, "rb");
//fpassthru($fp);
/* fpassthru is apparantly a memory-hog. Use this instead */
while(!feof($fp))
{
$buf = fread($fp, 4096);
print $buf;
}
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
--- End Message ---