Ok Here is Where I'm at... And I THINK i'm almost done with this weeks part excluding 1-2 little things, Unless You guys see something I'm missing.
1)I have database.php I deleted the old database and created another one with 2 new fields (image path, and details). Displays fine, picture uploads but the problem i am having with adding a new addition to database is with the picture. It is not storing the picture name into the database for some reason.
Code:
<html>
<html>
<?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 rowid, title, console, genre, publisher, releaseyear, rarity, details, image FROM Games";
// Apply statement //
$statement = $dbh->query($sql);
// Fetch the results //
$rowset = $statement->fetchAll();
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>NES Collection</title>
<link id="pagestyle" href="style.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<body>
<div id="header">
<h1>Retro Game Collection</h1><br><br><br>
<a href = "database.php">Home</a>
<a href = "Search.php">Search</a>
</div>
<div id="body">
<h1>NES Titles</h1>
<!-- This controlles and conatins the 3 collumn text boxes -->
<div id="contentBox" style="margin:0px auto; width:100%">
<div id="column1" style="float:left">
content (scrolls overflow)
</div>
<div id="column2" style="float:left">
content (scrolls overflow)
</div>
<div id="column3" style="float:left;">
content (scrolls overflow)
</div>
</div>
<div id="LowerBody">
<table border ="1" width: "100%">
<tr>
<th>Title</th>
<th>Console</th>
<th>Genre</th>
<th>Publisher</th>
<th>Release Year</th>
<th>Rarity</th>
<th>Details</th>
<th>img Path</th>
</tr>
<tr>
<?php foreach($rowset as $row): ?>
<tr>
<td>
<a href="gameDetails.php?rowid=<?php echo $row['rowid']; ?>">
<?php echo $row['title']; ?>
</a>
</td>
<td><?php echo $row['console']; ?></td>
<td><?php echo $row['genre']; ?></td>
<td><?php echo $row['publisher']; ?></td>
<td><?php echo $row['releaseYear']; ?></td>
<td><?php echo $row['rarity']; ?></td>
<td><?php echo $row['details']; ?></td>
<td><?php echo $row['image']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div id="midBody">
<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 =""> </option>
<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 =""> </option>
<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 =""> </option>
<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 =""> </option>
<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>
Details:<br>
<textarea name = "details" rows ="4" cols="50">
</textarea><br>
Upload Image: <input type="file" name="uploadFile"><br>
<input type = "submit" value = "Submit" name = "gameSubmit" style="width: 100px; height: 50px;" />
<?php
if(!empty($_FILES)) {
$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.";
}
}
}
?>
<!-- PHP statments to push New game data to the database -->
<?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, :details, :image)";
//Prepare the query
$sth = $dbh->prepare($sql);
//Create array with the named place holders 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"],
':details' => $_POST["details"],
':image' => $_POST["uploadFile"],
);
//Execute the query with the place holders populated by the data from the array
$sth->execute($data);
}
?>
</form>
</div>
</div>
</body>
</html>
2) When you click on any of the titles it does go to the next page gameDetails.php, but its not passing all the values for some reason (i might just be calling them wrong not sure). It gets the title (from both database.php and search.php) but its wont let me pull the rest of the information from the row.
Code:
<html>
<?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 title FROM Games WHERE rowid = :rowid";
//Prepare the query
$sth = $dbh->prepare($sql);
//Create array with the named place holders as keys and form data as values
$data = array(
':rowid' => $_GET["rowid"],
);
//Execute the query with the place holders populated by the data from the array
$sth->execute($data);
// Fetch the results //
$row = $sth->fetch();
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>NES Collection</title>
<link id="pagestyle" href="style.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<body>
<div id="header">
<h1>Retro Game Collection</h1><br><br><br>
<a href = "database.php"> Home</a>
<a href = "Search.php">Search</a>
</div>
<div id="detailsBody">
<h1><?php echo $row['title']; ?></h1>
<img src="images/EarthBound_Super Nintendo.jpg" > <br> <!-- This needs to be Coded to work with title selection -->
Console: <?php echo $row['console']; ?> <br>
Genre: <?php echo $row['Genre']; ?> <br>
Publisher: <?php echo $row['Publisher']; ?> <br>
Release Year: <?php echo $row['Release Year']; ?> <br>
Rarity: <?php echo $row['Rarity']; ?> <br>
</div>
</body>
</html>
3) I have a link to search.php in order to search via the database. My goal is for when the page is loaded it shows the entire database, but when you type a word into the search field and hit search it refreshes the database with only titles matching the entered word. I should just be able to change the sql statement that shows the database but kinda confused atm but working on this as we speak.
Code:
<html>
<?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 rowid, title, console, genre, publisher, releaseyear, rarity, details, image FROM Games";
// Apply statement //
$statement = $dbh->query($sql);
// Fetch the results //
$rowset = $statement->fetchAll();
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>NES Collection</title>
<link id="pagestyle" href="style.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<body>
<div id="header">
<h1>Retro Game Collection</h1><br><br><br>
<a href = "database.php"> Home</a>
<a href = "Search.php">Search</a>
</div>
<div id ="searchBody">
<form action = "Search.php" method = "post">
Search By Title: <input type="Text" name="title"><br>
<input type = "submit" value = "Submit" name = "searchSubmit" style="width: 100px; height: 50px;" />
</form>
<?php
if (empty($_POST)) {
//No form data found, moving on
}
else {
//Creating the string for the SQL statement with named placeholders
$sql = "SELECT * FROM GAMES WHERE TITLE = ':title'";
//Prepare the query
$sth = $dbh->prepare($sql);
//Create array with the named place holders as keys and form data as values
$data = array(
':title' => $_POST["title"],
);
//Execute the query with the place holders populated by the data from the array
$sth->execute($data);
}
?>
</div>
<div id="LowerBody">
<table border ="1" width: "100%">
<tr>
<th>Title</th>
<th>Console</th>
<th>Genre</th>
<th>Publisher</th>
<th>Release Year</th>
<th>Rarity</th>
<th>Details</th>
<th>img Path</th>
</tr>
<tr>
<?php foreach($rowset as $row): ?>
<tr>
<td>
<a href="gameDetails.php?rowid=<?php echo $row['rowid']; ?>">
<?php echo $row['title']; ?>
</a>
</td>
<td><?php echo $row['console']; ?></td>
<td><?php echo $row['genre']; ?></td>
<td><?php echo $row['publisher']; ?></td>
<td><?php echo $row['releaseYear']; ?></td>
<td><?php echo $row['rarity']; ?></td>
<td><?php echo $row['details']; ?></td>
<td><?php echo $row['image']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</body>
</html>
Reiteration of current issues:
1) Add game to database not adding image name
2) gameDetails.php not pulling all values from the database (ie console/genre)
3) search doesn't search lol