|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
difficulty with tutorial...
i've been trying to work with this tutorial but seem to be encountering some problems i.e. i'm new at php and mysql and so really can't work out why this is not working - sorry this excuse is really pathetic but i need to get something up in a hurry and also thought this would be an easy enough way for me to work out how to get the whole thing working and then later concerntrate on writing code...
URL this is the bit that is causing me grief... If you need to change any of these options, you can do so in PHP's configuration file. Anyhow, let's get back to our grabfile.php script. Create a new file named grabfile.php and paste each line of code shown below into it. We will run through the code line by line: <?php // 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; We start by declaring five global variables. When we pass any form values to a PHP script, PHP automatically makes the name of that element available to us as a global variable. So, for example, if I have a form element like this: <input type="text" name="myName" value="Mitchell Harper"> ... then if I posted this form to a PHP script using the post method, PHP would automatically create a variable named $myName, containing the value "Mitchell Harper". Form values are also stored in arrays, depending on the method used to post the form (get/post). For forms posted using the get method, they are stored in the associative array, $HTTP_GET_VARS, so I would access my form element like this: echo $HTTP_GET_VARS["myName"]; For forms posted using the post method, that forms elements are stored in the $HTTP_POST_VARS associative array: echo $HTTP_POST_VARS["myName"]; it just seems that the explanation is a bit brief and well confusing...this is what i have been playing with (my database is pics and my table is reunion - hmm, i wonder what that's about you say...) <?php // 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; echo $HTTP_POST_VARS["$strDesc"]; echo $HTTP_POST_VARS["$fileUpload"]; //echo $HTTP_POST_VARS["fileUpload"]; //echo $HTTP_POST_VARS["fileUpload"]; //echo $HTTP_POST_VARS["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 = "root"; $dbUser = "admin"; $dbPass = "password"; $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 reunion 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>"; ?> and these are my errors - somehow i don't think i'm connecting to the database correctly - do i need to do anything with odbc like in asp? i'm using IIS - i think i am missing the point somewhere. any help would be greatly appreciated. Notice: Undefined index: in d:\inetpub\wwwroot\reunion\grabfile.php on line 15 Notice: Undefined index: in d:\inetpub\wwwroot\reunion\grabfile.php on line 16 Warning: fopen("", "r") - No such file or directory in d:\inetpub\wwwroot\reunion\grabfile.php on line 32 Warning: fread(): supplied argument is not a valid File-Handle resource in d:\inetpub\wwwroot\reunion\grabfile.php on line 33 Warning: Access denied for user: 'admin@localhost' (Using password: YES) in d:\inetpub\wwwroot\reunion\grabfile.php on line 36 Warning: MySQL Connection Failed: Access denied for user: 'admin@localhost' (Using password: YES) in d:\inetpub\wwwroot\reunion\grabfile.php on line 36 Couldn't connect to database server ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > difficulty with tutorial... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|