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

Cannot Select DB using mssql

I change my database from mysql to mssql, so I need to change the connection code in my php. I’m not familiar about the codes using mssql. Now cannot connect to my database.
I used the following:
php 5.1.4
IIS 6.0
Microsoft SQL Server 2005 Express Edition
SQL Server Management Studio Express
Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //session_start(); 
  3. //session_regenerate_id(); 
  4.  
  5. //if($_SESSION['loggedin']){ 
  6. //the user is already logged in, lets redirect them to the other page 
  7.   //  header("Location:company.php"); 
  8. //} 
  9.  
  10.  
  11. $server = "ISM\SQLEXPRESS";
  12. //$db = "dbtest";
  13. $connectOptions = array("Database" => "dbtest");
  14. //Because UID and PWD are not specified in the connection option, the connection is made with Windows Authentication.
  15. $conn = mssql_connect($server) or die("Could not connect");
  16.  
  17.  
  18. $selected = mssql_select_db($connectOptions)or die("Cannot select DB");    
  19.  
  20.  
  21.         $department = $_POST['department'];    
  22.         $username = $_POST['username']; 
  23.  
  24.         $sql=mssql_query("SELECT `Department`, `Username` FROM `tbluser` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mssql_min_error_severity()); 
  25.         $ct = mssql_num_rows($sql); 
  26.  
  27.         if($ct == 1) { 
  28. // im guessing this means that the user is valid. 
  29. $_SESSION['loggedin'] = true; // now that the user is valid we change the session value. 
  30.             $row = mssql_fetch_assoc($sql);   
  31.  
  32.             //$_SESSION['username'] = $row['Username'] ;
  33.             //$_SESSION['department'] = $row['Department'];
  34.  
  35.             $Departments=array('aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj');
  36.  
  37.             if (in_array($row['Department'], $Departments)){
  38.                     header ('Location:company.php');
  39.             }else{
  40.                     echo "Incorrect Username or Department";
  41.                     header ('Location:index.php');
  42.             }
  43.         }
  44. ?>
  45.  
And when I run this code the result is:

Cannot select DB

Thank you in advance
Oct 12 '10 #1
2 1877
Markus
6,050 Expert 4TB
Use mssql_get_last_message to get an error string.
Oct 12 '10 #2
i think you should add "$conn" (without quotes) as your db resource link identifier..

CMIIW ... ^_^
Oct 27 '10 #3

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

Similar topics

2
by: tracy | last post by:
when i run the statement: SQL> select rowid from student_semester; ERROR at line 1: ORA-01445: cannot select ROWID from a join view without a key-preserved table student_semester is a view...
1
by: Rowan | last post by:
Hi there, it has been a while since i have posted. I am in a situation where I am stumped. I am learning to build a dts package where I am connecting to a table in an AS400. This database is...
0
by: Jim Sneeringer | last post by:
I have a GridView that loads correctly from a SQL table using a TableAdapter and stored procedures. However, when I try to delete from the GridView, I get "Procedure or Function 'EventDelete'...
3
by: Maciek Zywno | last post by:
Hi, I managed to do this by using a query and !! syntax, but it does not work with SPs. So I created a procedure with "@" to define a paraemter, but how can I pass a value to this procedure from...
8
by: terrorix | last post by:
I also posted this article at: microsoft.public.dotnet.framework.aspnet -------- Hi, I Have this sql select(MS SQL): select a.ID, b.ID from Table as a
1
by: agocurti | last post by:
Hi folks, I have a problem migrating from Oracle to MSSQL the statement: stmt2 := 'Select substr('||tabc||',1,50) from '||tabn||' OPEN cur2 FOR stmt2; How can I to perform this dynamic select...
1
by: darwin gonzaga | last post by:
kindly tech me how to use crystal report using mssql server
3
by: hplayer03 | last post by:
I am really stumped on this one.... I have a .net site that uses the default login controls to have users login. I recently made changes to the site (just look and feel) and now I cannot login...
0
by: kaapie | last post by:
Oracle does not know which table's rowid to return from this view and thus it gives an error. What this means is that one of the underlying tables in the view has to have either a primary key or...
5
ddtpmyra
by: ddtpmyra | last post by:
I cannot select the distinct records but Im pretty sure im connected to the database. Please tell me what's wrong with this? and why I cannot see the query result? thanks! echo "Status:"; ...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.