Re: function problem

From: Date: Sun, 02 Jan 2005 22:33:06 +0000
Subject: Re: function problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-205475@lists.php.net to get a copy of this message
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: <?php include "script/functions.php"; require 'script/common.inc'; $valid = TRUE; 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


« previous php.general (#205475) next »