Re: [PHP] function problem
* Richard Lynch <[EMAIL PROTECTED]>: > > > '$shippingCountry1')"))) > > { > >echo "the insertiont cannot be done"; > > echo mysql_error(); > > http://php.net/mysql_error > > >exit(); > > } > > header("Location:http://$HTTP_HOST/$DOCROOT/allright.html";); > > DON'T DO THAT!!! > > Just do: > include 'allright.html'; > > The Location header is for a document that has *MOVED* to a new URL. > > Your document has not moved. Actually, untrue. From the W3C HTTP 1.1 specs: The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. Yes, one of its primary uses is for 3xx errors, and it is used in that arena to indicate a change in a page's location. However, it can also be used in 2xx responses to indicate a page dynamically created for the request or simply to indicate that a 'pass-thru' was used in the request. It's a very common practice in web application programming -- not just PHP, but the field in general -- after a successful form submission to redirect to another page. Doing so can help prevent back-button issues when forms need to be filled out in series -- for example, when you don't want duplicate records created in the database. -- Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED] Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function problem
> '$shippingCountry1')"))) > { >echo "the insertiont cannot be done"; echo mysql_error(); http://php.net/mysql_error >exit(); > } > header("Location:http://$HTTP_HOST/$DOCROOT/allright.html";); DON'T DO THAT!!! Just do: include 'allright.html'; The Location header is for a document that has *MOVED* to a new URL. Your document has not moved. > exit(); > } > > When i try to insert -> the problem is in the insertion. The message > "the > insertiont cannot be done"; appears. Do you know what could be the > mistake? We don't know, but any time you get an error like that, the software that caused that error will have more infomation available if you dig for it. http://php.net/mysql_error is just what you use for MySQL. If it wasn't MySQL you were using, but something else in some other code, there would still be some function to tell you what went wrong. Get in the habit of not only checking for errors, but LOGGING them somewhere and reviewing those logs. You can use: http://php.net/error_log to do like this: error_log(__FILE__ . ': ' __LINE__ . ' ' . @mysql_error() . " $query "); Or you could even get serious and use http://php.net/error_handler with http://php.net/trigger_error to catch and log all errors. By default, your errors will be in the Apache error_log file (usually /usr/local/apache/logs/error_log) but you can send them any place you want. -- 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
Re: [PHP] function problem
Hi! Thank you for the reply! I have change the function: 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="") { if(!($link = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD))) { echo "the connection failed"; exit(); } if(!($newresult = mysql_db_query($DB, "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')"))) { echo "the insertiont cannot be done"; exit(); } header("Location:http://$HTTP_HOST/$DOCROOT/allright.html";); exit(); } When i try to insert -> the problem is in the insertion. The message "the insertiont cannot be done"; appears. Do you know what could be the mistake? Thank you! Viktor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function problem
Are you getting an error? If so what does it say. Also in your code you have nothing to tell you if something is going wrong. Use echo statements - say something if the connection or the query doesn't go through. Also noticed that when you made the connection to the DB you didn't assign it to a variable, but in the query you use $DB as the link. Ex: $DB = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD); if (!$DB) { // remove in production or have it sent to a log. echo 'Failed to connect to the DB'; } You can do the same thing for the query. Respectfully, Ligaya Turmelle 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: if (isset ($_POST['submit'])) { foreach($_POST as $key=>$value) { $$key = $value; } $valid = $fn = checkLength($fname, 2, 50); $ln = checkLength($family, 2, 50); $valid = $valid && $ln; $cm = checkLength($company,0,50); $valid = $valid && $cm; $ml = checkLength($MOL,0,50); $valid = $valid && $ml; $dnum = checkLength($dannum,0,12); $valid = $valid && $dnum; $bst = checkLength($bulstat,0,12); $valid = $valid && $bst; $phn = checkLength($phone,3,20); $valid = $valid && $phn; $em = checkEmail($email); $valid = $valid && $em; $usr = checkLength($username,4,10); $valid = $valid && $usr; $ps = checkLength($password,4,16); $valid = $valid && $ps; $ps2 = checkLength($password2,4,16); $valid = $valid && $ps2; $ps2 = $password == $password2; $valid = $valid && $ps2; $adr = checkLength($Addr,3,70); $valid = $valid && $adr; $cty = checkLength($City,2,50); $valid = $valid && $cty; $zp = checkLength($zipcode,2,10); $valid = $valid && $zp; if ($valid) { //-CHECK THIS--- doReg($fname,$family,$company, $MOL, $dannum, $bulstat, $phone, $email, $username, $password, $payment, $maillist, $Addr, $City, $zipcode, $Country, $shippingName, $shippingFamily, $shippingphone, $shippingAddr, $shippingcity, $shippingzipcode, $shippingCountry); exit; } } else { $fn = $ln = $cm = $ml = $dnum = $bst = $phn = $em = $usr = $ps = $ps2 = $adr = $cty = $zp = TRUE; $fname = $family = $company = $MOL = $dannum = $bulstat = $phone = $email = $username = $password = $password2 = $Addr = $City = $zipcode = ''; } ?> This is a page with validation. If everything is correct($valid==TRUE), I would like to call doReg which must do the following: 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); mysql_db_query($DB, "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')"); } The problem is that it doesn't work. I have tryed to put the code from the doReg function in the page and it works. But when I call the function I can't insert nothing. Why is that? could you tell me? Thank you in advance!! Viktor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function Problem
> 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 > After calling the header redirect call exit(); example: header('Location: somewhere.php'); exit(); Jim Grill Web-1 Hosting, LP http://www.web-1hosting.net > -- > 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] Function Problem (Long-ish)
I think this a lesson to me and anyone else to make more use of mysql_error() in sql statements. I soon as I saw the Engishized explanation via mysql_error() it was obvious and easy to fix. Note to self: Use mysql_error() as standard ;-) I humbly thank you all for you help. Dave C -Original Message- From: Vincent Jansen [mailto:[EMAIL PROTECTED] Sent: 13 January 2004 13:05 To: 'Dave Carrera'; 'Richard Davey' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Function Problem (Long-ish) I doubt that... MySQL says: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause --- Vincent Jansen -Original Message- From: Dave Carrera [mailto:[EMAIL PROTECTED] Sent: dinsdag 13 januari 2004 13:58 To: 'Richard Davey' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Function Problem (Long-ish) Thanks for the reply Richard. If I use this sql in my func: $sql = mysql_query("select count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); Then all is fine and works as expected. If I then add: $sql = mysql_query("select fieldtoselect, count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); So adding the extra field to select, This dose not work :-( Although in other apps not sql-ing within a func this kind of sql query works. So I am puzzled why and if you or the list can help I would appreciate it. Thank you Dave C -Original Message- From: Richard Davey [mailto:[EMAIL PROTECTED] Sent: 13 January 2004 12:48 To: Dave Carrera Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Function Problem (Long-ish) Hello Dave, Tuesday, January 13, 2004, 12:34:33 PM, you wrote: DC> sql = mysql_query("select *, count(id) as cnt from table where DC> somefield=\"somevar\""){ It's nothing to do with your function, simply that your SQL is invalid. -- Best regards, Richardmailto:[EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Function Problem (Long-ish)
I doubt that... MySQL says: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause --- Vincent Jansen -Original Message- From: Dave Carrera [mailto:[EMAIL PROTECTED] Sent: dinsdag 13 januari 2004 13:58 To: 'Richard Davey' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Function Problem (Long-ish) Thanks for the reply Richard. If I use this sql in my func: $sql = mysql_query("select count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); Then all is fine and works as expected. If I then add: $sql = mysql_query("select fieldtoselect, count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); So adding the extra field to select, This dose not work :-( Although in other apps not sql-ing within a func this kind of sql query works. So I am puzzled why and if you or the list can help I would appreciate it. Thank you Dave C -Original Message- From: Richard Davey [mailto:[EMAIL PROTECTED] Sent: 13 January 2004 12:48 To: Dave Carrera Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Function Problem (Long-ish) Hello Dave, Tuesday, January 13, 2004, 12:34:33 PM, you wrote: DC> sql = mysql_query("select *, count(id) as cnt from table where DC> somefield=\"somevar\""){ It's nothing to do with your function, simply that your SQL is invalid. -- Best regards, Richardmailto:[EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 -- 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] Function Problem (Long-ish)
Thanks for the reply Richard. If I use this sql in my func: $sql = mysql_query("select count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); Then all is fine and works as expected. If I then add: $sql = mysql_query("select fieldtoselect, count(fieldtocount) as cnt, sum(fieldforsum) as total from $tab3 where fieldtocompare =\"$varcomparedwith\""); So adding the extra field to select, This dose not work :-( Although in other apps not sql-ing within a func this kind of sql query works. So I am puzzled why and if you or the list can help I would appreciate it. Thank you Dave C -Original Message- From: Richard Davey [mailto:[EMAIL PROTECTED] Sent: 13 January 2004 12:48 To: Dave Carrera Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Function Problem (Long-ish) Hello Dave, Tuesday, January 13, 2004, 12:34:33 PM, you wrote: DC> sql = mysql_query("select *, count(id) as cnt from table where DC> somefield=\"somevar\""){ It's nothing to do with your function, simply that your SQL is invalid. -- Best regards, Richardmailto:[EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.560 / Virus Database: 352 - Release Date: 08/01/2004 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function Problem (Long-ish)
On Tuesday 13 January 2004 20:34, Dave Carrera wrote: [snip] > My Question is Why ? > > Any help is a appreciated and I thank you fully in advance. You're not checking for errors. Incorporate error checking code and make use of mysql_error(). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The goal of science is to build better mousetraps. The goal of nature is to build better mice. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function Problem (Long-ish)
From: "Dave Carrera" <[EMAIL PROTECTED]> > I get a Warning: > mysql_fetch_array(): supplied argument is not a valid MySQL result resource Whenever you get this warning it's because your query failed for some reason and you're trying to use a result that's not valid. Use mysql_error() to see what the error is. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function Problem (Long-ish)
Hello Dave, Tuesday, January 13, 2004, 12:34:33 PM, you wrote: DC> sql = mysql_query("select *, count(id) as cnt from table where DC> somefield=\"somevar\""){ It's nothing to do with your function, simply that your SQL is invalid. -- Best regards, Richardmailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] function problem?
[snip] Not sure why the last section won't work... ...so much code it made my head hurt [/snip] Not sure either. Did you have a question? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function problem (simple redirect)
--- Frank Tudor <[EMAIL PROTECTED]> wrote: > function $payment{ You probably mean payment, not $payment. > header ("location:test_page.html"); The Location header has an uppercase L, a space after the colon, and an absolute URL after the space. Your example violates all three. Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] function problem (simple redirect)
Make that: function payment{ global $payment; -Gregory -Original Message- From: Gregory Kornblum [mailto:[EMAIL PROTECTED] Sent: Monday, October 27, 2003 1:30 PM To: 'Frank Tudor'; 1PHP Subject: RE: [PHP] function problem (simple redirect) >function $payment{ Change that to: function payment{ $global $payment; Regards, -Gregory -- 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] function problem (simple redirect)
>function $payment{ Change that to: function payment{ $global $payment; Regards, -Gregory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function problem
On 2003.02.15 00:11 Peter Gumbrell wrote: [...] $option_block .= " [...] Are you sure it's a scope problem ? You haven't instantiated any $option_block variable when the loop starts, so you're concatenating a string to a bunch of uninitialized memory :) I can't run your script at the moment, so it's just a supposition... Hope it helps, Nicholas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] function problem
Here is the string that is being used in this function example. Everything print except the option_block // Vendor string $vendor_string .= << Select the vendor of your choice: $option_block; EOVS; -Original Message- From: Kevin Stone [mailto:[EMAIL PROTECTED]] Sent: Friday, February 14, 2003 6:41 PM To: Php-General Subject: Re: [PHP] function problem Exactly where does $option_block get put into $string? -Kevin - Original Message - From: "Peter Gumbrell" <[EMAIL PROTECTED]> To: "Php-General" <[EMAIL PROTECTED]> Sent: Friday, February 14, 2003 4:11 PM Subject: [PHP] function problem > I have a function below which populates a select list, based on the query > string and the field name. It then prints a string: > > function populate_selects($query_name, $db_field, $link, $string) > { > $result = mysql_query($query_name, $link) or die ("Could not execute > query."); > while ($columns = mysql_fetch_array($result)) > { > $column = $columns[$db_field]; > global $option_block; > $option_block .= " value=\"$column\">$column\n"; > } > print $string; > } > > Part of the string that is printed in $string is the $option_block which is > in the function. There seems to be some problem with scope here. I made the > $option_block variable global but it still won't print. I have tested that > the $column field is being populated and it is, so I believe that it must be > the $option_block part that isn't working. Does anyone have any suggestions? > > Peter Gumbrell > [EMAIL PROTECTED] > > > > -- > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function problem
Exactly where does $option_block get put into $string? -Kevin - Original Message - From: "Peter Gumbrell" <[EMAIL PROTECTED]> To: "Php-General" <[EMAIL PROTECTED]> Sent: Friday, February 14, 2003 4:11 PM Subject: [PHP] function problem > I have a function below which populates a select list, based on the query > string and the field name. It then prints a string: > > function populate_selects($query_name, $db_field, $link, $string) > { > $result = mysql_query($query_name, $link) or die ("Could not execute > query."); > while ($columns = mysql_fetch_array($result)) > { > $column = $columns[$db_field]; > global $option_block; > $option_block .= " value=\"$column\">$column\n"; > } > print $string; > } > > Part of the string that is printed in $string is the $option_block which is > in the function. There seems to be some problem with scope here. I made the > $option_block variable global but it still won't print. I have tested that > the $column field is being populated and it is, so I believe that it must be > the $option_block part that isn't working. Does anyone have any suggestions? > > Peter Gumbrell > [EMAIL PROTECTED] > > > > -- > 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] Function Problem
Hey, Of course they do, they work if I put the echo in the function its self, but I dont need the echo in the function. - Lee "Marco Tabini" <[EMAIL PROTECTED]> wrote in message news:1036911387.23753.1054.camel@;localhost.localdomain... > Either add > > global $db; > > as the first line of the function or change your function call to: > > $db = db_conn("$host","$user","$pass","$dab"); > > I assume that $host, $user, $pass and $dab actually contain some correct > values. > > > Marco > -- > > php|architect - The magazine for PHP Professionals > The first monthly worldwide magazine dedicated to PHP programmers > Check us out on the web at http://www.phparch.com > > > > On Sun, 2002-11-10 at 01:58, conbud wrote: > > 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] Function Problem
Either add global $db; as the first line of the function or change your function call to: $db = db_conn("$host","$user","$pass","$dab"); I assume that $host, $user, $pass and $dab actually contain some correct values. Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Sun, 2002-11-10 at 01:58, conbud wrote: > 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] function problem ...
Try require_once($your_file) or verify in $your_file use the function function_exists() []'s Frederico Augusto Costa [EMAIL PROTECTED] On Wed, 7 Feb 2001, Miguel Loureiro wrote: > Hello > I have a script that use other script file(php) twice, I call a function with >certain parameters and call it again with other parameters and when runnig the >script, the first function works well, but on second time I got a error message: >"Fatal error: Cannot redeclare getndays() in Unknown on line 5". > Anyone kows what is my problem ??? > T.Y. > Miguel Loureiro <[EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]