Re: $_SERVER['PHP_SELF']

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 9 Feb 2005 17:21:03 -0800 (PST), Patrick Roane
<fojomo@xxxxxxxxxxxxx> wrote:
> I'm trying to execute my php code from w/in the same
> page as my form. I've done this before, but recently
> i've been getting some parse errors.
> 
> Is there a certain way of writing the following so it
> works with my form?
> 
> For example, do I use:
> 
> action="<?php print $_SERVER['PHP_SELF']?>
> 
> or,
> 
> action="{' . $_SERVER['PHP_SELF'] . '}">
> 
> Currently, the error I get is:
> 
> Parse error: syntax error, unexpected '<' in
> c:\wamp\www\php_excercises\grabfile.php on line 13
> 
> My code is below:
> 
> <form enctype="multipart/form-data"
> name="frmUploadFile" action="<?PHP echo $me;?>">
> 
Error lies in these lines

> <?php
Your  PHP tag is start.
>    <form method="post" action="<?php print
but you write a normal html without a print or echo.
> $_SERVER['PHP_SELF']?>">
>    /*   action="{' . $_SERVER['PHP_SELF'] . '}">   */
> 
> ?>

it must be like this 
<?php
print "<form method='post' action='{$_SERVER['PHP_SELF']}'>";
 ?>

or 

print "<form method='post' action='"; // Note single quotes before
closing double quotes.
print $_SERVER['PHP_SELF'];
print "'>";

Remember once you have started a PHP tag you must use php things only .
Even if you want to write HTML then include it in  print or echo statements.

Zareef Ahmed 





> 
> <a href="http://www.devarticles.com";>
> 
> <img border="0"
> src="http://www.devarticles.com/dlogo.gif";>
> 
> </a>
> 
> <table border="0" cellpadding="0" cellspacing="0"
> bordercolor="#111111" width="100%">
> 
> <tr>
> 
> <td width="100%" bgcolor="#FF9900" height="22"
> colspan="2">
> 
> <p style="margin-left: 10"><b><font face="Verdana"
> size="2" color="#FFFFFF">
> 
> Upload a File</font></b></td>
> 
> </tr>
> 
> <tr>
> 
> <td width="100%" bgcolor="#FFE3BB" colspan="2">
> 
> <p style="margin-left: 10; margin-right: 10"><font
> face="Verdana" size="2">
> 
> <br>Please select a file from your local computer to
> upload to our web server
> 
> for saving in our database. This file can be of any
> type you like. Once you
> 
> have chosen a file, please click on the &quot;Upload
> this file&quot; button below.&nbsp;
> 
> &nbsp;<br>&nbsp;</font></td>
> 
> </tr>
> 
> <tr>
> 
> <td width="15%" bgcolor="#FFE3BB">
> 
> <p style="margin-left: 10"><font face="Verdana"
> size="2">
> 
> File Description:</font></td>
> 
> <td width="85%" bgcolor="#FFE3BB">
> 
> <input type="text" name="strDesc" size="20"
> maxlength="50"></td>
> 
> </tr>
> 
> <tr>
> 
> <td width="15%" bgcolor="#FFE3BB">
> 
> <p style="margin-left: 10"><font face="Verdana"
> size="2">File Location:</font></td>
> 
> <td width="85%" bgcolor="#FFE3BB">
> 
> <font face="Verdana" size="2">
> 
> <input type="file" name="fileUpload"
> size="20"></font></td>
> 
> </tr>
> 
> <tr>
> 
> <td width="33%" bgcolor="#FFE3BB">
> 
> <p style="margin-left: 10"><font face="Verdana"
> size="2">
> 
> <br>
> 
> <br>
> 
> &nbsp;</font></td>
> 
> <td width="67%" bgcolor="#FFE3BB">
> 
> <font face="Verdana" size="2">
> 
> <input type="submit" value="Upload this file"
> name="cmdSubmit"></font></td>
> 
> </tr>
> 
> </table>
> 
> </form>
> 
> <?php
> } else {
> // GrabFile.php: Takes the details
> 
> // of the new file posted as part
> 
> // of the form and adds it to the
> 
> // myBlobs table of our myFiles DB.
> 
> global $strDesc;
> 
> global $fileUpload;
> 
> global $fileUpload_name;
> 
> global $fileUpload_size;
> 
> global $fileUpload_type;
> 
> // Make sure both a description and
> 
> // file have been entered
> 
> if(empty($strDesc) || $fileUpload == "none")
> 
> die("You must enter both a description and file");
> 
> // Database connection variables
> 
> $dbServer = "localhost";
> 
> $dbDatabase = "myFiles";
> 
> $dbUser = "";
> 
> $dbPass = "";
> 
> $fileHandle = fopen($fileUpload, "r");
> 
> $fileContent = fread($fileHandle, $fileUpload_size);
> 
> $fileContent = addslashes($fileContent);
> 
> $sConn = mysql_connect($dbServer, $dbUser, $dbPass)
> 
> or die("Couldn't connect to database server");
> 
> $dConn = mysql_select_db($dbDatabase, $sConn)
> 
> or die("Couldn't connect to database $dbDatabase");
> 
> $dbQuery = "INSERT INTO myBlobs VALUES ";
> 
> $dbQuery .= "(0, '$strDesc', '$fileContent',
> '$fileUpload_type')";
> 
> mysql_query($dbQuery) or die("Couldn't add file to
> database");
> 
> 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>";
> 
> ?>
> </body>
> 
> </html>
> 
> =====
> Patrick Roane
> Web design and development
> www.franklin-band.com
> Fox River Grove, Il.
> 
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux