Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

login script with ODBC

Status
Not open for further replies.

Zuggy

Programmer
May 18, 2007
12
US
I'm trying to write a registration/login script that connects to an access database through odbc. When I enter the data to register and submit it I get the following error

PHP Fatal error: Call to undefined function odbc_query() in D:\Inetpub\ on line 17

The Code is as follows:

$usercheck = $_POST['username'];
$check = odbc_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(odbc_error());

When I try using odbc_do I get this error

PHP Warning: Wrong parameter count for odbc_do() in D:\Inetpub\ on line 17

I'm new to php and any help would be greatly appreciated.
 
If you go to the canonical source of information on PHP, the online manual ( you will find in the upper right-hand corner of every page of the manual the ability to search for a particular function's page in the manual. If you attempt to perform a lookup for the function odbc_query(), you will find there is no such function in PHP.

A search using that same feature of the online manual will take you the online manual page for odbc_do(). This page will tell you that odbc_do() is a synonym for odbc_exec() and will provide a link to the online manual page for the entry for odbc_exec(). That online manual page will tell you exactly what the parameters to odbc_exec() do.





Want the best answers? Ask the best questions! TANSTAAFL!
 
OK I decided to go with ADOdb to connect, but now I can't get my registration page to insert a new record. Here's the code.

<?php
// Connects to your Database
include('adodb/adodb.inc.php'); # load code common to ADOdb
$db = &ADONewConnection('access'); # create a connection
$db->PConnect('evdb'); # connect to MS-Access, evdb DSN
$db->debug = true;

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields, <a href="reg.php">Return</a>');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = $db->GetRow("SELECT user.username FROM [user] WHERE username = '$usercheck'")
or die('<b>Could Not Connect to Server</b>');
$check2 = count($check);


//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match.');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO user ( username, password )
VALUES ('".$_POST['username']."','".$_POST['pass']."')";
//echo $insert;
$add_member = $db->Execute($insert);

The problem is that I get the little custom error Could Not Connect to Server when I try to insert a record, yet when I check the table to see if the username has been previously used it reads it just fine and returns if the username has been used.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top