Jump to content

adrianTNT

Members
  • Posts

    146
  • Joined

  • Last visited

Posts posted by adrianTNT

  1. [quote author=Jenk link=topic=107362.msg430706#msg430706 date=1157733786]
    you don't have to, you can 'call upon' them within the function with the global key word..

    change to:[code]<?php

    function get_balance($the_user_id){
                global $database_affiliates, $affiliates;
    mysql_select_db($database_affiliates, $affiliates);

    ?>[/code]
    [/quote]
    Yes, that worked fine, I didn't knew that I have to access them from an upper level when working in a function.
    I also tried to send them in the function parameters when defining the function and when calling the function, that also worked; but your metod is better.

    Thank you very much. :)
  2. [b]Jenk[/b], the other variables $database_affiliates, $affiliates are defined above in the rest of the code, if these variables are inside the function do I have to send them to the function each time I call it?

    [b]Predator[/b], I don't know... I think I am not passing the user data to the function correctly. I tried to define the user_id before I call the function
    [code]<?php
    $the_user_id="1";
    echo get_balance($the_user_id);
    ?>[/code]
    But I get same errors.
  3. Hello,

    I have this php code... it reads a table "transactions", calculates the sum of the transactions where transactions belong to a certain user ID and should return the SUM of the transactions.

    Code I have now is:
    [code]
    <?php
    mysql_select_db($database_affiliates, $affiliates);
    $query_Recordset_total_to_pay = "SELECT SUM(tr_amount) FROM transactions WHERE tr_user_id = '1'";

    $Recordset_total_to_pay = mysql_query($query_Recordset_total_to_pay, $affiliates) or die(mysql_error());
    $row_Recordset_total_to_pay = mysql_fetch_assoc($Recordset_total_to_pay);
    $totalRows_Recordset_total_to_pay = mysql_num_rows($Recordset_total_to_pay);

    $arr = $row_Recordset_total_to_pay;
    $sum = 0;
    foreach($arr as $element){
    $sum += $element;
    }
    $total_to_pay=$sum;
    ?>
    [/code]
    The above code works ok and shows the SUM of transactions for USER ID "1".
    I want to place that code block in a function so that I can find the transactions sum for a given user ID.
    [code]
    <?php
    function get_balance($the_user_id){
    mysql_select_db($database_affiliates, $affiliates);
    $query_Recordset_total_to_pay = "SELECT SUM(tr_amount) FROM transactions WHERE tr_user_id = '".$the_user_id."'";

    $Recordset_total_to_pay = mysql_query($query_Recordset_total_to_pay, $affiliates) or die(mysql_error());
    $row_Recordset_total_to_pay = mysql_fetch_assoc($Recordset_total_to_pay);
    $totalRows_Recordset_total_to_pay = mysql_num_rows($Recordset_total_to_pay);

    $arr = $row_Recordset_total_to_pay;
    $sum = 0;
    foreach($arr as $element){
    $sum += $element;
    }
    $total_to_pay=$sum;
    return $total_to_pay;
    }
    ?>

    <?php
    // now trying to get the transactions sum (balance) for user id 1
    echo get_balance(1);
    ?>
    [/code]

    The second code returns these errors:
    [b]Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/adriantnt.com/httpdocs/affiliates/admin_users.php on line 59

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/vhosts/adriantnt.com/httpdocs/affiliates/admin_users.php on line 62[/b]
    Maybe I didnt place the code block in the function correctly or I incorrectly used the "return"?!
    I am still new to php, any help is appreciated.

    - Adrian.
  4. I got to another issue, I hope one of you can help :)
    I needed to display records between two given dates, it works fine.
    Then I added this code...
    if start and end date ranges are not set then end_date is today and start_date is 7 days ago; so that by default it displays records for last 7 days.
    [b]Is there a function to decrease 7 days from a date like '2006-09-06 00:00:00' ?[/b] A code block is also nice if there isn't a function for this :)

    Thanks.
    - Adrian.
  5. I made some more experiments while waiting a reply, I got to something that worked by this code:

    [code]<?php
    $start_date = ($start_year.'-'.$start_month.'-'.$start_day.' '.$start_hour.':'.$start_minutes.':'.$start_seconds);
    $end_date = ($end_year.'-'.$end_month.'-'.$end_day.' '.$end_hour.':'.$end_minutes.':'.$end_seconds);
    // add some slashes needed in query format
    $start_date="'".$start_date."'";
    $end_date="'".$end_date."'"; ?>
    [/code]
    Then lower in code I have:
    [code]<?php
    $query_Recordset_transactions = sprintf("SELECT * FROM transactions WHERE tr_user_id = %s AND tr_date BETWEEN $start_date and $end_date", GetSQLValueString($colname_Recordset_transactions, "text")); ?>
    [/code]
    This works for now so I will use this one if it will not generate problems.
    Thanks for both your replies.
  6. Hello.
    In my database I have records (transactions) that have a transaction_date field.
    The transaction_date filed value is formatted like this: "2006-09-15 00:00:00"
    I will send the month, day and year as URL variable (I will send both start date and end date)
    [b]How should the PHP code look in order to show only the records in that date range?[/b] ???
    Thank you.

    - Adrian.
  7. [quote author=fenway link=topic=106526.msg426084#msg426084 date=1157132604]
    Well, you have a die() statement -- just write a custom handler.
    [/quote]
    Thanks Fenway, so I guess I have to replace
    die(mysql_error());
    with myfunction(); ?!
    Another question in this case...
    What php code do I need in order to open an URL?
    So that I replace the "die" block with something like:
    [b]Open url : message.php?message=Error, user already exists.[/b]
    How can I open the URL by php code?

    Thank you.
  8. Hello.

    I made a membership signup form. (I dont have many PHP+MySQL skills, this was made in Dreamweaver).
    The user completes a form to signup (signup.php).
    If the new user is successfully created then is sent to message.php telling him that the new username was created.
    BUT
    If the username entered is already in database then the singup.php page replaces all site layout content and posts the error
    [b]"Duplicate entry 'Adrian' for key 2".[/b]

    How can I handle these errors so that if the username is already taken then the visitor is sent to
    [b]message.php?message=Username Taken[/b]
    Rather than showing the ugly SQL error on page.

    Thank you.
    - Adrian.

    I dont know if this helps, the code I have now on signup.php:

    [code]

    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO affiliates (aff_full_name, aff_user_name, aff_email, aff_pass) VALUES (%s, %s, %s, %s)",
                          GetSQLValueString($_POST['full_name_box'], "text"),
                          GetSQLValueString($_POST['username_box'], "text"),
                          GetSQLValueString($_POST['email_box'], "text"),
                          GetSQLValueString($_POST['pass_box'], "text"));

      mysql_select_db($database_affiliates, $affiliates);
      $Result1 = mysql_query($insertSQL, $affiliates) or die(mysql_error());

      $insertGoTo = "message.php?message=New username created successfully.&type=info";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }

    [/code]

  9. [quote author=corbin link=topic=103482.msg412114#msg412114 date=1155078236]
    Uhhh from your description of your problem it seems to me like you have an un-needed step... Why not have 2co.com send the info straight to your final site that is involved?
    [/quote]
    Because as I said above "this script needs to be on a certain site, the site that is set in my account".
    2Co, the processor, says that they will only send the variables to my main domain, but I need it to send the variables to another domain, so I tricked them :) I made it send to my main domain as they request but that script forwards it to another domain, they do not let me send directley to that domain because is not the one that I have set in my 2co.com account profile. It worked ok with your script :)
  10. Thanks for the replies guys.

    HeyRay2, I will try to explain why I needed this and how it worked.
    2Co.com (payment processor) asks for a script where it sends the payment info, this script needs to be on a certain site, the site that is set in my account. But i have more domains, one is a photo store. The photo store is at a different URL, so I told 2CO: "[b]OK, Send the payment data to www.mysite.com/redirector.php" and redirector.php reads all the data that 2CO sent and forwards it to where I needed it (to the photo store site to a certain script)[/b].
    The script at the end should be safe because it checks back with 2CO to see if info it received is same as on 2CO server so only after that it sends emails to buyers and process the order.


    [b]I just tried corbin's solution (above code) and worked perfect so far,[/b] I think everything is OK now.

    Thanks for all the replies, I posted first time here and looks like a nice forum.
  11. Hello.

    The script I am trying to modify is an "Instant Payment Notiffication" script for 2checkout.com (like paypal.com), when I sell something this IPN service sends info to my site, variables contain order amount, client name, amount paid, so that my scrit can process the order and send emails, etc.

    2co.com sends variables to my site (by Post I think) but for some reason I need to forward that to another URL that will process the variables, I suppose this second URL reads the variables by GET, as I said I dont know much about php and get/post. Let me know if you need more info, maybe the script code would help.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.