473,788 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Access Database Auto Number Issue

52 New Member
Hello All-

I need help on a Select statement. I have this...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $conn=odbc_connect('databasename','','');
  4. if (!$conn)
  5.   {exit("Connection Failed: " . $conn);}
  6.  
  7.     $sql="SELECT * FROM tablename where id = '" . $_REQUEST['id'] . "'";
  8.  
  9.     echo "$sql";
  10.     $rs=odbc_exec($conn,$sql);
  11. ?>
  12.  
When I run the page I get this...

Expand|Select|Wrap|Line Numbers
  1.  
  2. PHP Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\yada\yada\yada.php on line 27 
  3.  
  4.  
What am I doing wrong? I have printed the Select statement and it does get a value like so...

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tablename where id = '99999'
  2.  
Do I have to wrap a convert function around the requested id? I'm not really a PHP person, I concentrate mainly on ASP so I'm a little confused. Do I have the syntax correct? Any help would be great.

Also, as far as the Access Database goes the "id" field is set as "Autonumber " to increment and is the primary key of the table.
Dec 6 '07 #1
4 4717
nathj
938 Recognized Expert Contributor
Hello All-

I need help on a Select statement. I have this...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $conn=odbc_connect('databasename','','');
  4. if (!$conn)
  5.   {exit("Connection Failed: " . $conn);}
  6.  
  7.     $sql="SELECT * FROM tablename where id = '" . $_REQUEST['id'] . "'";
  8.  
  9.     echo "$sql";
  10.     $rs=odbc_exec($conn,$sql);
  11. ?>
  12.  
When I run the page I get this...

Expand|Select|Wrap|Line Numbers
  1.  
  2. PHP Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\yada\yada\yada.php on line 27 
  3.  
  4.  
What am I doing wrong? I have printed the Select statement and it does get a value like so...

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tablename where id = '99999'
  2.  
Do I have to wrap a convert function around the requested id? I'm not really a PHP person, I concentrate mainly on ASP so I'm a little confused. Do I have the syntax correct? Any help would be great.

Also, as far as the Access Database goes the "id" field is set as "Autonumber " to increment and is the primary key of the table.
Hi,

Try the following code:

[php]
<?php

$conn=odbc_conn ect('databasena me','','');
if (!$conn)
{exit("Connecti on Failed: " . $conn);}

$lnID = $_REQUEST['id'] ;
$sql="SELECT * FROM tablename where id = $lnID";

echo "$sql";
$rs=odbc_exec($ conn,$sql);
?>
[/php]
That works for me in MySQL and I beleive it should work in Access also.

Cheers
nathj
Dec 6 '07 #2
movieking81
52 New Member
Works Great, thanks! But why do I have to create a variable? Why can't I put the "$_Request("wha tever")" right in the select.

Thanks
Dec 10 '07 #3
clai83
41 New Member
Works Great, thanks! But why do I have to create a variable? Why can't I put the "$_Request("wha tever")" right in the select.

Thanks
Did you try the SQL statement without the single quotes?
Dec 10 '07 #4
nathj
938 Recognized Expert Contributor
Works Great, thanks! But why do I have to create a variable? Why can't I put the "$_Request("wha tever")" right in the select.

Thanks
Hi,

First of all I'm gald that it worked for you.

Second the reason I suggested the variable was two fold; first I like to have a copy of the information so that if it changes I still have the original for comparison. This may not be relevant in your case but for me I've found it useful. Second, and proibably more significant is that I have never tried it the way you suggest so it might work just fine.

Third, I notice you use $_REQUEST[]. At the risk of sticking my nose in where it's not wanted I would recommend not using this array. The data in there comes from $_POST or $_GET. So I think it always better to be explicit in the code as it make it easier to debug later. You will always know where the information came from just be reading that line.

Anyway, all the best with the rest of your project.

Cheers
nathj
Dec 11 '07 #5

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

Similar topics

49
14359
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
6
3672
by: Terry Bell | last post by:
We've had a very large A97 app running fine for the last seven years. I've just converted to SQL Server backend, which is being tested, but meanwhile the JET based version, running under terminal server, has suddenly started running very slowly. The network engineer has thrown up his hands and said "It's Access 97". I've checked out lots of things including the Oplocks setting and other stuff from this NG, and I think I've done everything...
1
1581
by: Eric Girouard | last post by:
Hi A web design client of mine has been developing an Access database with me for the last few months. His intention was to clean up a very messy paper-based workflow consisting of many location / many event calendars. We cleaned up the data, made tables and normalized it. So far so good, the database part works fine. He can find the information he wants when his boss needs him to.
3
16521
by: James Alba | last post by:
Hey all, I am accessing an ms access database using .NET and C#. Like so, /* Create the database connection. */ connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Name); connection.Open(); And all is good.
13
3998
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
17
4420
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting there, but is there a way they can find out if that application was put there from a CD or email or created at work? Hint: It's not on a client/server database, just native jet database mdb created on Access 2003 (default 2000)...
11
4498
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
3
1635
by: tc | last post by:
I have an app that I'm re-writing for MySql and MsSql, the old version connected to an Access database. It is more than likely that existing customers will want to upgrade to the later version. I don't want to rely on 3rd party apps for Migration, so.... I'm more than happy to write the connection code and transfer the data myself, but I don't know how to ensure that all Auto Number fields in the Access database transfer correctly, as in...
1
2917
by: wespw1 | last post by:
I have a database that was created in Access 97 converted to Access 2000, and then to Access 2003 that I created for my Store as a POS database system. The problem is I originally created the ID field (IE Purchaser Table otherwise known as the customer ID) as a text field. I was going to have the ID be part of the name. But that did not work well after the first 150 records or so and I changed the previous records to numbers 1-150 and...
2
2297
by: MNNovice | last post by:
I am working on a database on my CD collection using Access 2003. Some of the table structures are given below. Table 1 tblMusicCategory Field 1: MusicCategoryID - Auto Number (PK) Field 2: MusicCategory - text Field 3: MusicCategoryAbbv - text Table 2 tblArtists Field 1 ArtistID - Auto Number (PK)
0
9656
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
9498
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
10373
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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
10118
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
6750
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();...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2897
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.