Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php5 insert

Status
Not open for further replies.

lonelydragon

Programmer
Aug 5, 2004
75
US
hello:
i am tring to insert some data into the database without any luck. please give me a habd. thank you.

$qry = 'INSERT INTO event VALUES(?,?)';
$stmt = $this->connect->stmt_init();
if($stmt->prepare($qry)){
$stmt->bind_param('is',$userPntr,$startTime);
if(!$stmt->execute()){
printf("Errorcode: %d\n", $this->connect->errno);
}
}
$stmt->close();
 
Hi,

The syntax that you are using is muddled, so I'm guessing that you're fairly new to PHP - well done on getting started, though. I think it might be an idea to look at the documentation on PHP on the PHP.net website ( for the English version - there are other languages too) before you go much further.

You will find plenty of information on PHP syntax, including lots of information on using PHP with different databases. It is well worth reading the introductory chapters on PHP syntax, though, since this underpins all the PHP code. Note that there have been a few changes in the latest version of PHP (5), though most of this is to do with the Object-Oriented Programming side of the language.

There are separate functions for inserting and retrieving information into/from different databases. The functions you use will depend on the database you are using (e.g. MySQL, PostgreSQL, Firebird, Oracle, SQLite...). There are also database abstraction layers (such as ADOdb), which can be used if you are going to be (or might) be using your code on different types of database, so that you don't have to change your code much to access different databases. This is good if you don't know what database you'll definitely be using, since you would normally have to change your code quite a bit (unless you created your own API in your coding).

If you are using MySQL or PostgreSQL, then there are PHP front-end applications, written in PHP, for accessing and manipulating the databases. PHPMyAdmin is one for MySQL, and PHPPgAdmin is one for PostgreSQL. These are useful for setting up your database, and manipulating its structure.

You are better off reading the above information before asking for specific help, since what you want to know will be contained on the PHP site.

Good luck!
 
i am confused. can you just point out the syntax error? i think that will be more helpful. i just \ copied the above code from a PHP5 book and tested it. but the code seemed to does not work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top