+ Reply to Thread
Page 4 of 9 FirstFirst ... 2 3 4 5 6 ... LastLast
Results 61 to 80 of 165

Thread: HTML Website help     submit to reddit submit to twitter

  1. #61
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Corrderio View Post
    Oh whoops, misreead that.

    The first issue I see is Values needs to be plural, also you need to use the variables you created above. You want your Values clause to look something like:


    Code:
    VALUES ('$val1', '$val2', '$val3')"
    After that, all you really did was create a string. Now you need to run the query with that string on your SQLite DB like so:

    Code:
    $ok = sqlite_exec($dir, $sql);
    if (!$ok) die("Cannot execute statement.");
    Roughly this?
    Code:
    			<form action = "database.php" method = "post">
    				Add a Game to the database:<br>
    				<!-- Image place holder -->
    				Title: <input type="Text" name="title"><br>
    				Console:
    				<select name = "console">
    					<option value ="Nintendo"> Nintendo </option>
    					<option value ="Super Nintendo"> Super Nintendo </option>
    					<option value ="Nintendo 64"> Nintendo 64 </option>
    					<option value ="Game Cube"> Game Cube </option>
    					<Option value ="Playstation"> Playstation </option>
    					<option Value ="Playstation2"> Playstaiton 2 </option>
    					<option value ="Xbox"> Xbox </option>
    				</select><br>
    				Genre:
    				<select name= "genre">
    					<option value="Action"> Action </option>
    					<option value="Beatup"> Beat'em Up </option>
    					<option value="Platform"> Platformer </option>
    					<option value="shooter"> Shooter </option>
    					<option value="Adventure"> Adventure </option>
    					<option value="rpg"> Role-Playing </option>
    					<option value="Sim"> Simulation </option>
    					<option value="strategy"> Strategy </option>
    					<option value="Sports"> Sports </option>
    				</select><br>				
    				Publisher:
    				<select name = "publisher">
    					<option value="Capcom">Capcom </option>
    					<option value="KOEI">KOEI</option>
    					<option value ="Rare">Rare</option>
    					<option value="Snk">SNK</option>
    					<option value="SunSoft">SunSoft </option>
    				</select><br>
    				Release Year: <input type="Text" name="releaseYear"><br>
    				Rarity:
    				<select name= "rarity">
    					<option value="Common"> Common </option>
    					<option value="Uncommon"> Uncommon </option>
    					<option value="Rare"> Rare </option>
    					<option value="veryRare"> Very Rare </option>
    					<option value="SuperRare"> Super Rare </option>
    					<option value="Ultrarare"> Ultra Rare </option>
    				</select><br>
    				<input type = "submit" value = "Submit" name = "gameSubmit" />
    				<?php
    					if (empty($_POST)){
    				
    					}
    					else
    					{
    						 $title = $_REQUEST["title"];
    						 $console = $_REQUEST["console"];
    						 $genre = $_REQUEST["genre"];
    						 $publisher = $_REQUEST["publisher"];
    						 $releaseYear = $_REQUEST["releaseYear"];
    						 $rarity = $_REQUEST["rarity"];
    						$sql = "insert into Games Values('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    					}
    					$ok = sqlite_exec($dir, $sql);
    					if (!$ok) die("Cannot execute statement.");
    				?>
    To be honest i'm completely lost on what you are trying to say and not really understanding it. This is where i'm at at the moment. I have the text fields and select statements. We assigned them variable names like
    Code:
    				<select name = "publisher">
    
    				Release Year: <input type="Text" name="releaseYear"><br>
    afterwords we added the php. The first part I have no clue what this does:
    Code:
    					if (empty($_POST)){
    				
    					}
    The second part I am assuming says that if it empty then to fetch the information that was entered into the text boxes / select statements and assign them to their respective values ( $title, $ console, ext)

    Code:
    						 $title = $_REQUEST["title"];
    						 $console = $_REQUEST["console"];
    						 $genre = $_REQUEST["genre"];
    						 $publisher = $_REQUEST["publisher"];
    						 $releaseYear = $_REQUEST["releaseYear"];
    						 $rarity = $_REQUEST["rarity"];
    I am assuming that that $ok = sqlite_exec($dir, $sql); is saying that if it passes a test then execute sqlite, directory (listed at top of page) then perform the sql statement provided (but if im using $sql to select my rows for the table wouldn't that mess it up? Also i'm not understanding how the submit button is functioning. The way I understand it is that when i hit submit it is just performing the assigned perform acction (in this case database.php) so is it just reloading the information instead of pushing the command to sqlite?

    ------------------------------------------------------------------------------
    My line of thinking is that I should be adding a new variable in the top section of the php called $sql2. And define it with my insert into games values, then follow the path like done with displaying the tables like such:

    Code:
    	<?php
    				 
    		// Specify your sqlite database name and path //
    		$dir = 'sqlite:GameCollection';
    			 
    		// Instantiate PDO connection object and failure msg //
    		$dbh = new PDO($dir) or die("cannot open database");
    				 
    		// Define your SQL statement, myTable = table name in your DB //
    		$sql = "SELECT * FROM Games";
    		$sql2 = "insert into Games Values('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    			 
    		// Apply statement //
    		$statement = $dbh->query($sql);
    		$statement2 = $dbh->query($sql2);
    
    		// Fetch the results // 
    		$rowset = $statement->fetchAll();
    		$newGame = $statment2->fetchAll();
    	?>
    Then when the submit button is hit I call the php function you posted that gets all the values. then says something like
    Code:
    $newGame;
    But im assuming i'm WAY off?

  2. #62
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Sorry, was at the bar, anyway back to business...

    The submit button sends the form data over to the specified page in your form's action attribute, in this case you're sending it back to your page. You then use PHP to create variables from the form data to use in your SQL insert statement.

    Code:
    if (empty($_POST))
    {
         //No form data found, moving on				
    }
    else
    {
         //Form data found. Creating variables for form data.
         $title = $_REQUEST["title"];
         $console = $_REQUEST["console"];
         $genre = $_REQUEST["genre"];
         $publisher = $_REQUEST["publisher"];
         $releaseYear = $_REQUEST["releaseYear"];
         $rarity = $_REQUEST["rarity"];
    
         //Creating the string for the SQL statement
         $sql = "INSERT INTO Games (title, console, genre, publisher, releaseYear, rarity) " .  //The period is used to continue onto the next line
                "VALUES ('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    
         //Executes the SQL statement using the above string to add a new row.
         $ok = sqlite_exec($dir, $sql);
         if (!$ok) die("Cannot execute statement.");
    }
    All this is doing is checking if any form data is submitted. If so, the PHP will create variables from the form data that were passed, create a SQL statement string, then use that string with the sqlite_exec command to run the run the string on your database to create the new row. However, if no form data was passed, it will ignore all that.

  3. #63
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Corrderio View Post
    Sorry, was at the bar, anyway back to business...

    The submit button sends the form data over to the specified page in your form's action attribute, in this case you're sending it back to your page. You then use PHP to create variables from the form data to use in your SQL insert statement.

    Code:
    if (empty($_POST))
    {
         //No form data found, moving on				
    }
    else
    {
         //Form data found. Creating variables for form data.
         $title = $_REQUEST["title"];
         $console = $_REQUEST["console"];
         $genre = $_REQUEST["genre"];
         $publisher = $_REQUEST["publisher"];
         $releaseYear = $_REQUEST["releaseYear"];
         $rarity = $_REQUEST["rarity"];
    
         //Creating the string for the SQL statement
         $sql = "INSERT INTO Games (title, console, genre, publisher, releaseYear, rarity) " .  //The period is used to continue onto the next line
                "VALUES ('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    
         //Executes the SQL statement using the above string to add a new row.
         $ok = sqlite_exec($dir, $sql);
         if (!$ok) die("Cannot execute statement.");
    }
    All this is doing is checking if any form data is submitted. If so, the PHP will create variables from the form data that were passed, create a SQL statement string, then use that string with the sqlite_exec command to run the run the string on your database to create the new row. However, if no form data was passed, it will ignore all that.
    Ok I kind of get It now I think. But why do you have to do:
    Code:
    						 $sql = "INSERT INTO Games (title, console, genre, publisher, releaseYear, rarity) " .  //The period is used to continue onto the next line
    								"VALUES ('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    I understand your creating a string with the values, then using the string as the sql statement, but the way its worded is weird like why is it just "insert into games" on the first line then "values" on the second line? Also gives me a error of
    Code:
    Fatal error: Call to undefined function sqlite_exec() in
    On the line saying
    Code:
     $ok = sqlite_exec($dir, $sql);
    Trying to figure it out myself of course i'm thinking because $dir is not defined (although $sql and $dir are both defined at the top of the page so that confused me, also confuses me how I can have 2 $sql variables)

  4. #64
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    The way I worded the INSERT statement was just a matter of preference.

    As for the undefined function, I'm assuming it's because you're running an older version of PHP. Run your page with this line and it should give you the info on what PHP version you have:

    Code:
    <?php phpinfo() ?>

  5. #65
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    You shouldn't use the native interface anyway (sqlite_exec()), because you already opened a DB connection through PDO (at the top, "$dbh = new PDO($dir) or die("cannot open database");"). So all you have left to do is

    Code:
    $dbh->prepare($sql);
    $dbh->execute();
    where $sql is the variable that holds your insert query string.

  6. #66
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Aevis View Post
    You shouldn't use the native interface anyway (sqlite_exec()), because you already opened a DB connection through PDO (at the top, "$dbh = new PDO($dir) or die("cannot open database");"). So all you have left to do is

    Code:
    $dbh->prepare($sql);
    $dbh->execute();
    where $sql is the variable that holds your insert query string.
    So why does this not override the $sql at the top of the page? is it just being defined as a local variable and the one at the top is a global variable?

  7. #67
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Quote Originally Posted by Aevis View Post
    You shouldn't use the native interface anyway (sqlite_exec()), because you already opened a DB connection through PDO (at the top, "$dbh = new PDO($dir) or die("cannot open database");"). So all you have left to do is

    Code:
    $dbh->prepare($sql);
    $dbh->execute();
    where $sql is the variable that holds your insert query string.
    As a PHP greenhorn myself, why would that be a bad thing other than you need the right PHP version? Sorry I'm still new to PHP too so this is somewhat of a learning excise for me as well.

  8. #68
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Code:
    				<?php
    					if (empty($_POST)) {
    						 //No form data found, moving on				
    					}
    					else {
    						 //Form data found. Creating variables for form data.
    						 $title = $_REQUEST["title"];
    						 $console = $_REQUEST["console"];
    						 $genre = $_REQUEST["genre"];
    						 $publisher = $_REQUEST["publisher"];
    						 $releaseYear = $_REQUEST["releaseYear"];
    						 $rarity = $_REQUEST["rarity"];
    
    						 //Creating the string for the SQL statement
    						 $sql = "Insert Into Games VALUES ('$title', '$console', '$genre', '$publisher', '$releaseYear', '$rarity')";
    
    						 //Executes the SQL statement using the above string to add a new row.
    						$dbh ->prepare($sql);
    						$dbh->execute();
    					}
    				?>
    Tried it and getting:

    Fatal error: Call to undefined method PDO::execute() in

    Googling shows that you have to use a prepare statement but you did that :/ Also can i call the statement like i did in the $sql part? I hate having it broken up into two parts

  9. #69
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    Looking around StackFlow, I think you need to create a variable for the prepare line like so:

    Code:
    $varname_of_your_choice = $dbh ->prepare($sql);
    $varname_of_your_choice ->execute();

  10. #70
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    Corrderio is right, shouldn't write code late at night. Also either go with spaces between object and method "$dbh ->prepare($sql)" or not "$dbh->prepare($sql)" but be consistent throughout.

    You could call your statement all in one, even simpler and go with "$dbh->query($sql);". However, that leaves your site wide open to one of the most common threats: SQL injection (read up). PHP has implemented some basic security by not allowing multiple query execution anymore, so this famous example won't work. You still leave your insert vunerable to whatever funky content the user writes into the form fields. So let's adjust your code a bit:

    Code:
    <?php
        if (empty($_POST)) {
             //No form data found, moving on    
        }
        else {
            //Creating the string for the SQL statement with named placeholders
            $sql = "Insert Into Games VALUES (:title, :console, :genre, :publisher, :releaseYear, :rarity)";
    
             //Prepare the query
            $sth = $dbh->prepare($sql);
            
            //Create array with the named placeholders as keys and form data as values
            $data = array(
                ':title' => $_POST["title"],
                ':console' => $_POST["console"],
                ':genre' => $_POST["genre"],
                ':publisher' => $_POST["publisher"],
                ':releaseYear' => $_POST["releaseYear"],
                ':rarity' => $_POST["rarity"],
            );
            
            //Execute the query with the placeholders populated by the data from the array
            $sth->execute($data);        
        }
    ?>
    That way, PDO does all the magic and automatically binds the params from your array in the $sth->execute($data) call. It additionally treats them as strings and escapes special chars to prevent SQL injections. There's an additional advantage in that, that the query is prepared and cached on the database, which makes it very fast to execute multiple times. You could put your execute statement into a loop with varying values to insert and all PHP would do, is to send the placeholder values to the cached query in the DB.

    I replaced $_REQUEST with $_POST because you know which method your form data is sent by. $_REQUEST checks for $_GET, $_POST, $_COOKIE data. So you might even get the wrong data if you have a $_GET or $_COOKIE variable with the same name.

    Also yes, your insert string will overwrite the content of the $sql variable, but it doesn't matter here because the echo happend before. If you want, you can store your insert query in a variable of your choice and use that one instead.

    @Corrderio sqlite_exec() is deprecated as of PHP 5.4. PDO is a DB access abstraction layer to unify access from PHP to all supported databases (http://php.net/manual/en/pdo.drivers.php). If you use a native interface instead, you'll have to write database specific code and use such methods like sqlite_exec(). Now if you ever switch to another database, say MySQL, you'd have to rewrite all your code to use MySQL specific code. By using PDO, all you have left to do is to change your DB access information. Last but not least, user input escaping. Without PDO, you have to write your own code and/or use DB specific methods if there are any (e.g. mysql_real_escape_string()). PDO already does the magic for you, see above example.

    More of a personal preference but PDO is object-oriented, not filthy procedural

  11. #71
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    I see. I'll have to take a look into this since I haven't done much with SQL and PHP. Most of my PHP experience is in Java/C#

  12. #72
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    So If i wanted to allow the user to upload a picture of the game and store it into the database how hard would that be? I haven't tried this yet but its my next step. I assume I wouldn't be actually storing the picture in the database, I would just be getting the file location and storing that correct? I'm reading up on w3schools and seems like the actual button/upload function isant bad but the storing in the database/displaying it in the table is what seems difficult.

  13. #73
    Falcom is better than SE. Change my mind.
    Join Date
    Jun 2006
    Posts
    17,291
    BG Level
    9

    PHP can handle it, but it can be a bit complex:

    http://www.w3schools.com/php/php_file_upload.asp

  14. #74
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    You can store the image in the DB directly (look up the BLOB field type), but I'd advise against that. Mainly because your images will be lost if something happens to the database. Instead you'd upload it (Corrderio's link) into a specified folder and only store the image's name in the db. To display, you have to read that entry and put it into the img src tag

    Code:
    <img src="path/to/my/images/folder/".$image_name.">
    $image_name is the variable that holds your image name, which you get by running a SELECT query previously to the html img code.

  15. #75
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Thats actually the guide i was looking at. I've added the submit button and it lets me pick a file yada yada. I then created the upload_file.php page they wanted, but I dont see where I can change the path name to where it wants to install :/ I see that it stores the file in a folder called upload but when I tested it no file was ever created with upload :/.

    Also I put the upload area inside the submit button form. Would it work like that? Being kinda iffy with how form actions work not 100% about that.

    Code:
    			<form action = "database.php" method = "post">
    				Add a Game to the database:<br>
    				
    				<!-- Input field for the game title -->
    				Title: <input type="Text" name="title"><br>
    				
    				<!-- Drop down box for the console -->
    				Console:
    				<select name = "console">
    					<option value ="Nintendo"> Nintendo </option>
    					<option value ="Super Nintendo"> Super Nintendo </option>
    					<option value ="Nintendo 64"> Nintendo 64 </option>
    					<option value ="Game Cube"> Game Cube </option>
    					<Option value ="Playstation"> Playstation </option>
    					<option Value ="Playstation2"> Playstaiton 2 </option>
    					<option value ="Xbox"> Xbox </option>
    				</select><br>
    				
    				<!-- Drop down box for the Genre -->
    				Genre:
    				<select name= "genre">
    					<option value="Action"> Action </option>
    					<option value="Beatup"> Beat'em Up </option>
    					<option value="Platform"> Platformer </option>
    					<option value="shooter"> Shooter </option>
    					<option value="Adventure"> Adventure </option>
    					<option value="rpg"> Role-Playing </option>
    					<option value="Sim"> Simulation </option>
    					<option value="strategy"> Strategy </option>
    					<option value="Sports"> Sports </option>
    				</select><br>	
    				
    				<!-- Drop down box for the publisher -->
    				Publisher:
    				<select name = "publisher">
    					<option value="Aklaim"> Aklaim </option>
    					<option value="Capcom">Capcom </option>
    					<option value="EA"> EA </option>
    					<option value="KOEI">KOEI</option>
    					<option value="Konami"> Konami </option>
    					<option value="Nintendo"> Nintendo </option>
    					<option value ="Rare">Rare</option>
    					<option value="Snk">SNK</option>
    					<option value="SunSoft">SunSoft </option>
    					<option value="Square Enix"> Square Enix </option>
    					<option value="Tecmo"> Tecmo </option>
    					<option value="TradeWest"> TradeWest </option>
    					<option value="Broderbund"> Broderbund </option>
    				</select><br>
    				
    				<!-- Text field for the release year -->
    				Release Year: <input type="Text" name="releaseYear"><br>
    				
    				<!-- Drop down box for the Rarity option -->
    				Rarity:
    				<select name= "rarity">
    					<option value="Common"> Common </option>
    					<option value="Uncommon"> Uncommon </option>
    					<option value="Rare"> Rare </option>
    					<option value="veryRare"> Very Rare </option>
    					<option value="SuperRare"> Super Rare </option>
    					<option value="Ultrarare"> Ultra Rare </option>
    				</select><br>
    				
    				<form action="upload_file.php" method="post" enctype="multipart/form-data">
    					<label for="file">Upload Photo:</label>
    					<input type="file" name="file" id="file"><br>
    					<input type="submit" name="submit" value="Submit">
    				</form>
    
    				
    				<input type = "submit" value = "Submit" name = "gameSubmit" style="width: 100px; height: 50px;" />

  16. #76
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    You can't put a form into another form. Remove those form tags and simply add
    Code:
    enctype="multipart/form-data"
    into the existing form tag. There's no need to submit your image data to another file (action="upload_file.php"), because we're already handling everything in this one. Once everything works and you feel confident / understand the interconnection between sending/receiving the data, you still could put all your bussiness logic into external files.

    Now that you submit your image data to the very same file, you can access it through the global $_FILES variable and proceed from there on. Use your browser's webconsole to see what you send and what is received.

  17. #77
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Aevis View Post
    You can't put a form into another form. Remove those form tags and simply add
    Code:
    enctype="multipart/form-data"
    into the existing form tag. There's no need to submit your image data to another file (action="upload_file.php"), because we're already handling everything in this one. Once everything works and you feel confident / understand the interconnection between sending/receiving the data, you still could put all your bussiness logic into external files.

    Now that you submit your image data to the very same file, you can access it through the global $_FILES variable and proceed from there on. Use your browser's webconsole to see what you send and what is received.
    Thought that might be the case but was hopeful. So i don't need a new page, but I do need to bring in the other code into this page correct? Also does it matter where I put php code at? Like can I move all the php up to the top or does it need to stay around where its being used?

    Code:
    <?php
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 20000)
    && in_array($extension, $allowedExts)) {
      if ($_FILES["file"]["error"] > 0) {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
      } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
        if (file_exists("upload/" . $_FILES["file"]["name"])) {
          echo $_FILES["file"]["name"] . " already exists. ";
        } else {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
      }
    } else {
      echo "Invalid file";
    }
    ?>

  18. #78
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    Doesn't matter where, just remember you're writing procedural, means order of execusion goes from top to bottom. So you can't echo a variable which is not defined until further down etc.

  19. #79
    Salvage Bans
    Join Date
    Jun 2011
    Posts
    927
    BG Level
    5
    FFXI Server
    Sylph

    Ok this is what I have:
    Code:
    			<form action = "database.php" method = "post" enctype="multipart/form-data">
    				Add a Game to the database:<br>
    				
    				<!-- Input field for the game title -->
    				Title: <input type="Text" name="title"><br>
    				
    				<!-- Drop down box for the console -->
    				Console:
    				<select name = "console">
    					<option value ="Nintendo"> Nintendo </option>
    					<option value ="Super Nintendo"> Super Nintendo </option>
    					<option value ="Nintendo 64"> Nintendo 64 </option>
    					<option value ="Game Cube"> Game Cube </option>
    					<Option value ="Playstation"> Playstation </option>
    					<option Value ="Playstation2"> Playstaiton 2 </option>
    					<option value ="Xbox"> Xbox </option>
    				</select><br>
    				
    				<!-- Drop down box for the Genre -->
    				Genre:
    				<select name= "genre">
    					<option value="Action"> Action </option>
    					<option value="Beatup"> Beat'em Up </option>
    					<option value="Platform"> Platformer </option>
    					<option value="shooter"> Shooter </option>
    					<option value="Adventure"> Adventure </option>
    					<option value="rpg"> Role-Playing </option>
    					<option value="Sim"> Simulation </option>
    					<option value="strategy"> Strategy </option>
    					<option value="Sports"> Sports </option>
    				</select><br>	
    				
    				<!-- Drop down box for the publisher -->
    				Publisher:
    				<select name = "publisher">
    					<option value="Aklaim"> Aklaim </option>
    					<option value="Capcom">Capcom </option>
    					<option value="EA"> EA </option>
    					<option value="KOEI">KOEI</option>
    					<option value="Konami"> Konami </option>
    					<option value="Nintendo"> Nintendo </option>
    					<option value ="Rare">Rare</option>
    					<option value="Snk">SNK</option>
    					<option value="SunSoft">SunSoft </option>
    					<option value="Square Enix"> Square Enix </option>
    					<option value="Tecmo"> Tecmo </option>
    					<option value="TradeWest"> TradeWest </option>
    					<option value="Broderbund"> Broderbund </option>
    				</select><br>
    				
    				<!-- Text field for the release year -->
    				Release Year: <input type="Text" name="releaseYear"><br>
    				
    				<!-- Drop down box for the Rarity option -->
    				Rarity:
    				<select name= "rarity">
    					<option value="Common"> Common </option>
    					<option value="Uncommon"> Uncommon </option>
    					<option value="Rare"> Rare </option>
    					<option value="veryRare"> Very Rare </option>
    					<option value="SuperRare"> Super Rare </option>
    					<option value="Ultrarare"> Ultra Rare </option>
    				</select><br>
    				
    				Upload Image: <input type="file" name="uploadFile"><br>
    							
    				<input type = "submit" value = "Submit" name = "gameSubmit" style="width: 100px; height: 50px;" />
    				
    				<!-- php code to upload the image to the "image" folder -->
    				<?php
    					$target_dir = "images/";
    					$target_dir = $target_dir . basename( $_FILES["uploadFile"]["name"]);
    					$uploadOk=1;
    
    					// Check if file already exists
    					if (file_exists($target_dir . $_FILES["uploadFile"]["name"])) {
    						echo "Sorry, file already exists.";
    						$uploadOk = 0;
    					}
    
    					else { 
    						if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
    							echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.";
    						} else {
    							echo "Sorry, there was an error uploading your file.";
    						}
    					}
    				?>
    I keep getting a error saying:undefined index: uploadFile. Looking at stackoverflow someone said that the first time you run the page uploadFile doesn't exist because it hasn't been sent over from the form. Does this sound right? offered solutions like add in:

    Code:
    (!empty($GET['uploadFile']) ? $_GET['uploadFile'] : null);
    but that's not working, and don't think it would anyway.

    I think the problem comes from the way w3schools does it. The upload php is in another page, so the page is not trying to load it until the submit button is hit (and therefor upload File created). So I can just create a blank variable for uploadFile? :/

    i'm trying in a separate page to create a blank variable for upload file but not working. I'm going to keep working on it though and i'll post if i make progress.

  20. #80
    wotg torrent kitty :3
    Join Date
    Jun 2007
    Posts
    1,643
    BG Level
    6

    Yeah, $_FILES doesn't have any index because it doesn't exist before you upload something. Check if the array is empty before executing your upload code

    Code:
    if(!empty($_FILES))
    {
      all your upload code here
    }

+ Reply to Thread
Page 4 of 9 FirstFirst ... 2 3 4 5 6 ... LastLast

Similar Threads

  1. Replies: 3
    Last Post: 2011-04-29, 05:09
  2. Replies: 14
    Last Post: 2009-09-11, 13:12