Jump to content

HDFilmMaker2112

Members
  • Posts

    547
  • Joined

  • Last visited

    Never

Posts posted by HDFilmMaker2112

  1. <?php
    
    $number = 1234.56;
    
    // let's print the international format for the en_US locale
    setlocale(LC_MONETARY, 'en_US');
    echo money_format('%i', $number) . "\n";
    // USD 1,234.56
    
    ?>

     

    http://php.net/manual/en/function.money-format.php

     

    This doesn't work when you want to format data entered in different formats. It won't accept a number with the comma as a decimal separator.

     

    I need to be able to accept various inputs:

    1234.56

    1234

    1,234.56

    1,234

    1.234,56

    1.234

     

    and have them all enter into the database as 1234.56

  2. I came up with this, based on something I copied from php.net. The only issue I have is when I enter a value of 1,234,567 it prints out twice.

     

    Like this:

    12345671234567

     

    <?php
    
    $convertnum="1,123,234.86";
    
    $bits = explode(",",$convertnum); // split input value up to allow checking
           
    $first = strlen($bits[0]); // gets part before first comma (thousands/millions)
    $last = strlen($bits[1]); // gets part after first comma (thousands (or decimals if incorrectly used by user)
           
            if ($last <3){ // checks for comma being used as decimal place
                $convertnum = str_replace(",",".",$convertnum);
            }
            else{ // assume comma is a thousands seperator, so remove it
                $convertnum = str_replace(",","",$convertnum);
            }
    
    $thousands = explode(".",$convertnum);    
    $period_count = count($thousands);
    if($period_count > 1){
    $convertnum=str_replace(".",",",$thousands[0]);
    }
    
    for($i=1; $i < $period_count-1; $i++){
    $convertnum.="".$thousands[$i];
    }
    
    $cent_count=strlen($thousands[$period_count-1]);
    if($cent_count < 3 && $period_count==$period_count){
    $convertnum.=".".$thousands[$period_count-1];
    }
    else{
    $convertnum.=$thousands[$period_count-1];
    }
    echo $convertnum; // redefine the value of the variable, to be the new corrected one 
    
    ?>
    

  3. I'm looking to know if preg_replace would be the best option to format a users input of a money amount?

     

    With multiple different types of entries, it seems it may not work.

     

    IE:

    The four currency formats I know of:

     

    1,200.94

    1,200

    1.200,94

    1.200

     

     

    How would I be able to replace the decimals and commas, without messing up their positioning?

     

    I want to end up with a number formatted in the 1,200.94 format.

  4. Alright, now it works briefly. I can log-in, click a few links come back, and it's fine. Click a few more and come back, and it's now the log-in form again. It's like the session last for about 15 seconds.

     

     

    EDIT: Got it. Thanks for the help.

     

     

    <?php
    require_once 'func.php';
    session_start();
    
    print_r($_SESSION);
    
    if(isset($_SESSION['myusername2']) && kam3($_POST['password'])==$_SESSION['mypassword2'] || isset($_SESSION['myusername2']) && $_SESSION['mypassword3']==$_SESSION['mypassword2']){
    if(!empty($_POST['password'])){
    $_SESSION['mypassword3']=kam3($_POST['password']);
    }
    
    $content.='
    <div class="main">
    <div class="main_header">Admin CP</div>
    
    </div>
    ';
    }
    
    else{
    $content='
    <table class="actors_table">
    <tr>
    <td align="center">';
    
    if(isset($_GET['e']) && $_GET['e']=="0")
    {
    $content .= '<span style="color: #FF0000; font-weight: bold;">Incorrect Username or Password</span><br/><br/>';
    } 
    
    else{
    $content .="";
    }
    
    $content .='Re-Type your password to view this information:
    <form action="" method="post">
        <p>Username: <input type="text" name="username" value="'.$_SESSION['myusername2'].'" disabled="disabled" /></p>
    <p>Password: <input type="password" name="password" /></p>
        <p><input type="submit" value="Submit" name="Submit" /></p>
        </form>
    
    </td>
    </tr>
    </table>
    ';
    }
    ?>
    

  5. print_r() your $_POST and $_SESSION arrays and look at the output to see if there's any reason for a conditional not to do what you'd expect it to do.

     

    The hashed passwords mypassword2 and mypassword3 have different values. Once I log-in each time they're identical, click to another page, and come back to the form, they're different again.

     

    I think it's because the POST is assigning to the mypassword3 session outside the if statement, so therefore when come back to the page after clicking away, it's a hashing a blank entry thus giving a different hashed value.

  6. Have you checked what your code, variables, and data are doing? You are the only one here who has access to your code and database on your server and you are the only one here who can troubleshoot what your code, variables, and data are doing.

     

    What value is in $count_details? If it is not 1 like you expect, why not echo/var_dump it and see what value it actually is?

     

    What is in $details_result, a FALSE because the query failed due to an error or a result resource?

     

    Is the query in $check_details what you expect and is the username/password data in your database table the same as what is in the query?

     

    Looks like:

     

    echo $details_result; = a resource id

    echo $count_details; = 0

  7. I cut it down to this, and it logs in once, but if you click away from the page and come back, the form comes up again, as if the session was never set.

    <?php
    require_once 'func.php';
    session_start();
    $_SESSION['mypassword3']=kam3($_POST['password']);
    if(isset($_SESSION['myusername2']) && $_SESSION['mypassword3']==$_SESSION['mypassword2']){
    
    $content.='
    <div class="main">
    <div class="main_header">Admin CP</div>
    
    </div>
    ';
    }
    
    else{
    $content='
    <table class="actors_table">
    <tr>
    <td align="center">';
    
    if(isset($_GET['e']) && $_GET['e']=="0")
    {
    $content .= '<span style="color: #FF0000; font-weight: bold;">Incorrect Username or Password</span><br/><br/>';
    } 
    
    else{
    $content .="";
    }
    
    $content .='Re-Type your password to view this information:
    <form action="" method="post">
        <p>Username: <input type="text" name="username" value="'.$_SESSION['myusername2'].'" disabled="disabled" /></p>
    <p>Password: <input type="password" name="password" /></p>
        <p><input type="submit" value="Submit" name="Submit" /></p>
        </form>
    
    </td>
    </tr>
    </table>
    ';
    }
    
    ?>
    

  8.  

    The below is giving an error, saying that the password is incorrect. I know for a fact it's correct.

    <?php
    if(isset($_SESSION['myusername2']) && isset($_SESSION['mypassword3'])){ 
    
    $content.='
    <div class="main">
    <div class="main_header">Admin CP</div>
    
    </div>
    ';
    }
    
    else{
    $content='
    <table class="actors_table">
    <tr>
    <td align="center">';
    
    if(isset($_GET['e']) && $_GET['e']=="0")
    {
    $content .= '<span style="color: #FF0000; font-weight: bold;">Incorrect Username or Password</span><br/><br/>';
    } 
    
    else{
    $content .="";
    }
    
    $content .='Re-Type your password to view this information:
    <form action="./adminlogin.php" method="post">
        <p>Username: <input type="text" name="username" value="'.$_SESSION['myusername2'].'" disabled="disabled" /></p>
    <p>Password: <input type="password" name="password" /></p>
        <p><input type="submit" value="Submit" name="Submit" /></p>
        </form>
    
    </td>
    </tr>
    </table>
    ';
    }
    ?>
    

     

     

    <?php
    require_once 'db_select.php';
    require_once 'func.php';
    session_start();
    // username and password sent from form 
    $myusername=sanitize($_POST['username']); 
    $mypassword=sanitize($_POST['password']); 
    
    $check_details="SELECT * FROM $tbl_name WHERE username='$myusername' AND password='$mypassword'";
    $details_result=mysql_query($check_details);
    
    
    // Mysql_num_row is counting table row
    $count_details=mysql_num_rows($details_result);
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count_details==1){
    $_SESSION['mypassword3']=$mypassword;
    header("location:index.php?usercp");
    }
    else{ 
    header('Location:./index.php?admincp&e=0'); 
    } 
    ?>
    

  9. I think the issue is because it's a scroll table. Some of the left side of the table protrudes out further than other parts. Each row seems to have a slightly different width, when they're all set from the same CSS. It's not an issue at in IE.

     

     

     

    tablebump.png

     

    The above is just what I could get right now... occassionally it's much worse. It varies based on scrolling the table or scrolling the page.

  10. <?php
    
    // define menus
    $menu = array();
    $menu['user_investor'] = array("Films" => "$page.php?films","Webseries" => "$page.php?webseries","Company" =>"$page.php?company");
    $menu['user_donor'] = array("<a href='$page.php?contact'>Contact</a>","<a href='index.php?faq'>FAQ</a>","<a href='http://store.makethemoviehappen.com'>Store</a>");
    $menu['user_other'] = array("<a href='$page.php?donate'>Donate</a>","<a href='$page.php?contact'>Contact</a>","<a href='$page.php?faq'>FAQ</a>");
    
    // logic to determine which menu to use
    if(isset($_GET['test'])){
    $type = 'user_investor';
    } elseif(isset($_SESSION['myusername2'])){
    $type = 'user_donor';
    } else {
    $type = 'user_other';
    }
    
    $menu_text = array_keys($menu[$type]);
    
    // produce and output the correct menu
    
    $i=0;
    foreach(array_values($menu[$type]) as $link){
    echo '<div class="tab">';
    echo '<a href="'.$link.'">';
    echo $menu_text[$i];
    echo '</a>';
    echo "</div>";
    $i++;
    }
    ?>
    

  11. The below is out putting:

     

    FilmsWebseriesCompany - >?films

    FilmsWebseriesCompany - >?webseries

    FilmsWebseriesCompany - >?company

     

     

    I need it to iterate through each link name once.

     

     

    <?php
    
    // define menus
    $menu = array();
    $menu['user_investor'] = array("Films" => "$page.php?films","Webseries" => "$page.php?webseries","Company" =>"$page.php?company");
    $menu['user_donor'] = array("<a href='$page.php?contact'>Contact</a>","<a href='index.php?faq'>FAQ</a>","<a href='http://store.makethemoviehappen.com'>Store</a>");
    $menu['user_other'] = array("<a href='$page.php?donate'>Donate</a>","<a href='$page.php?contact'>Contact</a>","<a href='$page.php?faq'>FAQ</a>");
    
    // logic to determine which menu to use
    if(isset($_GET['test'])){
    $type = 'user_investor';
    $menu_text = array_keys($menu['user_investor']);
    } elseif(isset($_SESSION['myusername2'])){
    $type = 'user_donor';
    $menu_text = array_keys($menu['user_donor']);
    } else {
    $type = 'user_other';
    $menu_text = array_keys($menu['user_other']);
    }
    // produce and output the correct menu
    foreach($menu[$type] as $link){
    echo "<div class='tab'>";
    echo '<a href="'.$link.'">';
    
    for($i=0; $i <= count($menu_text); $i++){
    echo $menu_text[$i];
    }	
    
    echo '</a>';
    echo "</div>";
    }
    ?>
    

    \

  12. Here's what I ended up with... cut down on the redundant text as much as possible.

    <div class="tab">
    <a href="<?php echo $page; if(isset($_SESSION['myusername'])){ '.php?films">Films';}
    elseif(isset($_SESSION['myusername2'])){ echo '.php?contact">Contact';}
    else { echo '.php?donate">Donate';} ?> </a>
    </div>
    

  13. Looking to know if I should convert the below to a switch statements for efficiency? All the opening and closing php tags is getting to me.

     

    <div class="tab">
    <? if(isset($_SESSION['myusername'])){?> <a href="<? echo $page; ?>.php?films">Films</a><? } 
    elseif(isset($_SESSION['myusername2'])){?> <a href="<? echo $page; ?>.php?contact">Contact</a><? }
    else { ?> <a href="<? echo $page; ?>.php?donate">Donate</a> <? } ?>
    </div>
    <div class="tab">
    <? if(isset($_SESSION['myusername'])){?> <a href="index.php?webseries">Webseries</a><? }
    elseif(isset($_SESSION['myusername2'])){?> <a href="index.php?faq">FAQ</a><? } 
    else { ?> <a href="<? echo $page; ?>.php?contact">Contact</a> <? } ?>
    </div>
    <div class="tab">
    <? if(isset($_SESSION['myusername'])){?> <a href="index.php?company">Company</a><? } 
    elseif(isset($_SESSION['myusername2'])){?> <a href="http://store.makethemoviehappen.com">Store</a><? }
    else { ?> <a href="<? echo $page; ?>.php?faq">FAQ</a> <? } ?>
    </div>
    <div class="tab">
    <? if(isset($_SESSION['myusername'])){?> <a href="index.php?contact">Contact</a><? } 
    elseif(isset($_SESSION['myusername2'])){?> <a href="index.php?usercp">User CP</a><? }
    else { ?> <a href="<? echo $page; ?>.php?investors">Investors</a> <? } ?>
    </div>
    

  14. After reading some threads around the net I can't find a situable solutions for this.

    In my script I want to use a javascript code ( external source from another website ) and there's a JS variable with an ID ( the user ID in the other website).

     

    In my script I have the ID stored in the DB and I want to insert it in the javascript by the ID listed in the DB ( that can be changed, so there's the PHP needed )

     

    The JS code:

    <script>
    var siteID = 11111;
    
    all rest of code
    </script>

     

    How can I change the value of siteID in JS for the one I want? Lets say I would like something like:

     

    var siteID = <?php GetOtherSiteID(); ?>;

     

     

    This seems no to be possible. There's any sugestion?

     

    Does the php have line breaks in it?

    http://www.the-art-of-web.com/php/javascript-escape/

  15. I'm trying to set-up a function for me to choose which database to use, by place a call to the function with either number 1 or 2.

     

     

    $db_name="zyquo_donors"; // Database name 
    $db_name2="zyquo_investors";
    $tbl_name="donors"; // Table name 
    $tbl_name2="donors_credits";
    $tbl_name3="members";
    
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    
    function db_select($db="1"){
    if($db=="1"){
    mysql_select_db("$db_name")or die("cannot select DB");
    }
    elseif($db=="2"){
    mysql_select_db("$db_name2")or die("cannot select DB");
    }
    }
    

     

    and on the page I have:

     

    db_select("2");
    

     

    The result is:

    cannot select DB

  16. For some reason the first ternary operator is evaluating to false and running true for the second one, when $_SESSION['myusername']is set. Anybody see anything in the code below or is this an issue with the sessions being set.

     

    <? echo (isset($_SESSION['myusername'])) ? '<a href="'.$page.'.php?films">Films' : (isset($_SESSION['myusername2'])) ? '<a href="'.$page.'.php?contact">Contact' : '<a href="'.$page.'.php?donate">Donate'; ?></a>
    

×
×
  • 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.