Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Sqlite Database Problems
Old 07-01-2010, 10:56 PM Sqlite Database Problems
Junior Talker

Posts: 3
Name: Robert
Trades: 0
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($db0666$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($db0666$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
Attached Files
File Type: zip Sqllite_Logon_DB.zip (3.4 KB, 0 views)
79383 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-02-2010, 05:24 AM Re: Sqlite Database Problems
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Your query is in $Delete, not $sql...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-02-2010, 12:34 PM Re: Sqlite Database Problems
Junior Talker

Posts: 3
Name: Robert
Trades: 0
Thanks for the Reply But When I Changed the code
PHP Code:
<?php
include('sql_Connect.php');
$dh sqlite_open($db0666$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']))
    {
      
$delete =sqlite_escape_string($_POST['Id']);
      
$sql "DELETE FROM $logon WHERE id = (Id)
              VALUES (
$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); 
?>
Code:
All i get is sql = DELETE FROM Logon WHERE id = (Id) VALUES (4); Warning: sqlite_query() [function.sqlite-query]: near "VALUES"
I now I have gone beyond my knowledge of Sqllite And I plead for help, Thanks to tripy I missed an onvouse error. But I still Need Help Please
79383 is offline
Reply With Quote
View Public Profile
 
Old 07-02-2010, 04:37 PM Re: Sqlite Database Problems
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I don't know where you got that delete syntax, but it's all wrong...
http://sqlite.org/lang_delete.html

I think you should have:
PHP Code:
$sql "DELETE FROM $logon WHERE id = $delete;"
It's only for the insert statements that you give
Code:
insert into tblName (field1, field2) values (value1, value2);
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 07-02-2010 at 04:39 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-02-2010, 09:37 PM Re: Sqlite Database Problems
Junior Talker

Posts: 3
Name: Robert
Trades: 0
Thank You Tripy You where a Big help thanks, I am new to Sqllite and i am trying to learn my field is more mysql. i have One Last Question I went to combine the 2 Scripts into one page so you have the Add a User and then below that is the Current Sqllite Databse of users displayed and then you have the Delete a User below that but when i go to run the script i get a
Code:
Fatal error: Cannot redeclare sqlite_is_empty() (previously declared in C:\xampp\htdocs\test\Sql_Connect.php:5) in C:\xampp\htdocs\test\Sql_Connect.php on line 9
here is what i have
PHP Code:
<?php
include('sql_Connect.php');
$dh sqlite_open($db0666$err) or die ($err);

 
// check to see if the form was submitted 
  
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); 
?> 
<?php
include('sql_Connect.php');
$dh sqlite_open($db0666$err) or die ($err);

 
// check to see if the form was submitted if it is Delete the user 
  
if (isset($_POST['Delete']))
  {
    if (!empty(
$_POST['Id']))
    {
      
$delete sqlite_escape_string($_POST['Id']);
      
$sql "DELETE FROM $logon WHERE id = $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>
The SqlConnect code is
PHP Code:
<?php
$db 
'Test.sqlite';
$logon 'Logon';

function 
sqlite_is_empty($dh)
{
  
$result sqlite_query($dh,"SELECT name FROM sqlite_master WHERE type='table'");
  return (
sqlite_num_rows($result) == 0);
}

function 
sqlite_table_exists($dh$mytable)
{
  
// counts the tables that match the name given
  
$result sqlite_query($dh,"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$mytable'");
  
// casts into integer
  
$count intval(sqlite_fetch_single($result));
  return 
$count 0;
}

function 
sqlite_table_list($dh)
{
  
$result sqlite_query($dh,"SELECT name FROM sqlite_master WHERE type='table'");
  if (
sqlite_num_rows($result) > 0)
  {
    
$s 'Tables:<br />';
    while (
sqlite_has_more($result)) {
      
$row sqlite_fetch_single($result);
      
$s .= $row.'<br />';
    }
  }
  else
  {
    
$s 'Empty DB: No tables';
  }
  return 
$s;
}

if (!
extension_loaded("sqlite"))
{
  
dl("sqlite.so");
};
?>
Thank you and please bear in mind I am still new to this so I might continue to stumble my way throught this Again thank you in advance
79383 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Sqlite Database Problems
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22999 seconds with 13 queries