By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,402 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,402 IT Pros & Developers. It's quick & easy.

Ensuring records are written to the MySQL database

P: n/a
Is there any basic, sure fire 'if - else' script that will ensure that
records entered into my form will actually be written to the database?
I noticed when debugging one day that records would show up when using
the print command as though they'd been entered but hadn't actually
been written to the database. I'm hoping to find some sort of if/else
script that can be easily used with 'insert into' in my PHP. Am using
MySQL 4.1.11nt and PHP 5.04

A sample code I'm working on...
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to
database"); // make connection to database
mysql_select_db($DBName) or die("Unable to select database $DBName");
// select database
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please report this
problem';
exit;
}
$sqlquery = "INSERT INTO $table VALUES('$id', '$money', '$treats',
'$date')";
$results = mysql_query($sqlquery);
mysql_close();

TIA for any help.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


On 6-May-2005, cover <coverland914 @ yahoo.com> wrote:
Is there any basic, sure fire 'if - else' script that will ensure that
records entered into my form will actually be written to the database?
I noticed when debugging one day that records would show up when using
the print command as though they'd been entered but hadn't actually
been written to the database. I'm hoping to find some sort of if/else
script that can be easily used with 'insert into' in my PHP. Am using
MySQL 4.1.11nt and PHP 5.04


mysql_query() returns TRUE or FALSE to indicate the success of the query.
You can test it with an if.

Look at example 1 in the manual:
http://www.php.net/manual/en/functio...l-db-query.php

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

P: n/a
Yes. I can't tell if you're using mysql or mysqli so first pick one and
then use one of the following:

http://php.net/manual/en/function.my...ected-rows.php
http://php.net/manual/en/function.my...ected-rows.php

Jul 17 '05 #3

P: n/a
Isn't mysqli the one that is preferred? If so, I'll probably just use
that one exclusively. Thanks very much guys - appreciate your
replies.
On 6 May 2005 23:45:53 -0700, "Philip Olson" <ph*********@gmail.com>
wrote:
Yes. I can't tell if you're using mysql or mysqli so first pick one and
then use one of the following:

http://php.net/manual/en/function.my...ected-rows.php
http://php.net/manual/en/function.my...ected-rows.php


Jul 17 '05 #4

P: n/a
Isn't mysqli the one that is preferred? If so, I'll probably just use
that one exclusively. Thanks very much guys - appreciate your
replies.
On 6 May 2005 23:45:53 -0700, "Philip Olson" <ph*********@gmail.com>
wrote:
Yes. I can't tell if you're using mysql or mysqli so first pick one and
then use one of the following:

http://php.net/manual/en/function.my...ected-rows.php
http://php.net/manual/en/function.my...ected-rows.php


Jul 17 '05 #5

P: n/a
mysqli is used in php5 ONLY
Isn't mysqli the one that is preferred? If so, I'll probably just use
that one exclusively. Thanks very much guys - appreciate your
replies.

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.