Adding Records to Database
Moderator: General Moderators
-
vicphillips
- Forum Newbie
- Posts: 2
- Joined: Mon Oct 27, 2008 8:59 am
Adding Records to Database
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();
<?
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();
-
Paul Arnold
- Forum Contributor
- Posts: 141
- Joined: Fri Jun 13, 2008 10:09 am
- Location: Newcastle Upon Tyne
Re: Adding Records to Database
Code: Select all
mysql_query("INSERT INTO Main Ammonia ('field1', 'field2', 'field3', 'field4') VALUES ('Jack', '2008-10-26', '3', '2')");
-
vicphillips
- Forum Newbie
- Posts: 2
- Joined: Mon Oct 27, 2008 8:59 am
Re: Adding Records to Database
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
$database is probably not set, or set to an incorrect value. Try this:vicphillips wrote:i get the error Unable to Select Database.Code: Select all
@mysql_select_db($database) or die( "Unable to select database");
Code: Select all
echo $database;
@mysql_select_db($database) or die(mysql_error());
Last edited by Chalks on Mon Oct 27, 2008 11:04 am, edited 1 time in total.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Adding Records to Database
Code: Select all
mysql_query("INSERT INTO Main Ammonia ('field1', 'field2', 'field3', 'field4') VALUES ('Jack', '2008-10-26', '3', '2')") or die(mysql_error());-
vidyabhushan
- Forum Newbie
- Posts: 16
- Joined: Mon Oct 20, 2008 4:58 pm
Re: Adding Records to Database
is any of the field in database table is primary key???? if yes then make use of table update function....
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Adding Records to Database
But if he's trying to INSERt a record then UPDATE won't be of any help at all.
-
vidyabhushan
- Forum Newbie
- Posts: 16
- Joined: Mon Oct 20, 2008 4:58 pm
Re: Adding Records to Database
if insert fails to execute instead of using die function there we can make use of update function there right???
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Adding Records to Database
<?
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.
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.