Not able to insert data in database through phpscript
Posted by:
Sammy 95
Date: January 27, 2009 02:45AM
Hello !
First of all I am quite new to mySQL (but enjoys it) so please exuse me and answer me in a simple way.
I have spendt hours and hours editing a php script that will create a database and at the same time insert some data into it.
Everything works except from the last part. I end up with a database with tables, but no content has been inserted into the table.
No errormessages are shown, actually my checking says that it's OK (but thats MY checking ;-). So I really wonder how to do this..
I have tried both INSERT and UPDATE with no luck. Well UPDATE works in some way..
I am able to open my php script and there I have a form where I am supposed to later edit these data. If I try that everything works.
So I am able to update (insert) data into the database when inside the php script myselves, but when I try to fill it up when creating the database it's not possible.
Here is my trouble part:
-- CODE start --
// create conf
$queryBlocks = mysql_query('CREATE TABLE conf (cfg_id int(11) NOT NULL auto_increment, cfg_status text NOT NULL, cfg_checked text NOT NULL, cfg_admin text NOT NULL, cfg_adminpass text NOT NULL, cfg_pathscript text NOT NULL, cfg_notfound text NOT NULL, cfg_rowsperpage int(4) NOT NULL default \'0\', cfg_codelength int(2) NOT NULL default \'0\', cfg_clearbutton text NOT NULL, PRIMARY KEY (cfg_id));');
if($queryBlocks) {
$msg[] = '<span class="create"><strong>MySQL:</strong> The database table was created.</span>'; }
if(!$queryBlocks) {
$msg[] = '<span class="create"><strong>MySQL:</strong> The database table was NOT created.</span>'; }
// insert data in conf
$insertdata = mysql_query("UPDATE conf SET cfg_admin='$admin_username',cfg_adminpass='$admin_password',cfg_pathscript='$pathscript',cfg_notfound='$notfound',cfg_rowsperpage='10',cfg_codelength='6',cfg_checked='$cfgchecked',cfg_clearbutton='$clearbutton' WHERE cfg_id = '1'") or die(mysql_error());
if(!$insertdata){
$error = 1;
$msg[] = '<span class="error"><strong>MySQL:</strong> Not able to insert data into database </span>'; }
if($insertdata){
$msg[] = '<span class="create"><strong> MySQL:</strong> Data inserted into the database ok.</span>'; }
}
-- CODE cut --
(And the last UPDATE part is almost a clean copy from the php script that works..)
Anyone, please..
Sammy :-)
Edited 1 time(s). Last edit at 01/27/2009 04:02AM by Sammy 95.