[PHP] Re: function problem

2005-01-03 Thread Viktor Popov
Hi, thank you for your reply! I'll consider carefully this holes. Thank you!

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



[PHP] Re: function problem

2005-01-03 Thread Viktor Popov
Hi,

Thank you for your reply!

I have changed the function like this:

function doReg($fname1=,$family1=,$company1=, $MOL1=, $dannum1=,
$bulstat1=, $phone1=, $email1=, $username1=, $password1=,
$payment1=, $maillist1=, $Addr1=, $City1=, $zipcode1=,
$Country1=, $shippingName1=, $shippingFamily1=, $shippingphone1=,
$shippingAddr1=, $shippingcity1=, $shippingzipcode1=,
$shippingCountry1=)
{

  mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or
die(mysql_error());



 mysql_select_db($DB) or die(mysql_error());
  mysql_query( insert into users(name,family,company, MOL, taxnum, bulstat,
phone, email, username, password, payment, maillist, Addr, City, zipcode,
Country, shippingName, shippingFamily, shippingphone, shippingAddr,
shippingcity, shippingzipcode, shippingCountry)
values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
'$phone1', '$email1', '$username1', '$password1', '$payment1', '$maillist1',
'$Addr1', '$City1', '$zipcode1',
'$Country1','$shippingName1','$shippingFamily1',
'$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
'$shippingCountry1')) or die (mysql_error());


}

I think that the problem is not in the insertion string because when write
the function body :
 mysql_pconnect(.);
mysql_select_db($DB) or die(mysql_error());
mysql_query(insert into );

instead doReg() in register.php, everything works. I have inserted some data
in this way.
The problem is that A DATABASE is  NOT SELECTED. This is the message when I
use doReg().

The register.php   is   in the DOCROOT-emagazine.  In the subdirectory
script are common.inc  and  functions.php. In common.inc is this:

?php
 $DB_SERVER=localhost;
 $DB_LOGIN=admin;
 $DB_PASSWORD=**;
 $DB=emagazine;
 $HTTP_HOST=localhost:3000;
 $DOCROOT=emagazine;

?

Is it all right? I think that $DB=emagazine  should work. Here I select
the $DB, which name is emagazine.

I don't understand what's going on:)



Thank you!

Viktor

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



Re: [PHP] Re: function problem

2005-01-03 Thread Richard Lynch
If you were trying to use the result from mysql_pconnect() as the second
optional argument to mysql_query() in your function, be sure you declare
it 'global' inside the function.

Read PHP docs on variable scope if this is what tripped you up.

If not, I have no idea why the database is not selected, but you can now
focus on figuring out where/when it got selected, and where/when it got
un-selected, and there may even be a query you could send to ask MySQL
what database it thinks you are using.  Sprinkle a lot of those through
your code to find out where it changes from what you expect to not
working

Viktor Popov wrote:
 Hi,

 Thank you for your reply!

 I have changed the function like this:

 function doReg($fname1=,$family1=,$company1=, $MOL1=, $dannum1=,
 $bulstat1=, $phone1=, $email1=, $username1=, $password1=,
 $payment1=, $maillist1=, $Addr1=, $City1=, $zipcode1=,
 $Country1=, $shippingName1=, $shippingFamily1=, $shippingphone1=,
 $shippingAddr1=, $shippingcity1=, $shippingzipcode1=,
 $shippingCountry1=)
 {

   mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or
 die(mysql_error());



  mysql_select_db($DB) or die(mysql_error());
   mysql_query( insert into users(name,family,company, MOL, taxnum,
 bulstat,
 phone, email, username, password, payment, maillist, Addr, City, zipcode,
 Country, shippingName, shippingFamily, shippingphone, shippingAddr,
 shippingcity, shippingzipcode, shippingCountry)
 values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
 '$phone1', '$email1', '$username1', '$password1', '$payment1',
 '$maillist1',
 '$Addr1', '$City1', '$zipcode1',
 '$Country1','$shippingName1','$shippingFamily1',
 '$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
 '$shippingCountry1')) or die (mysql_error());


 }

 I think that the problem is not in the insertion string because when write
 the function body :
  mysql_pconnect(.);
 mysql_select_db($DB) or die(mysql_error());
 mysql_query(insert into );

 instead doReg() in register.php, everything works. I have inserted some
 data
 in this way.
 The problem is that A DATABASE is  NOT SELECTED. This is the message when
 I
 use doReg().

 The register.php   is   in the DOCROOT-emagazine.  In the subdirectory
 script are common.inc  and  functions.php. In common.inc is this:

 ?php
  $DB_SERVER=localhost;
  $DB_LOGIN=admin;
  $DB_PASSWORD=**;
  $DB=emagazine;
  $HTTP_HOST=localhost:3000;
  $DOCROOT=emagazine;

 ?

 Is it all right? I think that $DB=emagazine  should work. Here I select
 the $DB, which name is emagazine.

 I don't understand what's going on:)



 Thank you!

 Viktor

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Re: function problem

2005-01-02 Thread Greg Beaver
Hi Viktor,
Viktor Popov wrote:
Hi,
I'm trying to do the following but I don't have any success. Could you help
me here...
I have this code in mu page:
?php
include script/functions.php;
require 'script/common.inc';
$valid = TRUE;
if (isset ($_POST['submit'])) {
foreach($_POST as $key=$value) {
  $$key = $value;
}
This is a huge security hole, far better is to do this:
if (isset ($_POST['submit'])) {
foreach (array('field1', 'field2', 'field3') as $allowedfield) {
if (isset($_POST[$allowedfield])) {
$$allowedfield = $_POST[$allowedfield];
}
}
}
In addition, you really need to use mysql_escape_string() to avoid 
serious potential problems with sql injection attacks.

[NOTE: mysql_db_query() is deprecated, use mysql_query()/mysql_select_db()]
mysql_select_db($DB);
mysql_query('INSERT INTO blahbalhblahblah VALUES(' . 
mysql_escape_string($field1) . ' ');

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


[PHP] Re: function problem

2004-09-04 Thread Torsten Roehr
Matthias Bauw [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm having a problem with a php application;

 I have two files: one is ccadduser wich adds users to a controlcenter
 that I am currently designing for a website.

 In that ccaduserfile I call for a function checkpermission(); this
 function is defined in another file called ccfunctions

 When a user does not have access to the script it should abort the
 script, this is done using a header(location: ccnopermission.php);
 statement

 But now it seems that while executing the function checkpermission()
 the code in ccadduser just keeps running and the database query that
 inserts the new user is executed before the user can be redirected to
 ccnopermission.

 Is there a way to make php wait until checkpermission is completely
executed?

 I know it is not a simple question, but I really need a solution to
 ensure the safety of my system.

 grtz  thanks

 DragonEye

I'm not completely sure if I understand your question but PHP will process
one function after the other. Without seeing some code I'm afraid we can't
help you much.

Regards, Torsten Roehr

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



Re: [PHP] Re: function problem

2004-09-04 Thread Andre Dubuc
On Saturday 04 September 2004 03:42 pm, Torsten Roehr wrote:
 Matthias Bauw [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

  I'm having a problem with a php application;
 
  I have two files: one is ccadduser wich adds users to a controlcenter
  that I am currently designing for a website.
 
  In that ccaduserfile I call for a function checkpermission(); this
  function is defined in another file called ccfunctions
 
  When a user does not have access to the script it should abort the
  script, this is done using a header(location: ccnopermission.php);
  statement
 
  But now it seems that while executing the function checkpermission()
  the code in ccadduser just keeps running and the database query that
  inserts the new user is executed before the user can be redirected to
  ccnopermission.
 
  Is there a way to make php wait until checkpermission is completely

 executed?

  I know it is not a simple question, but I really need a solution to
  ensure the safety of my system.
 
  grtz  thanks
 
  DragonEye

 I'm not completely sure if I understand your question but PHP will process
 one function after the other. Without seeing some code I'm afraid we can't
 help you much.

 Regards, Torsten Roehr


Two thoughts:

You call function checkpermission(); that is defined in another file. How do 
you call this file: do you use absolute url? Might be the problem, as well as 
using header(location; ccnopermissions.php);. Might want to use an absolute 
url there too.

Just a thought or two,
Andre

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



[PHP] Re: Function Problem

2004-09-01 Thread Jasper Howard
the checkpermission(); function should be run before php can pharse anything
farther down the script, try putting an exit; after the header() statement.

-- 


--
Jasper Howard :: Database Administration
Velocity7
1.530.470.9292
http://www.Velocity7.com/
--
Matthias Bauw [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm having a problem with a php application;

 I have two files: one is ccadduser wich adds users to a controlcenter
 that I am currently designing for a website.

 In that ccaduserfile I call for a function checkpermission(); this
 function is defined in another file called ccfunctions

 When a user does not have access to the script it should abort the
 script, this is done using a header(location: ccnopermission.php);
 statement

 But now it seems that while executing the function checkpermission()
 the code in ccadduser just keeps running and the database query that
 inserts the new user is executed before the user can be redirected to
 ccnopermission.

 Is there a way to make php wait until checkpermission is completely
executed?

 I know it is not a simple question, but I really need a solution to
 ensure the safety of my system.

 grtz  thanks

 DragonEye

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



[PHP] Re: Function Problem (Long-ish)

2004-01-13 Thread David Robley
In article [EMAIL PROTECTED], [EMAIL PROTECTED] 
says...
 Hi List,
 
 I have a self-made function that uses a MySql statement something like this:
 
 Function MyFunc(){
  sql = mysql_query(select * from table where somefield=\somevar\){
   while(blah blah){
   $var =blah blah;
}
   }
  return $blah;
 }
 
 This works ok but if I add a bit to the sql then I get a Warning:
 mysql_fetch_array(): supplied argument is not a valid MySQL result resource
 in error, so if I add:
 
 Function MyFunc(){
  sql = mysql_query(select *, count(id) as cnt from table where
 somefield=\somevar\){
   while(blah blah){
   $var =blah blah;
}
   }
  return $blah;
 }
 
 I get the error.
 
 But this works:
 
 Function MyFunc(){
  sql = mysql_query(select count(id) as cnt, sum(numfield) as total from
 table where somefield=\somevar\){
   while(blah blah){
   $var =blah blah;
}
   }
  return $blah;
 }
 
 My Question is Why ?
 
 Any help is a appreciated and I thank you fully in advance.

Bit hard without seeing your actual code; however if you were to use 
mysql_error() after your call to the database it would probably return you 
a useful error message.

Cheers
-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

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



Re: [PHP] Re: Function Problem

2002-11-10 Thread Ernest E Vogelsinger
At 08:16 10.11.2002, conbud said:
[snip]
also I have the function wrong in my original question I have it as
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect($host, $user,$pass
mysql_select_db($dab,$db);
}

and not
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect($host, $user,$pass)mysql_select_db($dab,$db);
}
[snip] 

mysql_select_db already opens a connection to the database; you don't need
the mysql_connect() call afterwards.

In your code you have mysql_select_db() as fourth parameter to
mysql_connect(). While the fourth parameter is boolean and won't generate
any error at runtime, it's use- and senseless. The 4th parameter on
mysql_connect specifies if PHP should use an existing link, or create a new
one.

You should decide whether you want to go with mysql_select_db() or
mysql_connect().


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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




[PHP] Re: Function Problem

2002-11-09 Thread conbud
also I have the function wrong in my original question I have it as
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect($host, $user,$pass
mysql_select_db($dab,$db);
}

and not
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect($host, $user,$pass)mysql_select_db($dab,$db);
}


Conbud [EMAIL PROTECTED] wrote in message
news:20021110065837.99825.qmail;pb1.pair.com...
 Hey
 Im trying to create a fucntion in an include file
 function db_conn($host,$user,$pass,$dab)
 {
 $db = mysql_connect($host, $user,$pass)mysql_select_db($dab,$db);
 }
 
 
 In the page ide use:
 require('func.inc.php');
 db_conn($host,$user,$pass,$dab);
 $result = mysql_query(select * FROM $page,$db);
 $myrow = mysql_fetch_array($result);

 echo $myrow['general_info'];

 ...
 ...
 however when I use the db_conn on the webpage I just get a mysql error
 saying not a valid resource, so how do I get the db_conn to actually
return
 the data, ive tried using

 function db_conn($host,$user,$pass,$db)
 {
 $db = mysql_connect($host, $user,$pass)mysql_select_db($db,$db);

 return $db
 }

 and various other thing but still nothing, I have to actually put the echo
 statements in the function too to get it to work properlly, any ideas?





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




Re: [PHP] Re: Function Problem

2002-11-09 Thread Maxim Maletsky

you need to return $db:

function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect($host, $user,$pass
mysql_select_db($dab,$db);
return $db;
}

and then use $db = db_conn(,,,);

or make it global:


function db_conn($host,$user,$pass,$dab)
{
blobal $db;
$db = mysql_connect($host, $user,$pass
mysql_select_db($dab,$db);
}

-- 
Maxim Maletsky
[EMAIL PROTECTED]


On Sun, 10 Nov 2002 02:16:14 -0500 conbud [EMAIL PROTECTED] wrote:

 also I have the function wrong in my original question I have it as
 function db_conn($host,$user,$pass,$dab)
 {
 $db = mysql_connect($host, $user,$pass
 mysql_select_db($dab,$db);
 }
 
 and not
 function db_conn($host,$user,$pass,$dab)
 {
 $db = mysql_connect($host, $user,$pass)mysql_select_db($dab,$db);
 }
 
 
 Conbud [EMAIL PROTECTED] wrote in message
 news:20021110065837.99825.qmail;pb1.pair.com...
  Hey
  Im trying to create a fucntion in an include file
  function db_conn($host,$user,$pass,$dab)
  {
  $db = mysql_connect($host, $user,$pass)mysql_select_db($dab,$db);
  }
  
  
  In the page ide use:
  require('func.inc.php');
  db_conn($host,$user,$pass,$dab);
  $result = mysql_query(select * FROM $page,$db);
  $myrow = mysql_fetch_array($result);
 
  echo $myrow['general_info'];
 
  ...
  ...
  however when I use the db_conn on the webpage I just get a mysql error
  saying not a valid resource, so how do I get the db_conn to actually
 return
  the data, ive tried using
 
  function db_conn($host,$user,$pass,$db)
  {
  $db = mysql_connect($host, $user,$pass)mysql_select_db($db,$db);
 
  return $db
  }
 
  and various other thing but still nothing, I have to actually put the echo
  statements in the function too to get it to work properlly, any ideas?
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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




Re: [PHP] Re: Function Problem

2002-11-09 Thread conbud
huh I thought I tried that befoer and it didnt work but this time it worked
good, thanks everyone.

Also whats the difference between $globals['$variable'] and just global

-Lee

Maxim Maletsky [EMAIL PROTECTED] wrote in message
news:20021110082455.7C29.MAXIM;php.net...

 you need to return $db:

 function db_conn($host,$user,$pass,$dab)
 {
 $db = mysql_connect($host, $user,$pass
 mysql_select_db($dab,$db);
 return $db;
 }

 and then use $db = db_conn(,,,);

 or make it global:


 function db_conn($host,$user,$pass,$dab)
 {
 blobal $db;
 $db = mysql_connect($host, $user,$pass
 mysql_select_db($dab,$db);
 }

 --
 Maxim Maletsky
 [EMAIL PROTECTED]


 On Sun, 10 Nov 2002 02:16:14 -0500 conbud [EMAIL PROTECTED] wrote:

  also I have the function wrong in my original question I have it as
  function db_conn($host,$user,$pass,$dab)
  {
  $db = mysql_connect($host, $user,$pass
  mysql_select_db($dab,$db);
  }
 
  and not
  function db_conn($host,$user,$pass,$dab)
  {
  $db = mysql_connect($host,
$user,$pass)mysql_select_db($dab,$db);
  }
 
 
  Conbud [EMAIL PROTECTED] wrote in message
  news:20021110065837.99825.qmail;pb1.pair.com...
   Hey
   Im trying to create a fucntion in an include file
   function db_conn($host,$user,$pass,$dab)
   {
   $db = mysql_connect($host,
$user,$pass)mysql_select_db($dab,$db);
   }
   
   
   In the page ide use:
   require('func.inc.php');
   db_conn($host,$user,$pass,$dab);
   $result = mysql_query(select * FROM $page,$db);
   $myrow = mysql_fetch_array($result);
  
   echo $myrow['general_info'];
  
   ...
   ...
   however when I use the db_conn on the webpage I just get a mysql error
   saying not a valid resource, so how do I get the db_conn to actually
  return
   the data, ive tried using
  
   function db_conn($host,$user,$pass,$db)
   {
   $db = mysql_connect($host,
$user,$pass)mysql_select_db($db,$db);
  
   return $db
   }
  
   and various other thing but still nothing, I have to actually put the
echo
   statements in the function too to get it to work properlly, any ideas?
  
  
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 




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