473,387 Members | 1,892 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,387 software developers and data experts.

connection to two database and query for if data is recorded

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4. $con = mysql_connect("localhost","root","");
  5. if (!$con)
  6.   {
  7.   die('Could not connect: ' . mysql_error());
  8.   }
  9.  
  10. mysql_select_db("college",$con);
  11. $v_datetime = 'datetime';
  12.  
  13.  
  14. mysql_select_db("calendar", $con);
  15. $result = mysql_query("SELECT * FROM datetime  ORDER BY id DESC LIMIT 1");
  16. while($row = mysql_fetch_array($result))
  17.   {
  18.  
  19.  
  20.  
  21. echo"<div class='month' align='center'><input type='hidden' name='month' value='".$row['month']."' ><l>".$row['month']."</l></div>";
  22.  
  23.  
  24. //---------------------------------- choeckbox 1(bookable time 1)------------------------\\
  25.  
  26. $sql="SELECT college FROM is_availble WHERE datetime=".$v_datetime;
  27. $r = mysql_query($sql);
  28. echo"<div  class='box'>
  29. <div class='boxbut'>";
  30. if ($v_datetime == "$row[day1]   $row[time1]") {
  31.  
  32.  echo"
  33. <d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t> <br/>is booked";
  34. }
  35. else{
  36. echo"<input type='radio' name='datetime' value='". $row['day1']."&nbsp;&nbsp;&nbsp;".$row['time1']."'>
  37. <d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
  38.  
  39. </div>
  40. </div>";
  41.  
  42.  }
  43.  
  44.  

Regards
May 3 '12 #1
2 1660
Dormilich
8,658 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. $college = new PDO("mysql:host=localhost;dbname=college", $user, $pass);
  2. $calendar= new PDO("mysql:host=localhost;dbname=calendar", $user, $pass);
  3.  
  4. // using
  5. $result1 = $college->query($sql_1);
  6. // ...
  7.  
  8. $result2 = $calendar->query($sql_2);
  9. foreach ($result2 as $row)
  10. {
  11.     // ...
  12. }
May 3 '12 #2
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!

Expand|Select|Wrap|Line Numbers
  1. $host='localhost';
  2. $user='valvoja';
  3. $passoerd='test123';
  4. $con = mysql_connect($host,$user,$password);
  5. $con2=mysql_connect($host,$user,$password);
  6. if (!$con)
  7.   {
  8.   die('Could not connect: ' . mysql_error());
  9.   }
  10.  
  11. mysql_select_db("college",$con);
  12. $v_datetime = 'datetime';
  13.  
  14.  
  15. mysql_select_db("calendar", $con2);
  16. $result = mysql_query("SELECT * FROM datetime  ORDER BY id DESC LIMIT 1");
  17. while($row = mysql_fetch_array($result))
  18.   {
  19.     $sql="SELECT college FROM is_availble WHERE datetime=".$v_datetime;
  20. $r = mysql_query($sql);
  21. echo"<div  class='box'>
  22. <div class='boxbut'>";
  23. if ($v_datetime == "$row[day1]   $row[time1]") {
  24.  
  25.  echo"
  26. <d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t> <br/>is booked";
  27. }
  28. else{
  29. echo"<input type='radio' name='datetime' value='". $row['day1']."&nbsp;&nbsp;&nbsp;".$row['time1']."'>
  30. <d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
  31.  
  32. </div>
  33. </div>";
  34.  
  35.  }
  36.  
  37.  

Actually the most importand thing, that I want to do, is that query, which check if checkbox's value exist on database.

thanx
May 4 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
3
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...
6
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...
2
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...
7
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,...
2
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...
2
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...
9
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...
4
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... ...
2
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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...

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.