mmcdonald 28 Posting Pro

Thanks for that, it makes a lot of sense nexocentric. One thing I would like to be aware of is avoiding this all over the shop: $mysqli = new mysqli("localhost", "my_user", "my_password", "world");. I believe the term is OOP - how can I declare my DB connection once in the config and use it wherever on my website? Does a simple variable do the trick or do I turn that into a function and just delcare the function before any DB query?

As for:

One downfall of doing it this way is, every time you include config.php you will hit your database with a query.

Would it be better to define these once when the user logs in? Can you store an array as a session? Would this be the best method? I really appriciate your feedback so thank you.

mmcdonald 28 Posting Pro

Didn't refresh before posting this, thanks for reponses I'll look into it and post back soon.

M.

mmcdonald 28 Posting Pro

Hi all,

I've been playing around with this for 30 odd minutes now and basically been making a right fool of myself...

I want to make a function called userInfo() that uses the users email address, stored in $_SESSION['auth'];, to get any information required from sql. I'm using MySQLi and I'm very new to it (started this morning).

So basically, the function userInfo(); in config.php should create an array of that users info. When I need the username of the user I should be able to type $userInfo['username']; or $userInfo['landline']; to get the landline of the user anywhere on a page that has config.php included.

Now looking at the below example from php.net I know I need an associative array. What I don't udnerstand is keeping the array alive for the pages lifespan so that I can easily display array values anywhere. I've dedited the query below to match my actual SQL query.

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

$query = "SELECT * FROM users WHERE email = '".$_SESSION['authenticated_user']."'";
$result = $mysqli->query($query);

/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);

/* free result set <--- Do I just delete this? */ 
$result->free();

/* close connection <--- Does closing the connection destroy the retrieved values? */
$mysqli->close();
?>

Can anyone please help?

Thanks in advance!

mmcdonald 28 Posting Pro

Hi all,

I'm using crontab on Ubuntu 10.04 and I have had 7 tasks running smoothly for about 6 months. I've now created a new script but for some frustrating reason it will be execute. It's a small task that needs to run every two minutes. The issue doesn't reside with the code as if I execute the script manually it works perfectly. The script is written in PHP and I'm running Apache2.

This works fine:
*/5 * * * * php -q /var/tasks/PEQ.php

This does not:
*/2 * * * * php -q /var/tasks/SSC.php

There are no errors being reported by the script, which has error reporting on, and there are no errors being logged by crontab.

Any ideas?

Thanks in advance!

mmcdonald 28 Posting Pro

Thanks pritaeas! I let out my JS file ^^

<script src="javascripts/jquery.form.js" type="text/javascript"></script>
mmcdonald 28 Posting Pro

could you explain me breifly somemore what the requirement is?

The form should post it's data to contact_me.php, currently it's not even responding. It's acting as a button that's not even in form tags.

mmcdonald 28 Posting Pro

My form won't submit... nothing happens when clicking the submit button. Any ideas? N.B. I am knackered, I've been up 26 hours :/

Thanks in advance for any suggestions!

        <form action="contact_me.php" method="post" class="contact-form" id="contactForm">
          <div class="controls controls-row">
            <div class="control-group span6">
              <input class="span12" name="name" placeholder="your name" type="text" />
            </div>
            <div class="control-group span6">
              <input class="span12" name="email" placeholder="your email" type="email" />
            </div>
          </div>
          <div class="controls controls-row">
            <div class="control-group span12">
              <input class="span12" name="subject" placeholder="subject" type="text" />
            </div>
          </div>
          <div class="controls controls-row">
            <div class="control-group span12">
              <textarea class="span12" name="message" placeholder="please type your message in here... " rows="5"></textarea>
            </div>
          </div>
          <div class="controls controls-row">
            <div class="control-group span12">
              <button class="btn btn-primary" name="submitButton" type="submit">
                Send Message
              </button>
            </div>
          </div>
        </form>
mmcdonald 28 Posting Pro

Hi all,

I have a website that allows users to vote once every hour and I've run into a weird issue.

When a user votes for a listing their IP is collected and stored along with the time of the vote. An hour later they are able to vote again. This has been working perfectly for months.

My traffic is growing rapidly and I'm seeing more and more visitors vote by the day - but it's blocking people from voting who haven't voted in ages! (Including myself - frequently).

I'm using $_SERVER['REMOTE_ADDR']; to detect the visitors IP; but I'm led to believe that this cannot be trusted?

I've done some brainstoring and I think the use of cloudflare CDN might be the issue? What do you think?

Are there alternative methods to identifying the visitors uniquely?

Thanks!

mmcdonald 28 Posting Pro

FYI: stupid mistake - missed name="submit" on HTML button. Going to bed.

SOLVED.

mmcdonald 28 Posting Pro

Why was that a bad post?

mmcdonald 28 Posting Pro

Hey all, cant get this very very simple query to work but I have been going 26 hours and my thoughts are numb. Please assist? I have error reporting on and request mysql errors but I'm getting nothing.

Contents of config.php

$db_host = 'localhost'; //IP of database server (most likely 'localhost')
$db_username = 'root';  //Username to access database
$db_password = '';      //Password used to access database


    $con = mysql_connect($db_host, $db_username, $db_password);
        if (!$con)
          {
            die('Could not connect to the database. Email are not currently being stored.');
          }else{
            $select_db = mysql_select_db('email', $con);
            if (!$select_db) {
                die ('Can\'t select database : ' . mysql_error());
                    }
               }

The form:

<form method="post">
    <div id="subscribe">
        <input type="text" placeholder="Enter your email address for updates!" id="email" name="email">
        <input type="submit" value="Subscribe">
        <div class="clear"></div>
    </div>
</form>

The script to insert subscribers email:

require('config.php');
    if(isset($_POST['submit'])){

        @$email = $_POST['email'];
        @$date = date('d/m/Y H:i');

        if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $email) || empty($email)) {
            echo 'The email address entered is invalid.';
        } else {
            $query = "INSERT INTO subscribers (id, email, date) VALUES ('', '$email', '$date')"; 
            mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());  
            }
    }

Thanks in advance!

mmcdonald 28 Posting Pro

If you're on about generating a random number then you probably want rand()

Example:

<?php

     print rand() . "<br>"; 
     //generates and prints a random number

     print rand(10, 30); 
     //generates and prints a random number between 10 and 30 (10 and 30 ARE included)

     print rand(1, 1000000); 
     //generates and prints a random number between on and one million

 ?>

Check out this link: http://php.net/manual/en/function.rand.php

mmcdonald 28 Posting Pro

Something I still cant get me head around.

Tom and Charlie are on my website.

Tom credits his account with $5.00.

Charlie credits his account with $20.00.

My listener gets 2 responses, one with the value of 5$ and one with the value of 20$.

How does my script know to give the user called 'Tom' $5 and the user called 'Charlie' $20?

Whats the unique identifier? It can't be their PayPal address because I may have one address stored for them and they use another to pay?

Can it carry the value of a PHP session?

mmcdonald 28 Posting Pro

Since you got your cart working. Have you google this before you came on Daniweb?

Yes I has googled it - came up with a load of crap saturating the world wide web. That one page you have linked was not on the first 3 pages as I cleared them all. Also - the represenative from PayPal couldn't even provide me with that link.

Thanks for your help,
Mike

mmcdonald 28 Posting Pro

Hi all,

I've setup a simple cart where users choose how much they would like to deposit as virtual currency using the PayPal sandbox - I've tested it and it works great. So far I've got to successful money transfers between accounts and notifications.

However what I can't figure out is how to give the account on my website the virtual credit after the user pays. I want to store the value in a SQL column next to their username; doing so is easy - but how do I execute that SQL command only when a user has genuinely paid?

To clarify, this is a script that allows users to deposit money to their website account using paypal - I've got as far as the transactions (sending and receiving the money) and notifications. What I'm stuck with is adding the transaction value to the users account on my website.

Can anyone with previous experience please assist?

Thanks!

mmcdonald 28 Posting Pro

Hi all,

I have a very nasty issue here where SQL values are changing but I haven't been hacked because the changes are just too abnormal.

People vote for their servers and every so often the top few servers values roll back.

For example at 03:00 a server has 66 votes. Then at 04:00 it has 120, then at 05:00 i check and it has 88!

This randomly started occuring last night and no code was changed. I thought just to be same I'll overwrite my sites code with a previous backup from a week back. That hasn't helped!

I've turned on SQL logging but theres nothing logged.

What could this be!?

mmcdonald 28 Posting Pro

Sorry just found out that the figure 328 is my free RAM in MB which is great as its a 512MB server.

So for any newbies to Linux, like myself, run the command free -m. The figure located in the free column next to -/+ buffers/cache is the available RAM your server has!

In this case I have 328MB unused RAM - perfect for this particular webserver!

For more information: http://www.linuxatemyram.com/

mmcdonald 28 Posting Pro

Would you say its time to increase the RAM on this lil machine or is it okay? Could you please explain this output?

free -m -s 5             
                       total       used       free     shared    buffers     cached
Mem:                   496         439        57       0         20          250
-/+ buffers/cache:                 167        328
Swap:                  511         5          506

Thanks,
M

mmcdonald 28 Posting Pro
mmcdonald 28 Posting Pro

You can do this just using PHP and SQL but no one will just give you the code.

I can recommend this link: http://www.htmlgoodies.com/beyond/php/article.php/3855686/PHP-Mailer-Script-Step-by-Step.htm

It takes you through creating a mailer script step by step explaining every step of the way.

You need to connect to your SMTP server and send the emails in a loop. In each loop you are going to need to collect the recipients email address, username and password.

Have fun and good luck!

mmcdonald 28 Posting Pro

I don't suppose your mail server has changed or has an error? I know you put gmail above but that might just be to hide your domain :)

Also if (isset($_REQUEST['email'])) should not be used now as it has compatability issues with IE and possibly other browsers.

Instead use if (isset($_POST["button_id"])=="button_value")

in your case this would be if (isset($_POST["submit1"])=="Submit")

mmcdonald 28 Posting Pro

You'reDon't you think you're better off storing the values from form one and when it's submitted reloading the page with form 2? Perhaps by setting a session or rewriting the URL to domain.com/page.php?form=2

What you have right now will not work as your isset is within another isset at Minitauros said about :)

mmcdonald 28 Posting Pro

Sorry tell a lie it is working I was refreshing the productions erver and not my development server - sorry!

'.date('F',strtotime("+1 month")).'

Is the solution for anyone who may come across the same issue.

mmcdonald 28 Posting Pro

I am using this but it isn't working (which I thought it would)

echo date('Y-m-d',strtotime("+1 month"));
mmcdonald 28 Posting Pro

Hey all,

I am currently using the following to echo the 1st Current_month:

echo "1st '.date('F').'.";

So that would say, for example, 1st October.

What would I need to do to echo the next month? In this case 'November'?

Thanks for any help!

mmcdonald 28 Posting Pro

There is a slim chance my last post could have issues with IE 6,7 and 8 but not 100% sure.

mmcdonald 28 Posting Pro

On submission just see if the checkbox isset and if so execute a standard SQL query?

Also this: ny changes asap is really rude and arrogant. people help eachother here in their own free will - you're just registering for free help with takes the piss out of this awesome community.

Moving on...

When form is submit blah blah blah{

// some submission stuff here

if (isset($_POST['checkbox_id'])) {
            // Do query here
        }else{
            // Do something else
        } 

// some submission stuff here

    }

Hope it helps

mmcdonald 28 Posting Pro

I use this code to search my DB. When the search field is submitted you are directed to mydomain.com/search.php?search=search_term. I then get the search term using $_GET['search'] and query my SQL database using:

id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%'

Here's the search function in full (excluding how I display my results).

$txtsearch="";
            if (isset($_GET["btnsearch"])=="Search") 
            {
                        $txtsearch=$_GET['search'];
                        $count_query="SELECT * FROM servers WHERE active = '1' AND enabled = '1' AND ( id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%' ) ORDER BY vote_count DESC; ";

                        $select_query=" SELECT * FROM servers WHERE active = '1' AND enabled = '1' AND ( id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%' )  ORDER BY vote_count DESC
                                limit $eu, $limit ";
            }
mmcdonald 28 Posting Pro

Have you changed user privileges? If not your username should be 'root' an not'local host'. If you are using 'local host' for whatever reason that maybe you shouldnt have that space i.e. 'localhost' rather than 'local host'.

Local development privileges by default are 'root' as your username and '' as your password.

Let us know if you get any mor einformation to troubleshoot. Perhaps some copy and psting of errors would help further.

mmcdonald 28 Posting Pro

We sure are :)

Do I need to an a lib to my linux server for mysqli or just change all mysql_* to mysqli_*?

mmcdonald 28 Posting Pro

Thanks mate :)

mmcdonald 28 Posting Pro

Whats the best way to collect all the users where server_id = X

Table:

id     server_id     user
1      2761          adam
2      2567          tom
3      2761          luke
4      2761          mike
5      2346          lucy

So what should I do to echo all users where server_id = 2761?

What output should look like...

Adam, Luke, Mike

What I think is:

$voter_count = "SELECT user FROM `voters` WHERE `server_id`='2761'";
$voter_result = mysql_query($voter_count);

if ($voter_result > 0) {
                echo implode(", ", mysql_fetch_array($voter_result));
       }else{
                echo "No one has voted today using their username - be the first!";
       }

but this results this result:

adam, adam

Thanks in adavce!

mmcdonald 28 Posting Pro

Sorry?

mmcdonald 28 Posting Pro

You're a god :)

mmcdonald 28 Posting Pro

I have the same issue with the code above. The code above takes an image and writes data on top using PHP's imagegettftext. The process works fine but when it comes to overwriting the existing image it fails. I don't know where to apply your solution which fixed the same error earlier in this post.

mmcdonald 28 Posting Pro

I'm having the same issue with another script - how can I apply your solution to this:

<?php
session_start();

$id=isset($_GET['id']) ? $_GET['id'] : 0;
$server_name=isset($_GET['server_name']) ? $_GET['server_name'] : 0;
$ip=isset($_GET['ip']) ? $_GET['ip'] : 0;
$cur_players=isset($_GET['cur_players']) ? $_GET['cur_players'] : 0;
$max_players=isset($_GET['max_players']) ? $_GET['max_players'] : 0;
$vote_count=isset($_GET['vote_count']) ? $_GET['vote_count'] : 0;
$uptime=isset($_GET['uptime']) ? $_GET['uptime'] : 0;
$pingstatus=isset($_GET['pingstatus']) ? $_GET['pingstatus'] : 0;

$players=$cur_players." / ".$max_players;

        // Create image instances
        $src = imagecreatefromjpeg('../images/banners/server_banner.jpg');
        $dest = imagecreatetruecolor(450, 100);

        // Copy
        imagecopy($dest, $src, 0, 0, 0, 0, 450, 100);

        // Create some colors
        $heading_color = imagecolorallocate($dest, 255, 255, 255);
        $data_color = imagecolorallocate($dest, 0, 0, 0);

        //imagefilledrectangle($dest, 0, 0, 399, 29, $white);

        // The text to draw
        $text1 = 'Server: ';
        $text2 = 'IP: ';
        $text3 = 'Players: ';
        $text4 = 'Votes: ';
        $text5 = 'Uptime: ';
        $text6 = 'Status: ';
        // Replace path by your own font path
        //$font = 'css/fonts/MINECRAFT_Z2FONT.TTF';
        $font = '../css/fonts/merriweather-regular-webfont.ttf';


        // Add some shadow to the text
        //imagettftext($dest, 12, 0, 11, 21, $grey, $font, $text);

        // Add the text
        imagettftext($dest, 10, 0, 20, 22, $heading_color, $font, $text1);
        imagettftext($dest, 10, 0, 20, 44, $heading_color, $font, $text2);
        imagettftext($dest, 10, 0, 20, 65, $heading_color, $font, $text3);
        imagettftext($dest, 10, 0, 20, 86, $heading_color, $font, $text6);
        imagettftext($dest, 10, 0, 260, 65, $heading_color, $font, $text4);
        imagettftext($dest, 10, 0, 260, 85, $heading_color, $font, $text5);

        imagettftext($dest, 10, 0, 78, 22, $data_color, $font, $server_name);
        imagettftext($dest, 10, 0, 78, 44, $data_color, $font, $ip);
        imagettftext($dest, 10, 0, 78, 65, $data_color, $font, $players);
        imagettftext($dest, 10, 0, 78, 86, $data_color, $font, $pingstatus);
        imagettftext($dest, 10, 0, …
mmcdonald 28 Posting Pro

wait wait wait it's working! bravo!

Your if statement worked! thank you

mmcdonald 28 Posting Pro

Error reporting is already on fully

mmcdonald 28 Posting Pro

Only error that comes back is

SMTP -> ERROR: Failed to connect to server: Connection refused (111) 
Language string failed to load: smtp_connect_failed Mailer Error: Language string failed to load: smtp_connect_failed

and thats because I haven't finished configuring my SMTP on the page yet.

The file wasn't being replaced but the upload still works if I delete the existing file first.

Thanks for your help so far!

mmcdonald 28 Posting Pro

No errors. Some are www-data and some are root

mmcdonald 28 Posting Pro

This could be a PHP issue or a linux issue.

My form uses the following code to allow users to upload their banner and worked fine on my old server:

             if ($_FILES["banner"]["name"]!="")
            {
                $folder_path = "images/server_banners/";
                $myfileext=substr($_FILES["banner"]["name"], - 4,4);
                $banner_file_path=$username."-".$server_id.$myfileext;
                $file_path = $folder_path.$banner_file_path; 
                    if (file_exists($file_path))
                      {
                            unlink($file_path);
                            move_uploaded_file($_FILES["banner"]["tmp_name"],$file_path);
                      }
                     else
                      {
                          move_uploaded_file($_FILES["banner"]["tmp_name"],$file_path);
                      }

$sql = mysql_query("UPDATE servers SET banner='".$banner_file_path."' WHERE id = '".$server_id."' and administrator = '".$_SESSION['valid']."'");
                }

But it seems the images now cannot be overwritten? When I submit the form everything is fine as I can see the browser uploading the image by percentage - however the image is not stored IF a file already exists with the same name. Which means the script is working fine but there is some sort of permissions issue?

Just for a test I gave all folders and files 777 and the image still wasn't overwritten.

I then deleted the stored file and reverted back permissions and uploaded a new file and it worked fine.

Any ideas? Is there a way to ensure files can be overwritten in a certain directory?

mmcdonald 28 Posting Pro

No they don't they're smarter than that. The UK government supports business that indirectly boost education and there for employment. They see the money come back in taxes once those who were previously uneducated get a job.

It takes the unemployed who cost us hundreds of millions and and assists them in finding employment positions - therefore less money goes out and more money goes in.

That's basic economics - but I appriciate the joke ;)

N.B. Yes - taxes are high -.-

mmcdonald 28 Posting Pro

Not sure if this is the right place, so forgive me if it isn't.

There's a few of us building a huge online portal that contains IT training courses in Cisco, CompTIA, Microsoft and ITIL certifications. We're offering it at the small cost of £5.00/month full access to IT professionals and graduates but we're going to build links to colleges and secondary schools up and own the country providing free access for their students who have interest.

The only problem is that we are unable to complete certain topics. Years of experience and attaining most of the certifications myself has up to now proved sufficient enough for me to author the topics - but there are some that are to tough for me to get down on paper (even though I have practical experience in the topics i'm targeting!) so I need to contract some technology professionals.

Does anyone know of any grants that are available in the UK to complete this project? I estimate to need £5,000 - £8,000 to finish the website.

Thanks in advance!
Michael

mmcdonald 28 Posting Pro

Hi james. This is in regards to using <i class="icon-pencil"></i> and other span icons in nav forms? Or is that what you've pout and I'm missing the ort

mmcdonald 28 Posting Pro

That sounds like a good idea, any ideas how to log a scripts actions on Ubuntu 10.04 LTS?

mmcdonald 28 Posting Pro

Ofcourse but putting that aside - none of them are passing the 10 min marker... they should still complete their execution.

mmcdonald 28 Posting Pro

There's nothing wrong with the script as it works great if I execute it in my browser. This has to be a setting that I don't know about somewhere

mmcdonald 28 Posting Pro

I have three scripts running under crontab and theyre executing perfectly (see the log below):

Oct  9 10:40:01 servercharlie CRON[29850]: (root) CMD (php -q /var/www/folder/script-3.php)
Oct  9 10:41:01 servercharlie CRON[29861]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:42:01 servercharlie CRON[29867]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:43:01 servercharlie CRON[29873]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:44:01 servercharlie CRON[29879]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:45:01 servercharlie CRON[29887]: (root) CMD (   php -q /var/www/script-2.php)
Oct  9 10:45:01 servercharlie CRON[29888]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:45:01 servercharlie CRON[29889]: (root) CMD (php -q /var/www/folder/script-3.php)
Oct  9 10:46:01 servercharlie CRON[29901]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:47:01 servercharlie CRON[29907]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:48:01 servercharlie CRON[29915]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:49:01 servercharlie CRON[29921]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:50:01 servercharlie CRON[29929]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:50:01 servercharlie CRON[29930]: (root) CMD (php -q /var/www/folder/script-3.php)
Oct  9 10:50:01 servercharlie CRON[29931]: (root) CMD (   php -q /var/www/script-2.php)
Oct  9 10:51:01 servercharlie CRON[29942]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:52:01 servercharlie CRON[29949]: (root) CMD (php -q /var/www/tasks/script-1.php)
Oct  9 10:53:01 servercharlie CRON[29958]: (root) CMD (php -q /var/www/tasks/script-1.php)

Script 1 runs every minute and executes flawlessly. Script 2 executes every 5 minutes and this is the one I'm having problems with. It never completes its execution. It's a 10 - 15 minute long script. I have set_time_limit(0); in the file at the top, I have changed all limits on execution …

mmcdonald 28 Posting Pro

but if they run manually from any browser? Surely crontab can run them? What permissions do the files need for crontab to successfully execute them?

N.B. Cant be permissions as they all have the same

mmcdonald 28 Posting Pro

My crontab states:

PATH=/var/www
00 00 * * * php -q /tasks/script1.php
*/5 * * * * php -q /cycle/script2.php
*/1 * * * * php -q /tasks/script3.php

script 1 doesnt run, but I need to to run every midnight

script 2 doesnt run but works fine when executed manually.

script 3 DOES run perfectly...

makes no sense to me - any ideas?