Hi
I want to make a time reservation system. And for that I have one form, which is connected to two databases on the same host. Form gets data from one( datetime table on calendar db) and after user submitted data stores on another one( is_availble table on college db).
Every thing work good. I use checkboxs as calendar, so each checkbox is one time, and I want that make checkbox unavailble if it is has been selected once!
I use this cods but it doesn't work. Could anyone tell me where is the problem
this is how my form looks like:
And this is my code for the first checkbox: -
-
-
<?php
-
$con = mysql_connect("localhost","root","");
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
-
mysql_select_db("college",$con);
-
$v_datetime = 'datetime';
-
-
-
mysql_select_db("calendar", $con);
-
$result = mysql_query("SELECT * FROM datetime ORDER BY id DESC LIMIT 1");
-
while($row = mysql_fetch_array($result))
-
{
-
-
-
-
echo"<div class='month' align='center'><input type='hidden' name='month' value='".$row['month']."' ><l>".$row['month']."</l></div>";
-
-
-
//---------------------------------- choeckbox 1(bookable time 1)------------------------\\
-
-
$sql="SELECT college FROM is_availble WHERE datetime=".$v_datetime;
-
$r = mysql_query($sql);
-
echo"<div class='box'>
-
<div class='boxbut'>";
-
if ($v_datetime == "$row[day1] $row[time1]") {
-
-
echo"
-
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t> <br/>is booked";
-
}
-
else{
-
echo"<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
-
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
-
-
</div>
-
</div>";
-
-
}
-
-
Regards
2 1660
the problem is that you need two connections because mysql_select_db() only changes the default database on the given connection. hence you can’t use two databases on one connection.
additionally, never connect as root, that’s for DB administration. should someone find an exploit (SQL Injection), you’re doomed. a restricted user may only select, but root can alter, delete and create.
note, with PDO/MySQLi this would be easier to handle: -
$college = new PDO("mysql:host=localhost;dbname=college", $user, $pass);
-
$calendar= new PDO("mysql:host=localhost;dbname=calendar", $user, $pass);
-
-
// using
-
$result1 = $college->query($sql_1);
-
// ...
-
-
$result2 = $calendar->query($sql_2);
-
foreach ($result2 as $row)
-
{
-
// ...
-
}
Thank you for you help
I have now this code, actually making connection is still not possible. I also tried your code, but no reasult! -
$host='localhost';
-
$user='valvoja';
-
$passoerd='test123';
-
$con = mysql_connect($host,$user,$password);
-
$con2=mysql_connect($host,$user,$password);
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
-
mysql_select_db("college",$con);
-
$v_datetime = 'datetime';
-
-
-
mysql_select_db("calendar", $con2);
-
$result = mysql_query("SELECT * FROM datetime ORDER BY id DESC LIMIT 1");
-
while($row = mysql_fetch_array($result))
-
{
-
$sql="SELECT college FROM is_availble WHERE datetime=".$v_datetime;
-
$r = mysql_query($sql);
-
echo"<div class='box'>
-
<div class='boxbut'>";
-
if ($v_datetime == "$row[day1] $row[time1]") {
-
-
echo"
-
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t> <br/>is booked";
-
}
-
else{
-
echo"<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
-
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
-
-
</div>
-
</div>";
-
-
}
-
-
Actually the most importand thing, that I want to do, is that query, which check if checkbox's value exist on database.
thanx
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nick |
last post by:
Hi,
* I have established an ODBC connection to an interbase 5.6 .gdb file.
* I have executed a query on the database and put the returned query
data into a data grid.
The reason I copy the...
|
by: Rob Venable |
last post by:
Hi everyone,
Can anyone see a problem with this code. I'm kinda new to asp.net and
I'm having a problem populating a drop down list with a database query.
The results of my query populate the list...
|
by: Brian Henry |
last post by:
is there a way to tell when the database connection is retrieveing data? i
saw the connectionstate.fetching enumerated value, but of course it's not
implemented yet... is there another way to do...
|
by: Lurc |
last post by:
Hi all,
I need to query data from at least 2 MDB files that have a common CardNo
field. The tables that hold those info are in different MDBs, how can I
run select SQL statement under VB.NET...
|
by: Randy Yates |
last post by:
I'm a complete newbie to postgres so please look the
other way if these questions are really stupid.
Is it legitimate to have one database per data file? For
organizational and backup purposes,...
|
by: Jonathan Woods |
last post by:
Hi there,
I would like to query data from SQL Server 2000 by using SMS.
Conceptually, For example, I send the following SMS Message
"TK1234GPS" to SQL Server. Then SQL Server will respond to my...
|
by: Mejmeyster |
last post by:
Hi Everyone!
I've been desperately trying to prepare a database query from Access to Excel. The problem is, when I ask MS Query to import data from more than one table, no data is importing, only...
|
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= |
last post by:
Hi all
On SQL Server tables I use SqlDataReader to query data
like "SELECT * FROM table".
Is there something similar for XML Files ?
I want to use SQL Syntax like "SELECT * FROM table" on
a...
|
by: Cirene |
last post by:
I know that there are several ways to access/query data. (Stored procs,
direct SQL statements, etc...)
Typically I write a simple Stored Procedure, then access it from my webform
like this...
...
|
by: secutos |
last post by:
I have the option of storing data online as text files, or storing data online in a MySQL database. If the information is stored as a text file, all I have to do is a HttpWebRequest to the text file...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |