473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Ensuring records are written to the MySQL database

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
5 1495


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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rupak Banerjee | last post by:
Hi, I have a mysql database running on Mysql version 3.23.53 on a Red Hat Linux 7.2. In the database there is a single table with over 150,000 records. Unfortunately, the performance of that table...
7
by: jj | last post by:
It's taking forever to upload 400,000 records to the database through access/odbc, and I've tried phpMyAdmin's interface but it seems to timeout during import of a CSV file. Is there a better way...
2
by: Alex Hunsley | last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data infile' to put some data into a mysql database (I'm using the xampp bundle).. My problem is that I have a four line CSV file...
11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
0
ammoos
by: ammoos | last post by:
hiiii friends...i want to upload some selected mysql datarecords from my offline system which is written in vb to online system which is made by asp.net with vb. i also want to make some processing...
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
1
by: ponvijaya | last post by:
I want to take back up of records in My MySql Database I want to convert the records into csv file and store in a location. If needed I want to import it to the same database.. I need to...
2
by: gophersounds | last post by:
When I run this simple program I am not getting any data back. The program creates a database, creates a table, populates the table with some data, and then tries to read the data. However, no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.