I have a Script that reads a sqllite database with table called Logon the records for table are an ID field, Username, Password the script adds users to the table
PHP Code:
<?php
include('sql_Connect.php');
$dh = sqlite_open($db, 0666, $err) or die ($err);
// check to see if the form was submitted with a new article reference
if (isset($_POST['save']))
{
if (!empty($_POST['User']) && !empty($_POST['Pass']))
{
$User = sqlite_escape_string($_POST['User']);
$Pass = sqlite_escape_string($_POST['Pass']);
$sql = "INSERT INTO $logon (User_name,Password)
VALUES ('$User','$Pass');";
// echo "sql = $sql<br />"; // un-comment for debugging
$result = sqlite_query($dh, $sql) or die("Error in query: ".sqlite_error_string(sqlite_last_error($dh)));
echo "<p><i>Record successfully inserted!</i></p>";
}
else
{
echo "<p><i>Incomplete form input. Record not inserted! Go Back</i></p>";
}
}
else
{
echo 'Add a User to the program:<br />';
}
sqlite_close($dh);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<br />
<hr />
<table>
<tr><td>User_Name: </td><td><input type="text" name="User" size="80"></td></tr>
<tr><td>Password: </td><td><input type="text" name="Pass" size="80"></td></tr>
<tr><td><input type="submit" name="save" value="Save"></td><td><input type=reset value="Clear All"></td>
</table>
<hr/>
</form>
<?php
// set path of database file
$db = 'Test.sqlite';
// open database file
$handle = sqlite_open($db) or die("Could not open database");
// generate query string
$query = "SELECT * FROM Logon";
// execute query
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
// if rows exist
if (sqlite_num_rows($result) > 0) {
// get each row as an array
// print values
echo "<table cellpadding=10 border=1>";
while($row = sqlite_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}
// all done
// close database file
sqlite_close($handle);
?>
I also have a Script that i am working on that deletes a record from the table based upon the Unique Id # that the user inputs into an Id Field Example Record # 7 is ID=7,Username=Bob,Password=Pass123 The User would input 7 into the html form and it would delete that record here is what i have
PHP Code:
<?php
include('sql_Connect.php');
$dh = sqlite_open($db, 0666, $err) or die ($err);
// check to see if the form was submitted with a new article reference
if (isset($_POST['Delete']))
{
if (!empty($_POST['Id']))
{
$Id = sqlite_escape_string($_POST['Id']);
$Delete = "DELETE * FROM $logon WHERE ID LIKE $Delete;";
echo "sql = $sql<br />"; // un-comment for debugging
$result = sqlite_query($dh, $sql) or die("Error in query: ".sqlite_error_string(sqlite_last_error($dh)));
echo "<p><i>Record successfully Deleted!</i></p>";
}
else
{
echo "<p><i>Incomplete form input. Record not Deleted! Go Back</i></p>";
}
}
else
{
echo 'Delete a User:<br />';
}
sqlite_close($dh);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<br />
<hr />
<table>
<tr><td>Id:</td><td><input type="text" name="Id" size="80"></td></tr>
<tr><td><input type="submit" name="Delete" value="Delete"></td><td><input type=reset value="Clear All"></td>
</table>
<hr/>
</form>
<?php
// set path of database file
$db = 'Test.sqlite';
// open database file
$handle = sqlite_open($db) or die("Could not open database");
// generate query string
$query = "SELECT * FROM Logon";
// execute query
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
// if rows exist
if (sqlite_num_rows($result) > 0) {
// get each row as an array
// print values
echo "<table cellpadding=10 border=1>";
while($row = sqlite_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}
// all done
// close database file
sqlite_close($handle);
?>
The Problem that I have is that on Submitting the Form I get the error
Code:
sql =
Warning: sqlite_query() [function.sqlite-query]: Cannot execute empty query. in C:\xampp\htdocs\test\Test_Connection_Remove.php on line 13
Error in query: not an error
Please Help I also thank you in Advance
If it will help you I have uploaded the files in a .zip it has all the required files that i discussed
|