Page 1 of 1
Adding Records to Database
Posted: Mon Oct 27, 2008 9:04 am
by vicphillips
I will admit that i am just learning and do not have much knowledge....I have setup a database and i am trying to add records to it using a php page i created.... Below. The table is Main Ammonia and the fields are all setup in the table...I can go into the control panel and update records but not by this page... Can someone tell me where i have gone wrong .... It does not give me an error so my dbinfo.inc.php is working correctly.. I have verified this by changing it and then i get the error Unable to Select Database. Thanks
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
mysql_query("INSERT INTO Main Ammonia VALUES ('Jack', '2008-10-26', '3', '2')");
mysql_close();
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 9:26 am
by Paul Arnold
Code: Select all
mysql_query("INSERT INTO Main Ammonia ('field1', 'field2', 'field3', 'field4') VALUES ('Jack', '2008-10-26', '3', '2')");
You can't have spaces in the table name either.
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 10:25 am
by vicphillips
It will still not update.......Any other ideas.....I can go to phpadmin and add records but not by clicking on this php update page.
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 10:31 am
by papa
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 10:51 am
by Chalks
vicphillips wrote:i get the error Unable to Select Database.
Code: Select all
@mysql_select_db($database) or die( "Unable to select database");
$database is probably not set, or set to an incorrect value. Try this:
Code: Select all
echo $database;
@mysql_select_db($database) or die(mysql_error());
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 11:03 am
by aceconcepts
Code: Select all
mysql_query("INSERT INTO Main Ammonia ('field1', 'field2', 'field3', 'field4') VALUES ('Jack', '2008-10-26', '3', '2')") or die(mysql_error());
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 11:52 am
by vidyabhushan
is any of the field in database table is primary key???? if yes then make use of table update function....
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 12:00 pm
by aceconcepts
But if he's trying to INSERt a record then UPDATE won't be of any help at all.
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 12:04 pm
by vidyabhushan
if insert fails to execute instead of using die function there we can make use of update function there right???
Re: Adding Records to Database
Posted: Mon Oct 27, 2008 12:30 pm
by aceconcepts
No
Re: Adding Records to Database
Posted: Thu Oct 30, 2008 1:22 pm
by jarnail
<?
include("dbinfo.inc.php");
mysql_connect("localhost",$username,$password);
mysql_select_db($database) or die( "Unable to select database");
mysql_query("INSERT INTO Main Ammonia VALUES ('Jack', '2008-10-26', '3', '2')")
or die(mysql_error());
//check fields types. If still not work then send exported table. Everything will be fixed.