473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve data from database and set to a variable

I am having trouble getting this code to work, and was wondering if
someone could tell me what I am doing wrong.

--------------------------------------
CODE--------------------------------------
if (isset($_POST['submitted'])) {

require_once("d atabase.php");
$appt_date = $_POST['appt_month'] . '/' . $_POST['appt_day'] . '/' .
$_POST['appt_year'];
$phone = $_POST['phone1'] . '-' . $_POST['phone2'] . '-' .
$_POST['phone3'];
$appt_time = $_POST['appt_time'];

$query = "SELECT appt_date, appt_time FROM pest_control WHERE
appt_date = " . "'" . $appt_date . "' and appt_time =" . "'" .
$appt_time . "'";
$result = mysql_query ($query);
$rDate = $row['appt_date'];
$rTime = $row['appt_time'];
print $rDate;
print $rTime;
$num = mysql_num_rows( $result);
print $num;
//echo $num . " Number of rows returned<br>\n" ;
//if ($row != mysql_fetch_arr ay ($result)) {
//while ($row != mysql_fetch_arr ay ($result)) {
if ($num == 0)
{
$query = "INSERT INTO pest_control (appt_date, appt_time,
appt_type, name, address1, address2, city, state, zip, phone,
cross_streets)
VALUES ("."'" . $appt_date . "', "."'" .
$_POST['appt_time'] . "', "."'" . $_POST['appt_type'] . "', "."'" .
$_POST['name'] . "',
"."'" . $_POST['address1'] . "', "."'" .
$_POST['address2'] . "', "."'" . $_POST['city'] . "',
"."'" . $_POST['state'] . "', "."'" . $_POST['zip'] . "',
"."'" . $phone . "',
"."'" . $_POST['cross_streets'] . "')";

$result = mysql_query ($query); // Execute the query.
mysql_close($co nn); // Close the database connection.
exit;
}
elseif ($appt_date == $rDate) //Check for conflicting
appointment date
{
echo "We're sorry that appointment date is unavailable, please
select another date.";
user_form_resub mit();
}
elseif ($appt_date == $rTime) //Check for conflicting appoitment
time
{
echo "We're sorry that appointment time is unavailable, please
select another time.";
user_form_resub mit();
}
elseif ($appt_date == $rDate || $appt_time == $rTime) //Check for
conflicting date and time
{
echo "<h3 align='center'> We're sorry that appointment date and time
are already scheduled, please select another date and time.</h3>";
user_form_resub mit();
}
}
}

------------------------------END
CODE---------------------------------------

What I am trying to do is run a query against my database to see if a
appointment time and date are already scheduled, then set the
variables $rDate and $rTime from the query I ran to check those
values.

When I print the number of rows it returns 1, telling me that this
date and time are already scheduled, but then my forms loads again but
doesn't display my message about the conflicting date and time.

I don't get anything returned when I try to print the $rDate and
$rTime to screen.

Any help is appreciated.

Thank you in advance for your assistance.

~John
Jun 2 '08 #1
2 1677
John wrote:
I am having trouble getting this code to work, and was wondering if
someone could tell me what I am doing wrong.

--------------------------------------
CODE--------------------------------------
if (isset($_POST['submitted'])) {

require_once("d atabase.php");
$appt_date = $_POST['appt_month'] . '/' . $_POST['appt_day'] . '/' .
$_POST['appt_year'];
$phone = $_POST['phone1'] . '-' . $_POST['phone2'] . '-' .
$_POST['phone3'];
$appt_time = $_POST['appt_time'];

$query = "SELECT appt_date, appt_time FROM pest_control WHERE
appt_date = " . "'" . $appt_date . "' and appt_time =" . "'" .
$appt_time . "'";
$result = mysql_query ($query);
$rDate = $row['appt_date'];
$rTime = $row['appt_time'];
print $rDate;
print $rTime;
$num = mysql_num_rows( $result);
print $num;
//echo $num . " Number of rows returned<br>\n" ;
//if ($row != mysql_fetch_arr ay ($result)) {
//while ($row != mysql_fetch_arr ay ($result)) {
if ($num == 0)
{
$query = "INSERT INTO pest_control (appt_date, appt_time,
appt_type, name, address1, address2, city, state, zip, phone,
cross_streets)
VALUES ("."'" . $appt_date . "', "."'" .
$_POST['appt_time'] . "', "."'" . $_POST['appt_type'] . "', "."'" .
$_POST['name'] . "',
"."'" . $_POST['address1'] . "', "."'" .
$_POST['address2'] . "', "."'" . $_POST['city'] . "',
"."'" . $_POST['state'] . "', "."'" . $_POST['zip'] . "',
"."'" . $phone . "',
"."'" . $_POST['cross_streets'] . "')";

$result = mysql_query ($query); // Execute the query.
mysql_close($co nn); // Close the database connection.
exit;
}
elseif ($appt_date == $rDate) //Check for conflicting
appointment date
{
echo "We're sorry that appointment date is unavailable, please
select another date.";
user_form_resub mit();
}
elseif ($appt_date == $rTime) //Check for conflicting appoitment
time
{
echo "We're sorry that appointment time is unavailable, please
select another time.";
user_form_resub mit();
}
elseif ($appt_date == $rDate || $appt_time == $rTime) //Check for
conflicting date and time
{
echo "<h3 align='center'> We're sorry that appointment date and time
are already scheduled, please select another date and time.</h3>";
user_form_resub mit();
}
}
}

------------------------------END
CODE---------------------------------------

What I am trying to do is run a query against my database to see if a
appointment time and date are already scheduled, then set the
variables $rDate and $rTime from the query I ran to check those
values.

When I print the number of rows it returns 1, telling me that this
date and time are already scheduled, but then my forms loads again but
doesn't display my message about the conflicting date and time.

I don't get anything returned when I try to print the $rDate and
$rTime to screen.

Any help is appreciated.

Thank you in advance for your assistance.

~John
Hi, John,

Well, to start with, where does the $row array come from, i.e.

$rDate = $row['appt_date'];
$rTime = $row['appt_time'];

You need to call mysql_fetch_arr ay() BEFORE using these to retrieve the
data returned.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 2 '08 #2
On Apr 19, 8:32*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
John wrote:
I am having trouble getting this code to work, and was wondering if
someone could tell me what I am doing wrong.
--------------------------------------
CODE--------------------------------------
if (isset($_POST['submitted'])) {
* *require_once(" database.php");
* *$appt_date = $_POST['appt_month'] . '/' . $_POST['appt_day'] . '/' .
$_POST['appt_year'];
* *$phone = $_POST['phone1'] . '-' . $_POST['phone2'] . '-' .
$_POST['phone3'];
* *$appt_time = $_POST['appt_time'];
* *$query = "SELECT appt_date, appt_time FROM pest_control WHERE
appt_date = " . "'" . $appt_date . "' and appt_time =" . "'" .
$appt_time . "'";
* *$result = mysql_query ($query);
* *$rDate = $row['appt_date'];
* *$rTime = $row['appt_time'];
* *print $rDate;
* *print $rTime;
* *$num = mysql_num_rows( $result);
* *print $num;
* *//echo $num *. " Number of rows returned<br>\n" ;
* * * * * *//if ($row != mysql_fetch_arr ay ($result)) {
* * * * * *//while ($row != mysql_fetch_arr ay ($result)) {
* * * * * *if ($num == 0)
* * * * * *{
* * * * * * * * * * * * * * * * * *$query = "INSERT INTO pest_control (appt_date, appt_time,
appt_type, name, address1, address2, city, state, zip, phone,
cross_streets)
* * * * * * * * * * * * * * * * * * * * * * * * * * *VALUES ("."'" . $appt_date . "', "."'" .
$_POST['appt_time'] . "', "."'" . $_POST['appt_type'] . "', "."'" .
$_POST['name'] . "',
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"."'" . $_POST['address1'] . "', "."'" .
$_POST['address2'] . "', "."'" . $_POST['city'] . "',
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"."'" . $_POST['state'] . "', "."'" . $_POST['zip'] . "',
"."'" . $phone . "',
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"."'" . $_POST['cross_streets'] . "')";
* * * * * * * * * * * * * * * * * *$result = mysql_query ($query); * * * * * * * * * * ** * * * * // Execute the query.
* * * * * * * * * * * * * * * * * *mysql_close($c onn); * * * * * * * * * * * * * * * * * * * * * * * * * * // Close the database connection.
* * * * * * * * * * * * * * * * * *exit;
* * * * * *}
* * * * * *elseif ($appt_date == $rDate) * * * ** * * * * * * * * * * * * //Check for conflicting
appointment date
* * * * * *{
* * * * * * * * * *echo "We're sorry that appointment date is unavailable, please
select another date.";
* * * * * * * * * *user_form_resu bmit();
* * * * * *}
* * * * * *elseif ($appt_date == $rTime) * * * ** * * * * * * * * * * * * //Check for conflictingappo itment
time
* * * * * *{
* * * * * * * * * *echo "We're sorry that appointment time is unavailable, please
select another time.";
* * * * * * * * * *user_form_resu bmit();
* * * * * *}
* * * * * *elseif ($appt_date == $rDate || *$appt_time== $rTime) * * * * *//Check for
conflicting date and time
* * * * * *{
* * * * * * * * * *echo "<h3 align='center'> We're sorry that appointment date and time
are already scheduled, please select another date and time.</h3>";
* * * * * * * * * *user_form_resu bmit();
* * * * * *}
* *}
}
------------------------------END
CODE---------------------------------------
What I am trying to do is run a query against my database to see if a
appointment time and date are already scheduled, then set the
variables $rDate and $rTime from the query I ran to check those
values.
When I print the number of rows it returns 1, telling me that this
date and time are already scheduled, but then my forms loads again but
doesn't display my message about the conflicting date and time.
I don't get anything returned when I try to print the $rDate and
$rTime to screen.
Any help is appreciated.
Thank you in advance for your assistance.
~John

Hi, John,

Well, to start with, where does the $row array come from, i.e.

* * * * $rDate = $row['appt_date'];
* * * * $rTime = $row['appt_time'];

You need to call mysql_fetch_arr ay() BEFORE using these to retrieve the
data returned.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===- Hide quoted text -

- Show quoted text -
Hi Jerry,

Thank you so much for you help. That fixed my problem.

I appreciate your time in looking at this for me.

~John
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
3014
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however lately I've been wanting to do more stuff with user accounts, and had been eying MySQL for over a year. Finally I've decided to start off small by converting the forum's account system to a MySQL database (and convert the rest later after I'm...
1
7561
by: Daman | last post by:
Hi, I am currently facing difficulty displaying chinese, japanese, russian etc. characters. I am using VB 6 and ADO to query the DB2 Version 7.2 unicode database (UTF-8). The resultset that comes back contains garbage characters for Chinese, Russian etc languages. The english characters come back fine using ADO. It seems that DB2 assumes that my application is NOT Unicode compliant.
6
8213
by: Salvani Langosta | last post by:
In an Access 97 database, I use serveral global variables that hold information about the database, for example: gstrFileServer - holds the server root where the database is stored gstrDataServer - holds the server root where a related data warehouse is stored The values of these variables are set when the database is opened. I want to retrieve one or more of these values in a query, but Access
1
1823
by: j.t.w | last post by:
Hi. I'm new to ASP.Net and I'm running into a simple problem (I think). I'm trying to get 2 values from 2 separate queries into 2 different variables. I would then like to take the difference of the two varaibles and place it into a label on an .aspx page. Basically, MyGrossSales = GrossSales from query
13
3437
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My problem here is i need to retrieve back the information submitted to display all the data that the...
1
2094
by: sonalpathak | last post by:
hi i m working on windows application using c#. i have to retrieve data from database in checkbox control but its giving the following error---cannot convert object to bool. the code i am typing is checkbox1.checked=convert.toboolean(ds.tables.rows); if i m using a flag variable bool a= convert.toboolean(ds.tables.rows); if(a==true) checkbox1.checked=true)
3
5065
by: Alfred | last post by:
I want to post text field data from these HTML TEXTAREA tags to a PostgreSQL database and have it reappear back on another page exactly as I had typed it. Over the years I have done this but only did it with simple text. This time around, I want to handle much more complex text. I need to preserve some kinds of features. (Yes, I have turned off magic quotes.) - Need to strip diacritics. I learned I could use htmlentities to catch...
0
1436
by: tigger | last post by:
Hi there, I'm having problems retrieving data from Access database using Visual basic 2005. My database is called Actual_Database and it has a few tables. One of them is called Threshold Database. I'm trying to retrieve data from Threshold Database. In that table, it has columns of AC250L, AC250R, BC250L, BC250R, AC500L etc.. When i select a name from the combo box, and click presentButton, it will show a smile if the values from...
2
2074
by: zek2005 | last post by:
Hi! I have a value loaded in a database as following: &lt;p&gt;&lt;strong&gt;test&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;test 2&lt;/ strong&gt;&lt;em&gt;&lt;strong&gt;questions&lt;img alt=&quot;&quot; src=&quot;http://www.mysite.com/fckeditor/editor/images/smiley/msn/ regular_smile.gif&quot; /&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.