Click to See Complete Forum and Search --> : php + sql + oracle
mikeyzc
08-25-2003, 09:58 AM
ok, im trying to grab the session ID when the use comes to a page, open the database and insert the ID through sql. I've never done this before adn I've had code snippets thrown at me and was told "make them work". Since I'm new to both php & sql I figured I'd ask for some help...
<?php
session_start();
$_SESSION['refer'] = $_GET["refer"];
echo $_SESSION["refer"];
include ( "includes/config.inc" );
function dbConnect($connection);
function dbExecute($sql);
?>
I'm sure there is plenty wrong with my syntax, but of you could point me in the right direction I would appreciate it. Thanks
This code:
session_start();
$_SESSION['refer'] = $_GET["refer"];is going to set the session refer to the value of the $_GET variable refer (which is probably recieved via the query string in a url that looks like this: http://www.yourdomain.com/page.php?refer=someval)
Then, this:
include ( "includes/config.inc" );is going to be including a file. I'm assuming it will be the code for the SQL connectect, functions, etc...
and this code:
function dbConnect($connection);
function dbExecute($sql);is calling two functions, dbConnect and dbExecute, while passing the variable $connection to the former and $sql to the latter.
mikeyzc
08-25-2003, 10:08 AM
oh, sorry for the confusion. I know what that code does, I just wrote it. It seems to have sytax issues and will not parse correctly.
What does the error message you are getting look like?
mikeyzc
08-25-2003, 10:17 AM
Originally posted by pyro
What does the error message you are getting look like?
Parse error: parse error, unexpected ';', expecting '{' in D:\AntekHealthware website\daqbilling\index.php on line 7
Oops... I made a mistake of my description of your code above... :D
This line:
function dbConnect($connection); is not calling a function, but rather setting the function up. If you want to call it, you need to do this:
dbConnect($connection);Otherwise, you need to do something like this:
function dbConnect($connection) {
//do some stuff
}
mikeyzc
08-25-2003, 10:27 AM
here is the config file im including...
<%
if ( ! defined ( 'CONFIG' ))
{
define ( 'CONFIG', 1 );
// Databese login information
// Must be filled in for the system
$db_uname = 'refer';
$db_pword = 'password';
$db_schema = 'schema';
// General defines and globals
function dbConnect ()
{
global $Connection, $db_uname, $db_pword, $db_schema;
$Connection = @ocilogon ( $db_uname, $db_pword, $db_schema );
if ( $Connection != null )
{
return $Connection;
}
exit;
//die ( "Unable to connect to Oracle." );
}
}
/* ------------------------------------------------------------------------- */
function dbExecute ( $sql )
$sql = "INSERT INTO ";
$sql .= " inet_refer (";
$sql .= " user_id ";
$sql .= ") VALUES ( ";
$sql .= $_SESSION['refer'] ." )";
{
$ret_val = false;
if (( $Connection = dbConnect ()) != null )
{
$Statement = @ociparse ( $Connection, $sql );
// Default mode is commit on success
if ( @ociexecute ( $Statement ))
{
$ret_val = true;
}
@ocifreestatement ( $Statement );
@ocilogoff ( $Connection );
}
return $ret_val;
}
/* _____________________________________________________________________*/
}
// Do NOT put any code below this as it will by-pass some of the security
?>
Two things that I noticed right off... First is that you opened your PHP with <% (ASP style tag) and closed with ?>. Try opening it with <?PHP and closing with ?>
Second is that you have one too many closing curly brackets ( } ). If you'd space your code out nicer it'd be easier to read. I code java style, which is like this:
<?PHP
function myFunction() {
$x = 1;
if ($x == 1) {
echo "Hello World!";
}
else {
echo "Goodbye World!";
}
}But you could also use C style, which is like this (and closer to what you have):
<?PHP
function myFunction()
{
$x = 1;
if ($x == 1)
{
echo "Hello World!";
}
else
{
echo "Goodbye World!";
}
}
mikeyzc
08-25-2003, 10:48 AM
Parse error: parse error, unexpected $end in D:\AntekHealthware website\daqbilling\includes\config.inc on line 68
Fatal error: Call to undefined function: dbconnect() in D:\AntekHealthware website\daqbilling\index.php on line 7
<?php
session_start();
#use $HTTP_SESSION_VARS with PHP 4.0.6 or less
$_SESSION['refer'] = $_GET["refer"];
#echo $_SESSION["refer"];
include ( "includes/config.inc" );
dbConnect($connection);
dbExecute ($sql);
?>