Originally Posted by
Corrderio
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
But im assuming i'm WAY off?