Posts by ThomasNiven

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

When I take out the code for inserting an image. it all works fine. While that code is in there, nothing works. Sometimes if I switch the code around only the payment details will insert but no image. NEED HELP, it’s annoying me lol

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

Hi folks, I am looking for some help on a small project I am currently working on. The reason for this project is so that I can learn PHP. I am using PDO and i’m trying to insert images to a table while also inserting a business request into a separate table. The image does not insert into the DB an I think my logic is a little wrong as I am first checking to see if the fields are empty, then I check if the card number is < = 15 or >= 17, as a bank card number is 16 long. The next part I check is if the expiry date is <= 4 or >= 6, after this I check to see if the CVV (Security code) is <= 2 or >= 4. All of this data is obviously made up, just random. After I have checked all of those I then check to see if row[‘c’] >= 4 and the card number starts with 99. (row[‘c’] is checking if the premium listing slots are all taking (there can only be a maximum of 4 slots.) If they are all taking the listing type will be set to ‘1’ (a normal business listing). If not then we continue the script. The next part checks if the card number is set to 99. If it is then it will insert all of the data, including the image to the DB. This is my logic but I’m not sure I have done it all correctly within my page. This is my payment page (is quite long though)

<?php
session_start();
error_reporting(E_ALL);

include_once('connect.php');

// CHECK IF THE SESSION ID IS SET
if(isset($_SESSION['id'])) {
    $id = $_SESSION['id'];
}

// POST INPUT STRING TO VARIABLES
$cat = $_GET['cat'];
$list = $_GET['radio'];

$norm_li = 'unchecked';
$prem_li = 'unchecked';

if ($list == 1) {
    $value = '£10 for a normal business listing';
}
else if ($list == 2) {
    $value = '£50 for a premium business listing';
}

if (empty($cat)){
    echo '<p style="font-family: Arial; text-align: center;">Please enter a category</p>';
    echo '<p style="font-family: Arial; text-align: center;">Redirecting...</p>';
    header('refresh:3;url=dashboard.php');
}
else {

    // SELECT MATCH FROM THE DATABASE
    $querymatch = "SELECT * FROM category where cat_name=?";            
    $statementmatch = $con->prepare($querymatch);
    $statementmatch->execute(array(
        $cat
    ));

    if($statementmatch->rowCount() > 0) {

    $data = $statementmatch->fetch(PDO::FETCH_ASSOC);
    ?>

        <!Doctype html>

            <head>
            <title></title>
            <!-- Styles -->
            <link rel="stylesheet" href="assets/css/styles.css"/>

            <!-- Scripts -->
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- jQuery Core -->

            <script>
            $(document).onload(function(){

                $(window).resize(function(){
                    $('.className').css({position:'absolute', left: ($(window).width() 
                    - $('.className').outerWidth())/2,
                    top: ($(window).height() 
                    - $('.className').outerHeight())/2
                    });
                });

                // To initially run the function:
                $(window).resize();
            });
            </script>

            </head>
            <body style="background: rgba(0, 0, 0, 0.7);">
                <div class="payment">
                    <h3>What you have selected</h3>
                    <p name="pay_cat" style="width: 100%; display: block; text-align: center;"><?php echo 'You have selected your category as '.$cat; ?></p>
                    <p name="pay_list" style="width: 100%; display: block; text-align: center; line-height: 22px;">
                    <?php
                        // CHECK TO SEE IF THERE ARE 4 PREMIUM LISTINGS
                        $sql = "SELECT COUNT(*) AS c FROM payment WHERE listing_type = 2";
                        $stm = $con->prepare($sql);
                        $stm->execute();
                        $row = $stm->fetch(PDO::FETCH_ASSOC);

                        // IF THERE IS 4 PREMIUM LISTINGS (MAXIMUM)
                        if($list == 2 && $row['c'] >= 4) {
                            echo 'Our premium list is currently full. We have transfered <br />you to a normal business listing.';
                        }
                        // IF THERE IS A PREMIUM SPACE, CREATE A NEW VARIABLE
                        else {
                            echo 'You agree to pay '.$value;
                        }
                    ?></p>

                    <div class="method">
                        <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"><br /><br />
                            <h3>Enter your bank details</h3>

                            <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
                            <input name="fileup" type="file" />

                            <label>Card number</label>
                            <input type="text" name="cardNo" placeholder="Enter"><br />

                            <label>Expiry date</label>
                            <input type="text" name="expiry" placeholder="Enter"><br />

                            <label>CVV</label>
                            <input type="text" name="cvv" placeholder="Enter"><br />

                            <button class="btn" type="input" name="submit" value="pay_now">Pay Now</button>
                            <button class="btn grey" type="reset">Reset Form</button>

                            <div>

                                <?php

                                $uploadpath = 'uploads/';      // directory to store the uploaded files
                                $max_size = 2000;          // maximum file size, in KiloBytes
                                $alwidth = 900;            // maximum allowed width, in pixels
                                $alheight = 800;           // maximum allowed height, in pixels
                                $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png');        // allowed extensions

                                if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
                                    $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);       // gets the file name
                                    $sepext = explode('.', strtolower($_FILES['fileup']['name']));
                                    $type = end($sepext);       // gets extension
                                    list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);     // gets image width and height
                                    $err = '';         // to store the errors

                                // IF THE SUBMIT BUTTON HAD BEEN CLICKED AND THE VALUE IS = TO PAY_NOW
                                    if(isset($_POST['submit']) && $_POST['submit'] == 'pay_now') {
                                        $cat_name = $_GET['cat'];
                                        $list_val = $_GET['radio'];

                                        $card = $_POST['cardNo'];
                                        $expiry = $_POST['expiry'];
                                        $cvv = $_POST['cvv'];

                                        // SETTING THE TIME ZONE FOR INPUTING THE DATE INTO THE DB
                                        date_default_timezone_set('Europe/London');
                                        $date = date("d-m-y");

                                        if(empty($card) || empty($expiry) || empty($cvv)) {
                                            echo '<div class="error">Please fill out all fields</div>';
                                        }
                                        else if(strlen($card) <= 15) {
                                            echo '<div class="error">Card number is to short</div>';
                                        }
                                        else if(strlen($card) >= 17) {
                                            echo '<div class="error">Card number is to long</div>';
                                        }
                                        else if(strlen($expiry) <=4) {
                                            echo '<div class="error">Expiry date is to short</div>';
                                        }
                                        else if(strlen($expiry) >=6) {
                                            echo '<div class="error">Expiry date is to long</div>';
                                        }
                                        else if(strlen($cvv) <=2) {
                                            echo '<div class="error">Security code is to short</div>';
                                        }
                                        else if(strlen($cvv) >=4) {
                                            echo '<div class="error">Security code is to long</div>';
                                        }
                                        // IF THERE IS 4 PREMIUM LISTINGS (MAXIMUM)
                                        else if ($row['c'] >= 4 && substr($card, 0, 2) == 99) {
                                            // INSERT INFO INTO THE DATABASE
                                            $query = "INSERT INTO payment SET pay_id='' , user_id='$id' , listing_type='1' , category=? , card_no=? , expiry=? , cvv=? , date='$date' , accepted='In Progress'";    
                                            $statement = $con->prepare($query);
                                            $statement->execute(array(
                                                $cat_name,
                                                $card,
                                                $expiry,
                                                $cvv
                                            ));

                                            // IT'S ALL GOOD
                                            echo '<div class="success">Payment Successful</div>';
                                            header('refresh:3;url=dashboard.php');
                                        }
                                        else if (substr($card, 0, 2) == 99) {

                                        // Checks if the file has allowed type, size, width and height (for images)
                                        if(!in_array($type, $allowtype)) $err .= '<div class="error">Invalid extention type</div>';
                                        if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<div class="error">File is too large. Max size '. $max_size. ' KB.</div>';
                                        if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<div class="error">Max width x height is </div>'. $alwidth. ' x '. $alheight;

                                            // INSERT INFO INTO THE DATABASE
                                            $query = "INSERT INTO payment SET pay_id='' , user_id='$id' , listing_type=? , category=? , card_no=? , expiry=? , cvv=? , date='$date' , accepted='In Progress'";    
                                            $statement = $con->prepare($query);
                                            $statement->execute(array(
                                                $list_val,
                                                $cat_name,
                                                $card,
                                                $expiry,
                                                $cvv
                                            ));

                                            // If no errors, upload the image, else, output the errors
                                            if($err == '') {
                                                if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {

                                                    $path = $_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath;
                                                    $name = $_FILES['fileup']['name'];
                                                    $type = end($sepext);

                                                    $sql = "INSERT INTO uploads SET user_id = '$id', img_name = '$name', img_type = '$type', img_path = '$path'";
                                                    $statement = $con->prepare($sql);
                                                    $statement->execute();

                                                    echo '<div class="success">Payment Successful</div>';
                                                    header('refresh:3;url=dashboard.php');

                                                //echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
                                                //echo '<br />File type: <b>'. $_FILES['fileup']['type'] .'</b>';
                                                //echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
                                                //if(isset($width) && isset($height)) echo '<br />Image Width x Height: '. $width. ' x '. $height;
                                                //echo '<br /><br />Image address: <a href="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'">Click to view '.$name.'</a>';
                                                }
                                                else {
                                                    echo '<div class="error">Unable to upload file</div>';
                                                    echo $err;
                                                }
                                            }
                                        }
                                        else {
                                            echo '<div class="error">Card does not start with 99</div>';
                                        }
                                    }
                                }
                                ?>
                            </div>
                        </form>
                    </div>
                </div>

                <div class="closer">
                    <a href="index.php"><img alt="Closer" src="assets/img/closer.png" /></a>
                </div>

<?php 
    }
    else {
        echo '<p style="font-family: Arial; text-align: center;">No such category in DB. Please enter another</p>';
        echo '<p style="font-family: Arial; text-align: center;">Redirecting...</p>';
        header('refresh:3;url=dashboard.php');
    }
}
?>

Here is an image of what it looks like in action:

error with payment: error page

successful payment: success page

any help is very much appreciated :)

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

Can’t seem to find you. What do you need to help me? You need my tables in my DB?

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says
I need some way of getting my pagination to send me to another page where it will then tell me if there is a business that is in a specific category. I f there is then it will display the business information, such as name, address and postcode. Here is my pagination:
<?php
error_reporting(E_ALL);

include('connect.php');

// IF THE PAGE IS NOT SET, SET IT TO 1
$page = isset($_GET['page']) ? $_GET['page'] : 1;

// SET RECORDS PER PAGE
$perPage = 15;

// CALCULATE FOR THE QUERY LIMIT CLAUSE
$recordNum = ($perPage * $page) - $perPage;

// SELECT ALL DATA FROM THE CATEGORY TABLE, ORDER IT BY THE CATEGORY NAME
$query = "SELECT * FROM category ORDER BY cat_id asc LIMIT {$recordNum}, {$perPage}";

$statement = $con->prepare($query);
$statement->execute();

// GET THE NUMBER OF ROWS RETURNED
$num = $statement->rowCount();

// CHECK IF ROWS RETURNED IS GREATER THAN 0
if($num > 0){

    while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
        // CREATING A NEW INSTANCE PER RECORD
        echo "<a href="#"><div class="category">";
            echo '<p id="center">'.$row['cat_name'].'</p>';
        echo "</div></a>";
    }
    echo "<div class="row">";
    echo "<div id="paging">";

        if($page > 1){
            // SHOW THE PREVIOUS BUTTON
            $prev_page = $page - 1;
            echo "<a href="" . $_SERVER[" php_self="" .="" title="Previous page is {$prev_page}." class="customBtn">";
                echo "<span style="margin:0 7px;"> Prev </span>";
            echo "</a>";

        }

        // FIND THE TOTAL PAGES
        $query = "SELECT COUNT(*) as total_rows FROM category";
        $statement = $con->prepare( $query );
        $statement->execute();

        $row = $statement->fetch(PDO::FETCH_ASSOC);
        $total_rows = $row['total_rows'];

        $total_pages = ceil($total_rows / $perPage);

        // RANGE OF NUMBER OF LINKS TO SHOW
        $range = 2;

        // DISPLAY NUMBER OF LINK TO THE RANGE OF PAGES AND WRAP AROUND THE CURRENT PAGE
        $initial_num = $page - $range;
        $condition_limit_num = ($page + $range)  + 1;

        for ($x = $initial_num; $x < $condition_limit_num; $x++) {

            // SETTING THE CURRENT PAGE
            if (($x > 0) && ($x <= $total_pages)) {

                // DISPLAY CURRENT PAGE
                if ($x == $page) {
                    echo "<span class="customBtn" style="background: #5BC5AC;">$x</span>";
                }
                else {
                    echo " <a href="{$_SERVER[" php_self="" class="customBtn">$x</a> ";
                }
            }
        }

        if($page < $total_pages){
            // DISPLAY NEXT PAGE
            $next_page = $page + 1;
            echo "<a href="" . $_SERVER[" php_self="" .="" title="Next page is {$next_page}." class="customBtn">";
                echo "<span style="margin:0 .5em;"> Next </span>";
            echo "</a>";
        }
        echo "</div>";
        echo "</div>";
        echo "";
}
else{
    echo "<div class="noneFound">No records found.</div>";
}
?>
This is the outcome of that page: sample image

So for example if a user clicks on accountants, they will be took to another page and all of the business that have signed up for a listing in that category will be displayed.

Any help is much appreciated as I am still learning PHP and PDO. Thanks in advance.

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

I am looking for the best way to check if my input starts with 99. I am currently using PDO and I am new to PHP so this is a little difficult for me. Can anyone help me out?

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

Its OK now just send the information to the same page. Had to edit my code a little but it all works now. Thanks anyway.

I do still have one slight problem though. I can’t seem to get a paragraph to center. The paragraph is echoed out in PHP, I have used inline styles as well as CSS to try to get this centered. Somehow it doesn’t seem to be playing ball :(

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

Hello folks. I need to find a way of passing a variable through to another PHP page. I’m not sure how to go about this. Do I use sessions or perhaps declare a global variable. I am using PDO and need to get a variable named $pay_id which is = to $data[‘pay_id’];

This is the admin page script:
<?php
                                    // SELECTING ALL DATA FROM THE PAYMENT TABLE WHERE THE USER ID MATCHES THE CURRENT SESSION
                                    $query = "SELECT *
                                                FROM payment a
                                                INNER JOIN users b ON a.user_id = b.user_id
                                                WHERE accepted='In Progress'";
                                    $statement = $con->prepare($query);
                                    $statement->execute();

                                    // WHILE THE QUERY IS TRUE
                                    while($data = $statement->fetch(PDO::FETCH_ASSOC)) {

                                        // IF THERE IS NO ROWS TO RETURN THEN ECHO THE ERROR
                                        if($statement->rowCount() <= 0) {

                                            echo '<tr class="task">
                                                    <td class="cell-icon" />
                                                    <td class="cell-detail"><p>No results to display</p></td>
                                                    <td class="cell-id" />
                                                    <td class="cell-date" />
                                                    <td class="cell-app" />
                                                </tr>';
                                        }
                                        else if($statement->rowCount() > 0) {

                                            $pay_id = $data['pay_id'];

                                            // CREATING A STRING FOR THE LISTING TYPE
                                            if($data['listing_type'] == 1) {
                                                $data['listing_type'] = 'normal';
                                            }
                                            else if($data['listing_type'] == 2) {
                                                $data['listing_type'] = 'premium';
                                            }
                                            // ECHO WHAT THE BUSINESS HAS PURCHASED 
                                            echo '<tr class="task">';
                                            echo '<td class="cell-icon fa fa-circle-o" />';
                                            echo '<td class="cell-detail"><div>'.$data['business'].' has bought a '.$data['listing_type'].' listing in the '.$data['category'].' category.</div></td>';
                                            echo '<td class="cell-id">'.$pay_id.'</td>';
                                            echo '<td class="cell-date"><div>'.$data['date'].'</div></td>';
                                            echo '<td class="cell-app">';
                                            ?>
                                            <form action="listings.php" method="post">
                                                <button type="input" name="submitA" value="approve" class="fa-btn btn-green"><i class="fa fa-check fa-lg" /></button>
                                                <button type="input" name="submitB" value="decline" class="fa-btn btn-red"><i class="fa fa-trash-o fa-lg" /></button>
                                            </form>
                                            <?php
                                            echo '</td>';
                                            echo '</tr>';
                                        }
                                        else {

                                        }
                                    }
                                ?>
This is the listing.php page:
$approve = $_POST['submitA'];
// $decline = $_POST['submitB'];

$_GET['pay_id']; // This does not work

if(isset($_POST['submitA']) && $_POST['submitA'] == 'approve') {

    $queryapp = "UPDATE payment SET accepted = 'approved' WHERE pay_id ='$id'";
    $statementapp = $con->prepare($queryapp);
    $statementapp->execute();

    echo '<p style="font-family: Arial; text-align: center;">Listing approved</p>';
    echo '<p style="font-family: Arial; text-align: center;">Redirecting...</p>';
    header('refresh:3;url=admin.php');
}

As you can see I have commented the line which does not work. ”$_GET[‘pay_id’];” I have tried this a few different ways myself but can’t seem to figure out the best way of doing this.

Please feel free to change any part of either script if it means it may work for me. Thanks in advance :)

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

How do I convert this so that it is set to dd/mm/yyyy

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

The date field in my DB has been set the type of ‘date’.

66 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
ThomasNiven
says

I am posting here to ask for some help off of the lovely community here. I am trying to insert the current date into my DB when a user submits a form. The date does insert to the DB but the formatting is wrong. I am hoping someone may be able to help me with this. I am looking to have my date set as London GMT (09-04-2015) but instead I am getting the correct date but slightly different format. I currently get this (2009-04-15) As you can see the are the same (current date) just not the way I would like.

I’m not sure if this is a PHP problem or a configuration problem with easy PHP. However the code I have is below:

date_default_timezone_set('Europe/London'); $date = date("d-m-y");
by
by
by
by
by
by