Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-20 Thread Evert Lammerts
I should've checked the assumption.

A little strange though for a scripting language. I'd say, since
default behaviour of mysql_* functions is to assume the last opened
link when a parameter is not passed, and since default behaviour is to
evaluate null, false and 0 the same, mysql_* functions should issue a
warning when a not valid link is passed but still use the last opened
link (in that logic, null should also generate a warning though). I'm
guessing the reason is that mysql_connect returns false when it fails,
but i can't see a reason why an undefined variable cannot be used.

All that and I don't remember what it was for.

On Fri, Jun 20, 2008 at 1:57 AM, Chris <[EMAIL PROTECTED]> wrote:
>
>> [new code]
>> if (!mysql_connect($a, $b, $c)) return;
>>
>> if (!mysql_select_db($dbname)) return;
>>
>> $res = mysql_query("SELECT * FROM manual;", $link);
>> [/new code]
>
>
> Isn't going to work because $link is not defined and definitely not a
> resource like mysql_query expects.
>
>> OR, optionally, to surpress the warnings:
>>
>> [new code]
>> if (!mysql_connect($a, $b, $c)) return;
>>
>> $link = null;
>>
>> if (!mysql_select_db($dbname)) return;
>>
>> $res = mysql_query("SELECT * FROM manual;", $link);
>> [/new code]
>
> Isn't going to work because mysql_query needs a resource to connect to.
> You've defined $link as null.
>
> $ cat test.php
>  $user = 'my_db_user';
> $pass = 'my_pass';
> $host = 'localhost';
> $db = 'my_db';
>
> error_reporting(E_ALL);
> ini_set('display_errors', true);
>
> if (!mysql_connect($host, $user, $pass)) {
>die("unable to connect");
> }
>
> if (!mysql_select_db($db)) {
>die("unable to choose db");
> }
>
> $link = null;
> $res = mysql_query('select version() as version', $link);
> while ($row = mysql_fetch_assoc($res)) {
>print_r($row);
> }
>
>
> $ php test.php
>
> Warning: mysql_query(): supplied argument is not a valid MySQL-Link
> resource in /path/to/test.php on line 19
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
> result resource in /path/to/test.php on line 20
>
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread Chris

> [new code]
> if (!mysql_connect($a, $b, $c)) return;
> 
> if (!mysql_select_db($dbname)) return;
> 
> $res = mysql_query("SELECT * FROM manual;", $link);
> [/new code]


Isn't going to work because $link is not defined and definitely not a
resource like mysql_query expects.

> OR, optionally, to surpress the warnings:
> 
> [new code]
> if (!mysql_connect($a, $b, $c)) return;
> 
> $link = null;
> 
> if (!mysql_select_db($dbname)) return;
> 
> $res = mysql_query("SELECT * FROM manual;", $link);
> [/new code]

Isn't going to work because mysql_query needs a resource to connect to.
You've defined $link as null.

$ cat test.php
http://www.designmagick.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread bateivan

Eric,

You gessed right. Both of the files are in my "docroot" directory.
I tried this. Unfortunely, it did not work ( perhaps, I did not use it
right), although, I followed your instructions.

Isaak gave me an idea which solved my problem (see his replies).

Thank you


Eric-275 wrote:
> 
> 
> 
> http://myprojects.srhost.info
> eric{at}myprojects{dot}srhost{dot}info
> - Original Message - 
> From: "bateivan" <[EMAIL PROTECTED]>
> To: 
> Sent: Tuesday, June 17, 2008 11:19 PM
> Subject: [PHP-DB] PHP-MySQL connection for particular module
> 
> 
> : 
> : Hello,
> : 
> : First of all, please, have in mind that I am new in this business.
> : 
> : I have a problem connecting with data base in one particular module.
> That's
> : right. The rest of the modules can connect to db, update tables with new
> : info but this one is refusing giving me message like this:
> : 
> : "Warning: mysql_query() [function.mysql-query]: Access denied for user
> : 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache
> Software
> : Foundation\Apache2.2\htdocs\login.php on line 17
> : 
> 
> This error message state that you have provided a wrong username and / or
> password
> use the die also to ensure the connection was created.
> 
> : Warning: mysql_query() [function.mysql-query]: A link to the server
> could
> : not be established in
> : D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php
> on
> : line 17"
> : 
> : 
> : It is a authentication module and this is the fragment of the code which
> is
> : giving me a hard time:
> : 
> :
> ***
> :  : include $_SERVER['DOCUMENT_ROOT'].
> : '/layout.php';
> : 
> 
> Let's your included page on the same directory. Say f:\webroot\docroot
> As
> f:\webroot\docroot\layout.php
> f:\webroot\docroot\login.php
> 
> then try change the line from
> 
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/layout.php';
> 
> to
> 
> $app_root = './';
>  include ($app_root . 'layout.php');
> 
> 
> : switch($_REQUEST['req']){ 
> :
> : case "validate":
> : 
> :$validate = mysql_query("SELECT * FROM members
> :WHERE username = '{$_POST['username']}'
> :AND password = md5('{$_POST['password']}')"
> :);
> : 
> : etc
> : 
> :
> ***
> : 
> : My platform is WinXP on drive F:\ (I have Win'98 on C:\) and as you can
> see
> : my program files are on D:\. All this may not be important but I listed
> : anyway.
> : It is installed Apache 2.2.6 using windows installer, PHP 5.2.6 (I just
> : replaced 5.2.5 hoping to fix the problem), and MySQL 5.0.45.
> : 
> : I am using persisten connection which should be on until you restart the
> : server. I have a file included in every page for connection with MySQL
> and
> : data base.
> : PHP manual says that "mysql_query" reuses the existing connection or try
> to
> : create one if not present (I think, according to the warning is trying
> to
> : create one).
> : I had been checking after each step using phpinfo() if the connection is
> : there and it's there but for some reason the above fragment does not
> work.
> : As I mentioned above the rest of my modules are working fine with mysql.
> : 
> : I checked the "php.ini" file. I compared it to "php.ini.recomended" from
> the
> : .zip distribusion package and they are almost identical exept couple of
> : things for error reporting.
> : I, also checked FAQ, mail listings and other forums but it does not seem
> : anybody had a similar problem.
> : 
> : In one of my tests I included a line for connection just before the
> problem
> : lines, as described below, and it worked but my intention is to keep
> such
> : lines in a separate files and include them in every page instead.
> : 
> :
> ***
> : ...
> : 
> : $link = mysql_pconnect('localhost', 'root', 'testing');
> : 
> : 
> :$validate = mysql_query("SELECT * FROM members
> :WHERE username = '{$_POST['username']}'
> :AND password = md5('{$_POST[

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread Isaak Malik
It's great that you got your problem solved :).

On Thu, Jun 19, 2008 at 12:30 PM, bateivan <[EMAIL PROTECTED]> wrote:

>
> Hello Isaak,
>
> You've scored the bulleye! It works!
> Also, I tested by including "common.php" instead of "database.php" and it
> worked too.
> This solution is perfect for me as I can keep my code compact and tidy.
>
> I would, definetely, recommend this site to my fellow developers.
>
> Thank you very much, Isaak and all the rest of the guys who took interst in
> my problem.
> Best regards.
>
>
> Isaak Malik-3 wrote:
> >
> > To Evert:
> >
> > 4. I am posting some of my code to compare. Module "carmade.php" works
> > v.s.
> > "login.php" which does not. Also, I am posting my "database.php" which is
> > establishing the connection and is included in every page through
> > "layout.php"->"common.php"->"database.php".
> >
> > To bateivan:
> >
> > I can only guess that the database.php file isn't correctly loaded via
> > layout.php, did you already try to include database.php into the module
> in
> > which it wasn't working? If so and it works then the issue is probably
> > caused by incorrectly including that file, otherwise it has to be
> > something
> > else...
> >
> > And register_globals allows you to use short variables for super global
> > arrays. Ex: $name instead of $_POST['name'], etc.
> >
> >
> > On Wed, Jun 18, 2008 at 9:47 PM, Evert Lammerts <
> [EMAIL PROTECTED]>
> > wrote:
> >
> >> Pastebin works lots better when you're posting code: www.pastebin.com
> >>
> >> I don't see your database.php included in both of these modules. Where
> >> do you include it?
> >>
> >> EVert
> >>
> >> On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
> >> >
> >> > Hello,
> >> >
> >> > To answer these qwestions:
> >> > 1. I am using "include" in my code.
> >> > 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
> >> > variable. I can just include this line before mysql_query function and
> >> it
> >> > works even without entering into mysql_query the "$link" variable.
> >> (Like
> >> the
> >> > connection is waking up).
> >> > 3.My php.ini register_globals is off as suggested for new versions of
> >> PHP
> >> > but include file should work instead according to the manual.
> >> > 4. I am posting some of my code to compare. Module "carmade.php" works
> >> v.s.
> >> > "login.php" which does not. Also, I am posting my "database.php" which
> >> is
> >> > establishing the connection and is included in every page through
> >> > "layout.php"->"common.php"->"database.php".
> >> >
> >> > carmade.php:
> >> >  >> > include $_SERVER['DOCUMENT_ROOT'].
> >> >'/layout.php';
> >> >
> >> > // Quick Login session check
> >> > login_check();
> >> >
> >> > switch($_REQUEST['req']){
> >> >   // Insert Case
> >> >   case "create_carmade":
> >> > myheader("Добавяне на автомобилни марки в списъка");
> >> >
> >> > // Double check form posted values are there
> >> > // before performing INSERT query
> >> > if(!$_POST['car_descr']){
> >> > echo 'Липсва информациятя от формата!'.
> >> > 'Моля, използвайте бутона'.
> >> > 'Назад и въведете данните отново!';
> >> >  footer();
> >> > exit();
> >> > }
> >> >
> >> > // Insert Query
> >> > $sql = mysql_query("INSERT INTO carmade
> >> > (car_descr)
> >> > VALUES('{$_POST['car_descr']}')");
> >> >
> >> > // Insert query results
> >> > if(!$sql){
> >> > echo "Грешка при въвеждане на данните:".mysql_error();
> >> > } else {
> >> >
> >> > echo 'Марката "'.$_POST['car_descr'].
> >> > '"е въведенас номер:'.mysql_insert_id();
> >> > echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
> >> >'въведете друга марка? ';
> >> > }
> >> >   break;
> >> >
> >> >   // Create car made form case
> >> >   case "new_carmade":
> >> >  myheader("Въвеждане на нова автомобилна марка");
> >> >  include $_SERVER['DOCUMENT_ROOT'].
> >> >  '/html/forms/carmade_insert.html';
> >> >  footer();
> >> >   break;
> >> >
> >> >   default:
> >> >  myheader("Администриране на списъка с автомобилните марки");
> >> >  include $_SERVER['DOCUMENT_ROOT'].
> >> >  '/html/carmade_admin.html';
> >> >  footer();
> >> >   break;
> >> >
> >> > }
> >> > ?>
> >> >
> >> > login.php:
> >> >  >> > include $_SERVER['DOCUMENT_ROOT'].
> >> >'/layout.php';
> >> >
> >> >
> >> > switch($_REQUEST['req']){
> >> >
> >> > case "validate":
> >> >
> >> >   $validate = mysql_query("SELECT * FROM members
> >> >   WHERE username = '{$_POST['username']}'
> >> >   AND password = md5('{$_POST['password']}')"
> >> >   );
> >> >
> >> >   $num_rows = mysql_num_rows($validate);
> >> >
> >> >   if($num_rows == 1){
> >> >  while($row = mysql_fetch_assoc($validate)){
> >> > 

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread bateivan

Hello Isaak,

You've scored the bulleye! It works!
Also, I tested by including "common.php" instead of "database.php" and it
worked too.
This solution is perfect for me as I can keep my code compact and tidy.

I would, definetely, recommend this site to my fellow developers.

Thank you very much, Isaak and all the rest of the guys who took interst in
my problem.
Best regards.


Isaak Malik-3 wrote:
> 
> To Evert:
> 
> 4. I am posting some of my code to compare. Module "carmade.php" works
> v.s.
> "login.php" which does not. Also, I am posting my "database.php" which is
> establishing the connection and is included in every page through
> "layout.php"->"common.php"->"database.php".
> 
> To bateivan:
> 
> I can only guess that the database.php file isn't correctly loaded via
> layout.php, did you already try to include database.php into the module in
> which it wasn't working? If so and it works then the issue is probably
> caused by incorrectly including that file, otherwise it has to be
> something
> else...
> 
> And register_globals allows you to use short variables for super global
> arrays. Ex: $name instead of $_POST['name'], etc.
> 
> 
> On Wed, Jun 18, 2008 at 9:47 PM, Evert Lammerts <[EMAIL PROTECTED]>
> wrote:
> 
>> Pastebin works lots better when you're posting code: www.pastebin.com
>>
>> I don't see your database.php included in both of these modules. Where
>> do you include it?
>>
>> EVert
>>
>> On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
>> >
>> > Hello,
>> >
>> > To answer these qwestions:
>> > 1. I am using "include" in my code.
>> > 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
>> > variable. I can just include this line before mysql_query function and
>> it
>> > works even without entering into mysql_query the "$link" variable.
>> (Like
>> the
>> > connection is waking up).
>> > 3.My php.ini register_globals is off as suggested for new versions of
>> PHP
>> > but include file should work instead according to the manual.
>> > 4. I am posting some of my code to compare. Module "carmade.php" works
>> v.s.
>> > "login.php" which does not. Also, I am posting my "database.php" which
>> is
>> > establishing the connection and is included in every page through
>> > "layout.php"->"common.php"->"database.php".
>> >
>> > carmade.php:
>> > > > include $_SERVER['DOCUMENT_ROOT'].
>> >'/layout.php';
>> >
>> > // Quick Login session check
>> > login_check();
>> >
>> > switch($_REQUEST['req']){
>> >   // Insert Case
>> >   case "create_carmade":
>> > myheader("Добавяне на автомобилни марки в списъка");
>> >
>> > // Double check form posted values are there
>> > // before performing INSERT query
>> > if(!$_POST['car_descr']){
>> > echo 'Липсва информациятя от формата!'.
>> > 'Моля, използвайте бутона'.
>> > 'Назад и въведете данните отново!';
>> >  footer();
>> > exit();
>> > }
>> >
>> > // Insert Query
>> > $sql = mysql_query("INSERT INTO carmade
>> > (car_descr)
>> > VALUES('{$_POST['car_descr']}')");
>> >
>> > // Insert query results
>> > if(!$sql){
>> > echo "Грешка при въвеждане на данните:".mysql_error();
>> > } else {
>> >
>> > echo 'Марката "'.$_POST['car_descr'].
>> > '"е въведенас номер:'.mysql_insert_id();
>> > echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
>> >'въведете друга марка? ';
>> > }
>> >   break;
>> >
>> >   // Create car made form case
>> >   case "new_carmade":
>> >  myheader("Въвеждане на нова автомобилна марка");
>> >  include $_SERVER['DOCUMENT_ROOT'].
>> >  '/html/forms/carmade_insert.html';
>> >  footer();
>> >   break;
>> >
>> >   default:
>> >  myheader("Администриране на списъка с автомобилните марки");
>> >  include $_SERVER['DOCUMENT_ROOT'].
>> >  '/html/carmade_admin.html';
>> >  footer();
>> >   break;
>> >
>> > }
>> > ?>
>> >
>> > login.php:
>> > > > include $_SERVER['DOCUMENT_ROOT'].
>> >'/layout.php';
>> >
>> >
>> > switch($_REQUEST['req']){
>> >
>> > case "validate":
>> >
>> >   $validate = mysql_query("SELECT * FROM members
>> >   WHERE username = '{$_POST['username']}'
>> >   AND password = md5('{$_POST['password']}')"
>> >   );
>> >
>> >   $num_rows = mysql_num_rows($validate);
>> >
>> >   if($num_rows == 1){
>> >  while($row = mysql_fetch_assoc($validate)){
>> > $_SESSION['login'] = true;
>> > $_SESSION['userid'] = $row['member_id'];
>> > $_SESSION['first_name'] = $row['first_name'];
>> > $_SESSION['last_name']  = $row['last_name'];
>> > $_SESSION['email_address'] = $row['email_address'];
>> >
>> > if($row['admin_access'] == 1){
>> >$_SESSION['admin_access'] = true;
>> > }
>> > $login_time = m

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread Evert Lammerts
What you said wasn't wrong - you'd just produce a couple of warnings.
By taking away the assignment of the $link variable you're unsetting
it, meaning it will have a value equal to NULL. All of the following
should work.

[old code]
if (!($link = mysql_connect($a, $b, $c))) return;

if (!mysql_select_db($dbname)) return;

$res = mysql_query("SELECT * FROM manual;", $link);
[/old code]

[new code]
if (!mysql_connect($a, $b, $c)) return;

if (!mysql_select_db($dbname)) return;

$res = mysql_query("SELECT * FROM manual;", $link);
[/new code]

OR, optionally, to surpress the warnings:

[new code]
if (!mysql_connect($a, $b, $c)) return;

$link = null;

if (!mysql_select_db($dbname)) return;

$res = mysql_query("SELECT * FROM manual;", $link);
[/new code]

Evert

On Thu, Jun 19, 2008 at 9:12 AM, Isaak Malik <[EMAIL PROTECTED]> wrote:
> My mistake then, it's been a while that I used it that way so some things do
> fade away from my mind.
>
> On Thu, Jun 19, 2008 at 1:57 AM, Chris <[EMAIL PROTECTED]> wrote:
>
>> Isaak Malik wrote:
>> > Because then the connection resource isn't stored in the $link variable
>> > and you will be able to use the mysql functions without passing that
>> > variable to each function.
>>
>> RTM again.
>>
>> The link parameter is completely optional.
>>
>> If you don't specify it, it uses the last connection created.
>>
>> I can do this and it's perfectly valid:
>>
>> $link = mysql_connect($server, $user, $pass);
>> if (!$link) {
>>  die ("Unable to connect to the database server");
>> }
>>
>> $db_selected = mysql_select_db($databasename);
>> if (!$db_selected) {
>>  die("Unable to connect to the database $databasename");
>> }
>>
>> $result = mysql_query("select 1");
>>
>> --
>> Postgresql & php tutorials
>> http://www.designmagick.com/
>>
>
>
>
> --
> Isaak Malik
> Web Developer
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-19 Thread Isaak Malik
My mistake then, it's been a while that I used it that way so some things do
fade away from my mind.

On Thu, Jun 19, 2008 at 1:57 AM, Chris <[EMAIL PROTECTED]> wrote:

> Isaak Malik wrote:
> > Because then the connection resource isn't stored in the $link variable
> > and you will be able to use the mysql functions without passing that
> > variable to each function.
>
> RTM again.
>
> The link parameter is completely optional.
>
> If you don't specify it, it uses the last connection created.
>
> I can do this and it's perfectly valid:
>
> $link = mysql_connect($server, $user, $pass);
> if (!$link) {
>  die ("Unable to connect to the database server");
> }
>
> $db_selected = mysql_select_db($databasename);
> if (!$db_selected) {
>  die("Unable to connect to the database $databasename");
> }
>
> $result = mysql_query("select 1");
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>



-- 
Isaak Malik
Web Developer


Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Chris
Isaak Malik wrote:
> Because then the connection resource isn't stored in the $link variable
> and you will be able to use the mysql functions without passing that
> variable to each function.

RTM again.

The link parameter is completely optional.

If you don't specify it, it uses the last connection created.

I can do this and it's perfectly valid:

$link = mysql_connect($server, $user, $pass);
if (!$link) {
  die ("Unable to connect to the database server");
}

$db_selected = mysql_select_db($databasename);
if (!$db_selected) {
  die("Unable to connect to the database $databasename");
}

$result = mysql_query("select 1");

-- 
Postgresql & php tutorials
http://www.designmagick.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Isaak Malik
To Evert:

4. I am posting some of my code to compare. Module "carmade.php" works v.s.
"login.php" which does not. Also, I am posting my "database.php" which is
establishing the connection and is included in every page through
"layout.php"->"common.php"->"database.php".

To bateivan:

I can only guess that the database.php file isn't correctly loaded via
layout.php, did you already try to include database.php into the module in
which it wasn't working? If so and it works then the issue is probably
caused by incorrectly including that file, otherwise it has to be something
else...

And register_globals allows you to use short variables for super global
arrays. Ex: $name instead of $_POST['name'], etc.


On Wed, Jun 18, 2008 at 9:47 PM, Evert Lammerts <[EMAIL PROTECTED]>
wrote:

> Pastebin works lots better when you're posting code: www.pastebin.com
>
> I don't see your database.php included in both of these modules. Where
> do you include it?
>
> EVert
>
> On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > To answer these qwestions:
> > 1. I am using "include" in my code.
> > 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
> > variable. I can just include this line before mysql_query function and it
> > works even without entering into mysql_query the "$link" variable. (Like
> the
> > connection is waking up).
> > 3.My php.ini register_globals is off as suggested for new versions of PHP
> > but include file should work instead according to the manual.
> > 4. I am posting some of my code to compare. Module "carmade.php" works
> v.s.
> > "login.php" which does not. Also, I am posting my "database.php" which is
> > establishing the connection and is included in every page through
> > "layout.php"->"common.php"->"database.php".
> >
> > carmade.php:
> >  > include $_SERVER['DOCUMENT_ROOT'].
> >'/layout.php';
> >
> > // Quick Login session check
> > login_check();
> >
> > switch($_REQUEST['req']){
> >   // Insert Case
> >   case "create_carmade":
> > myheader("Добавяне на автомобилни марки в списъка");
> >
> > // Double check form posted values are there
> > // before performing INSERT query
> > if(!$_POST['car_descr']){
> > echo 'Липсва информациятя от формата!'.
> > 'Моля, използвайте бутона'.
> > 'Назад и въведете данните отново!';
> >  footer();
> > exit();
> > }
> >
> > // Insert Query
> > $sql = mysql_query("INSERT INTO carmade
> > (car_descr)
> > VALUES('{$_POST['car_descr']}')");
> >
> > // Insert query results
> > if(!$sql){
> > echo "Грешка при въвеждане на данните:".mysql_error();
> > } else {
> >
> > echo 'Марката "'.$_POST['car_descr'].
> > '"е въведенас номер:'.mysql_insert_id();
> > echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
> >'въведете друга марка? ';
> > }
> >   break;
> >
> >   // Create car made form case
> >   case "new_carmade":
> >  myheader("Въвеждане на нова автомобилна марка");
> >  include $_SERVER['DOCUMENT_ROOT'].
> >  '/html/forms/carmade_insert.html';
> >  footer();
> >   break;
> >
> >   default:
> >  myheader("Администриране на списъка с автомобилните марки");
> >  include $_SERVER['DOCUMENT_ROOT'].
> >  '/html/carmade_admin.html';
> >  footer();
> >   break;
> >
> > }
> > ?>
> >
> > login.php:
> >  > include $_SERVER['DOCUMENT_ROOT'].
> >'/layout.php';
> >
> >
> > switch($_REQUEST['req']){
> >
> > case "validate":
> >
> >   $validate = mysql_query("SELECT * FROM members
> >   WHERE username = '{$_POST['username']}'
> >   AND password = md5('{$_POST['password']}')"
> >   );
> >
> >   $num_rows = mysql_num_rows($validate);
> >
> >   if($num_rows == 1){
> >  while($row = mysql_fetch_assoc($validate)){
> > $_SESSION['login'] = true;
> > $_SESSION['userid'] = $row['member_id'];
> > $_SESSION['first_name'] = $row['first_name'];
> > $_SESSION['last_name']  = $row['last_name'];
> > $_SESSION['email_address'] = $row['email_address'];
> >
> > if($row['admin_access'] == 1){
> >$_SESSION['admin_access'] = true;
> > }
> > $login_time = mysql_query("UPDATE members
> >   SET last_login=now()
> >   WHERE id='{$row['id']}'");
> >   }
> >   header("Location: /loggedin.php");
> >   } else {
> >  myheader("Входът в административната зона е неуспешен!");
> >  echo 'Входът в страницата не е успешен!';
> >  echo 'Проверете потребителското си '.
> >   'име и паролата си и опитайте пак или се '.
> >   'обадете на администратора.';
> >  footer();
> >   }
> > break;
> >
> > default:
> >   myheader("Вход!");
> >  include $_SERVER['DOCUME

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Evert Lammerts
Pastebin works lots better when you're posting code: www.pastebin.com

I don't see your database.php included in both of these modules. Where
do you include it?

EVert

On Wed, Jun 18, 2008 at 9:38 PM, bateivan <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> To answer these qwestions:
> 1. I am using "include" in my code.
> 2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
> variable. I can just include this line before mysql_query function and it
> works even without entering into mysql_query the "$link" variable. (Like the
> connection is waking up).
> 3.My php.ini register_globals is off as suggested for new versions of PHP
> but include file should work instead according to the manual.
> 4. I am posting some of my code to compare. Module "carmade.php" works v.s.
> "login.php" which does not. Also, I am posting my "database.php" which is
> establishing the connection and is included in every page through
> "layout.php"->"common.php"->"database.php".
>
> carmade.php:
>  include $_SERVER['DOCUMENT_ROOT'].
>'/layout.php';
>
> // Quick Login session check
> login_check();
>
> switch($_REQUEST['req']){
>   // Insert Case
>   case "create_carmade":
> myheader("Добавяне на автомобилни марки в списъка");
>
> // Double check form posted values are there
> // before performing INSERT query
> if(!$_POST['car_descr']){
> echo 'Липсва информациятя от формата!'.
> 'Моля, използвайте бутона'.
> 'Назад и въведете данните отново!';
>  footer();
> exit();
> }
>
> // Insert Query
> $sql = mysql_query("INSERT INTO carmade
> (car_descr)
> VALUES('{$_POST['car_descr']}')");
>
> // Insert query results
> if(!$sql){
> echo "Грешка при въвеждане на данните:".mysql_error();
> } else {
>
> echo 'Марката "'.$_POST['car_descr'].
> '"е въведенас номер:'.mysql_insert_id();
> echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
>'въведете друга марка? ';
> }
>   break;
>
>   // Create car made form case
>   case "new_carmade":
>  myheader("Въвеждане на нова автомобилна марка");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/forms/carmade_insert.html';
>  footer();
>   break;
>
>   default:
>  myheader("Администриране на списъка с автомобилните марки");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/carmade_admin.html';
>  footer();
>   break;
>
> }
> ?>
>
> login.php:
>  include $_SERVER['DOCUMENT_ROOT'].
>'/layout.php';
>
>
> switch($_REQUEST['req']){
>
> case "validate":
>
>   $validate = mysql_query("SELECT * FROM members
>   WHERE username = '{$_POST['username']}'
>   AND password = md5('{$_POST['password']}')"
>   );
>
>   $num_rows = mysql_num_rows($validate);
>
>   if($num_rows == 1){
>  while($row = mysql_fetch_assoc($validate)){
> $_SESSION['login'] = true;
> $_SESSION['userid'] = $row['member_id'];
> $_SESSION['first_name'] = $row['first_name'];
> $_SESSION['last_name']  = $row['last_name'];
> $_SESSION['email_address'] = $row['email_address'];
>
> if($row['admin_access'] == 1){
>$_SESSION['admin_access'] = true;
> }
> $login_time = mysql_query("UPDATE members
>   SET last_login=now()
>   WHERE id='{$row['id']}'");
>   }
>   header("Location: /loggedin.php");
>   } else {
>  myheader("Входът в административната зона е неуспешен!");
>  echo 'Входът в страницата не е успешен!';
>  echo 'Проверете потребителското си '.
>   'име и паролата си и опитайте пак или се '.
>   'обадете на администратора.';
>  footer();
>   }
> break;
>
> default:
>   myheader("Вход!");
>  include $_SERVER['DOCUMENT_ROOT'].
>  '/html/forms/login_form.html';
>   footer();
> break;
> }
> ?>
>
> database.php:
>  $link = mysql_pconnect('localhost','root','testing');
> $set = mysql_query('SET NAMES CP1251');
> $set = mysql_query('SET_COLLATION=CP1251_GENERAL_CI');
> mysql_select_db('samek_db', $link) or die(mysql_error());
>
> ?>
>
> common.php:
> 
> // Include Meta Content Class
> include $_SERVER['DOCUMENT_ROOT'].'/classes/clsMetaContent.php';
>
> // Include Email Class
> include $_SERVER['DOCUMENT_ROOT'].'/classes/clsEmail.php';
>
> // Include Database Connection File
> include $_SERVER['DOCUMENT_ROOT'].'/includes/database.php';
>
> // Include Session File
> include $_SERVER['DOCUMENT_ROOT'].'/includes/session.php';
>
> ?>
>
> Thank you for your help
>
>
> You're very welcome, I understand that you need a solution which allows you
> to keep using the connection this way.
>
> I doubt that your php.ini is the cause so I'll suggest the following:
>
> Try executing your MySQL queries by passing the $link variable to the
> function a

Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread bateivan

Hello,

To answer these qwestions:
1. I am using "include" in my code.
2. About the "$link = mysql_connect('localhost', 'root', 'testing');"
variable. I can just include this line before mysql_query function and it
works even without entering into mysql_query the "$link" variable. (Like the
connection is waking up).
3.My php.ini register_globals is off as suggested for new versions of PHP
but include file should work instead according to the manual.
4. I am posting some of my code to compare. Module "carmade.php" works v.s.
"login.php" which does not. Also, I am posting my "database.php" which is
establishing the connection and is included in every page through
"layout.php"->"common.php"->"database.php".

carmade.php:
Липсва информациятя от формата!'.
 'Моля, използвайте бутона'.
 'Назад и въведете данните отново!';
  footer();
 exit();
 }
 
 // Insert Query
 $sql = mysql_query("INSERT INTO carmade
 (car_descr)
 VALUES('{$_POST['car_descr']}')");
   
 // Insert query results  
 if(!$sql){
 echo "Грешка при въвеждане на данните:".mysql_error();
 } else {
 
 echo 'Марката "'.$_POST['car_descr'].
 '"е въведенас номер:'.mysql_insert_id();
 echo ' /admin/carmade.php?req=new_carmade Искате ли да'.
'въведете друга марка? ';
 } 
   break;
   
   // Create car made form case
   case "new_carmade":
  myheader("Въвеждане на нова автомобилна марка");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/carmade_insert.html';
  footer();
   break;
   
   default:
  myheader("Администриране на списъка с автомобилните марки");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/carmade_admin.html';
  footer();
   break;
   
}
?>

login.php:
Входът в страницата не е успешен!';
  echo 'Проверете потребителското си '.
   'име и паролата си и опитайте пак или се '.
   'обадете на администратора.';
  footer();
   }
break;

default:
   myheader("Вход!");
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/login_form.html';
   footer();
break;
}
?>  

database.php:


common.php:


Thank you for your help


You're very welcome, I understand that you need a solution which allows you
to keep using the connection this way.

I doubt that your php.ini is the cause so I'll suggest the following:

Try executing your MySQL queries by passing the $link variable to the
function as the connection resource:

mysql_query("SELECT...", $link);

Something that also might cause it is that you use (include|require)_once
and that this module doesn't have access to the connection resource, if this
is the case change it into include|require and see if that solves your
issue. If not then could you please post some example code of your module if
possible so we can be more helpful?

Also be sure that you global $link; it in functions (I don't know if this
required since I didn't use it this way for a long while).

Could you also please answer to the list instead of directly to me as this
might also be informative for others.

-- 
View this message in context: 
http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17990192.html
Sent from the Php - Database mailing list archive at Nabble.com.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread bateivan

Thank you, Chris,

I tried your suggestion using regular connection. Unfortunately, I got the
same result.
See my reply to Isaak,s reply where I am going to post portion of my code to
visualize what I am talking about.

Thanx again


chris smith-9 wrote:
> 
> 
>> It means that either your mysql conenction details are not correctly set
>> or
>> the connection resource isn't accessible for your mysql functions. I
>> suggest
>> you first try by replacing:
>> 
>> $link = mysql_pconnect('localhost', 'root', 'testing');
>> 
>> into:
>> 
>> mysql_pconnect('localhost', 'root', 'testing');
> 
> Why? How is that going to help fix the problem?
> 
> Personally I'd say to *not* use persistent connections as it will cause
> you problems later.
> 
> Use a normal connection:
> 
> $link = mysql_connect($server, $user, $pass);
> 
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17989584.html
Sent from the Php - Database mailing list archive at Nabble.com.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Isaak Malik
Because then the connection resource isn't stored in the $link variable and
you will be able to use the mysql functions without passing that variable to
each function.

On Wed, Jun 18, 2008 at 1:51 AM, Chris <[EMAIL PROTECTED]> wrote:

>
> > It means that either your mysql conenction details are not correctly set
> or
> > the connection resource isn't accessible for your mysql functions. I
> suggest
> > you first try by replacing:
> >
> > $link = mysql_pconnect('localhost', 'root', 'testing');
> >
> > into:
> >
> > mysql_pconnect('localhost', 'root', 'testing');
>
> Why? How is that going to help fix the problem?
>
> Personally I'd say to *not* use persistent connections as it will cause
> you problems later.
>
> Use a normal connection:
>
> $link = mysql_connect($server, $user, $pass);
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>



-- 
Isaak Malik
Web Developer


Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-17 Thread Roberto Carlos García Luís

excuseme but, you can access by terminal? [shell]

ODBC is the user? or is a ODBC database?

Please answer me and i can help you.

**Excuse me my english is bad. :(

El 17/06/2008, a las 06:51 p.m., Chris escribió:



It means that either your mysql conenction details are not  
correctly set or
the connection resource isn't accessible for your mysql functions.  
I suggest

you first try by replacing:

$link = mysql_pconnect('localhost', 'root', 'testing');

into:

mysql_pconnect('localhost', 'root', 'testing');


Why? How is that going to help fix the problem?

Personally I'd say to *not* use persistent connections as it will  
cause

you problems later.

Use a normal connection:

$link = mysql_connect($server, $user, $pass);

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-17 Thread Chris

> It means that either your mysql conenction details are not correctly set or
> the connection resource isn't accessible for your mysql functions. I suggest
> you first try by replacing:
> 
> $link = mysql_pconnect('localhost', 'root', 'testing');
> 
> into:
> 
> mysql_pconnect('localhost', 'root', 'testing');

Why? How is that going to help fix the problem?

Personally I'd say to *not* use persistent connections as it will cause
you problems later.

Use a normal connection:

$link = mysql_connect($server, $user, $pass);

-- 
Postgresql & php tutorials
http://www.designmagick.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-17 Thread Eric


http://myprojects.srhost.info
eric{at}myprojects{dot}srhost{dot}info
- Original Message - 
From: "bateivan" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, June 17, 2008 11:19 PM
Subject: [PHP-DB] PHP-MySQL connection for particular module


: 
: Hello,
: 
: First of all, please, have in mind that I am new in this business.
: 
: I have a problem connecting with data base in one particular module. That's
: right. The rest of the modules can connect to db, update tables with new
: info but this one is refusing giving me message like this:
: 
: "Warning: mysql_query() [function.mysql-query]: Access denied for user
: 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software
: Foundation\Apache2.2\htdocs\login.php on line 17
: 

This error message state that you have provided a wrong username and / or 
password
use the die also to ensure the connection was created.

: Warning: mysql_query() [function.mysql-query]: A link to the server could
: not be established in
: D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on
: line 17"
: 
: 
: It is a authentication module and this is the fragment of the code which is
: giving me a hard time:
: 
: 
***
: http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17915108.html
: Sent from the Php - Database mailing list archive at Nabble.com.
: 
: 
: -- 
: PHP Database Mailing List (http://www.php.net/)
: To unsubscribe, visit: http://www.php.net/unsub.php
:

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-17 Thread Isaak Malik
If you get an error of this kind:

"Warning: mysql_query() [function.mysql-query]: Access denied for user
'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\login.php on line 17

Warning: mysql_query() [function.mysql-query]: A link to the server could
not be established in
D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on
line 17"

It means that either your mysql conenction details are not correctly set or
the connection resource isn't accessible for your mysql functions. I suggest
you first try by replacing:

$link = mysql_pconnect('localhost', 'root', 'testing');

into:

mysql_pconnect('localhost', 'root', 'testing');

On 6/17/08, bateivan <[EMAIL PROTECTED]> wrote:
>
>
> Hello,
>
> First of all, please, have in mind that I am new in this business.
>
> I have a problem connecting with data base in one particular module. That's
> right. The rest of the modules can connect to db, update tables with new
> info but this one is refusing giving me message like this:
>
> "Warning: mysql_query() [function.mysql-query]: Access denied for user
> 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache
> Software
> Foundation\Apache2.2\htdocs\login.php on line 17
>
> Warning: mysql_query() [function.mysql-query]: A link to the server could
> not be established in
> D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on
> line 17"
>
>
> It is a authentication module and this is the fragment of the code which is
> giving me a hard time:
>
>
> ***
>  include $_SERVER['DOCUMENT_ROOT'].
> '/layout.php';
>
> switch($_REQUEST['req']){
>
> case "validate":
>
>$validate = mysql_query("SELECT * FROM members
>WHERE username = '{$_POST['username']}'
>AND password = md5('{$_POST['password']}')"
>);
>
> etc
>
>
> ***
>
> My platform is WinXP on drive F:\ (I have Win'98 on C:\) and as you can see
> my program files are on D:\. All this may not be important but I listed
> anyway.
> It is installed Apache 2.2.6 using windows installer, PHP 5.2.6 (I just
> replaced 5.2.5 hoping to fix the problem), and MySQL 5.0.45.
>
> I am using persisten connection which should be on until you restart the
> server. I have a file included in every page for connection with MySQL and
> data base.
> PHP manual says that "mysql_query" reuses the existing connection or try to
> create one if not present (I think, according to the warning is trying to
> create one).
> I had been checking after each step using phpinfo() if the connection is
> there and it's there but for some reason the above fragment does not work.
> As I mentioned above the rest of my modules are working fine with mysql.
>
> I checked the "php.ini" file. I compared it to "php.ini.recomended" from
> the
> .zip distribusion package and they are almost identical exept couple of
> things for error reporting.
> I, also checked FAQ, mail listings and other forums but it does not seem
> anybody had a similar problem.
>
> In one of my tests I included a line for connection just before the problem
> lines, as described below, and it worked but my intention is to keep such
> lines in a separate files and include them in every page instead.
>
>
> ***
> ...
>
> $link = mysql_pconnect('localhost', 'root', 'testing');
>
>
>$validate = mysql_query("SELECT * FROM members
>WHERE username = '{$_POST['username']}'
>AND password = md5('{$_POST['password']}')"
>);
> etc.
>
> ***
>
> As I metioned, this is an authentication module and, may be, that's why is
> behaving diferently from the rest or I need to do some setup changes in
> "php.ini" which I am not familiar with.
>
> If anyone has had simmilar problem I would appreciate his/her input.
> Please,
> help me resolve this mistery.
>
> --
> View this message in context:
> http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17915108.html
> Sent from the Php - Database mailing list archive at Nabble.com.
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
Isaak Malik
Web Developer


[PHP-DB] PHP-MySQL connection for particular module

2008-06-17 Thread bateivan

Hello,

First of all, please, have in mind that I am new in this business.

I have a problem connecting with data base in one particular module. That's
right. The rest of the modules can connect to db, update tables with new
info but this one is refusing giving me message like this:

"Warning: mysql_query() [function.mysql-query]: Access denied for user
'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\login.php on line 17

Warning: mysql_query() [function.mysql-query]: A link to the server could
not be established in
D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on
line 17"


It is a authentication module and this is the fragment of the code which is
giving me a hard time:

***
http://www.nabble.com/PHP-MySQL-connection-for-particular-module-tp17915108p17915108.html
Sent from the Php - Database mailing list archive at Nabble.com.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php