phorce 131 Posting Whiz in Training Featured Poster

Have you made sure that the file is being included?

phorce 131 Posting Whiz in Training Featured Poster

You have not declared the method prototype correctly in your class.

static std::map<std::pair<u32, u32>, CreateSessInfo> m_mSessionId2CCRNum2DefaultBearerId;

Shoudl be:

static std::map<std::pair<u32, u32>, CreateSessInfo> m_mSessionId2CCRNum2DefaultBearerId()
{
    // Logic here

    return map; 

}

Then you can access it as:

Foo::m_mSessionId2CCRNum2DefaultBearerId();

Here, I did a similar example: http://ideone.com/NelSt9 no logic is there, but, I hope it gives you an understanding of where you went wrong.

EDIT:

Just realised what you were attempting, so, @NathanOliver answer is more accurate.

rubberman commented: Good - give credit where credit is due! :-) +12
phorce 131 Posting Whiz in Training Featured Poster

First off, your question is quite confusing. I can't gather what it is what you're trying to do, let me try with a different example, see if it makes sense to what I think they are wanting you to do.

Let's assume that you have a Person, each person therefore, has a: Name, age, nationality.. Defined below:

class Person
{
    public:

        Person()
        {
            // default
        }

        Person(std::string name, int age, std::string nation)
        {
            this->theName = name;
            this->theNation = nation;
            this->age = age;
        }

    protected:

        std::string theName; 
        std::string theNation;
        int age;
};

So, far we have created the base class. We now introduce inheritence, let's say that you now have a "Student", well a "Student" shares all the characteristics as a person and therefore you can inherit from this:

class Student : public Person {

    public:

       Student() { } // default 

       Student(std::string theName, int theAge, std::string nation, int num)
          : Person(theName, theAge, nation)
       {
          // now we can do this:
          this->theNum = num;

       }

    protected:

       int theNum;

}

Therefore, when we are creating objects, we no longer have to look at the "Person" class.. We can just do the following:

Student s("Phorce", 10, "British", "00001");

If we had a method in the "Person" called getName we could do the following:

std::string returnName()
{
    return this->theName;
}

We can access it by std::cout << s.returnName() note how we did not define this in the Student class?

This can relate to your problem, you can …

phorce 131 Posting Whiz in Training Featured Poster

Because not many people have access to this library, please could you specify some expected input and outputs?

Also, what is the data type of MInput?

phorce 131 Posting Whiz in Training Featured Poster

I believe, from what I can see is that the validation requires a . followed by between two or three characters (\.[a-z]{2,3}) so email addresses like: test1@gmail.com would valid true, whereas email addresses containing a . with only one character, would throw up an error.

There are some pre-built functions: http://www.php.net/manual/en/filter.examples.validation.php which would filter this information for you.

Hope this answers your question, slightly.

phorce 131 Posting Whiz in Training Featured Poster

What do you mean by "Pin"?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

If you're happy for me to do so. I don't mind looking over your database, to see where you went wrong. Also, it might be a good idea to take a look at your script. If you would allow access to the server for around half an hour, that would be great. You can make a seperate user account up if you don't want the admin details. Please post back; if you're sending details, make sure they are in a PM. I am around for most of the night tonight (UK time) so I'll take a look.

phorce 131 Posting Whiz in Training Featured Poster

Have not coded PHP in so long..

<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

$con = mysql_connect("localhost","372***", "********");
if (!$con)
  {
  die('NEIN!' . mysql_error());
  }
//Connect to DB
//(Possible offender below)
$res = mysql_query("SHOW DATABASES");

while ($row = mysql_fetch_assoc($res)) {
    echo $row['372***'] . "\n";
}
mysql_select_db(372***, $con)
or die("Lost");

echo "<table border='1'>
<tr>
<th>Employee Name</th>
<th>Employee Address</th>
</tr>";

$result = mysql_query("SELECT * FROM b8_14160309_simple*** LIMIT 1") or die (mysql_error());

$row = mysql_fetch_array($result); // I think you commented out the $result
var_dump($row[0]);

?>

This should now not display any errors. Post back

phorce 131 Posting Whiz in Training Featured Poster

Right, ok. mhm. This is really weird.

First off, attempt to do the following:

// After $result, comment the rest put this
$row = mysql_fetch_row($result);

var_dump($row[0]); // What does this give? 
phorce 131 Posting Whiz in Training Featured Poster

Please post, what the field names actually say?

phorce 131 Posting Whiz in Training Featured Poster

I can barely see that, have another one? I'm pretty sure it says 'emp_names' and not 'emp_name' am I right?

phorce 131 Posting Whiz in Training Featured Poster

Inside your table,

Are the rows emp_name / emp_address or are they named something else? Please print screen the table

phorce 131 Posting Whiz in Training Featured Poster

Can you post some more code? I.e. where do you make a connection to the database? If you post back within the next 15 mins, I'll take a look - Or just write one for you to test myself!

phorce 131 Posting Whiz in Training Featured Poster

Its saying there are no records inside the table.so are there records in the table? Or the query returns NULL I would check the table. Try and screen print it to verify there are records in the table.

Peace

phorce 131 Posting Whiz in Training Featured Poster

Try:

$result = mysql_query("SELECT * FROM b8_14160309_simpleDB3 LIMIT 1") or die ("Something is wrong here", mysql_error());

OR try:

if(mysql_num_rows($result)==0)
{
   echo "Theres something wrong here";
}
phorce 131 Posting Whiz in Training Featured Poster

Could you not do something like:

$action = $_GET['action']; // assume that action.php?action=edit

switch ($action) {

        case "Edit":
            echo "EDIT STUFF HERE";
            break;

        case "update":

            echo "Update here";
            break;
        /*.....*/

        default: 
        echo "Default";
    }    
phorce 131 Posting Whiz in Training Featured Poster

On a side note: The link that @iwavetostars mentioned is a really good read; I actually want that book as a reference.

phorce 131 Posting Whiz in Training Featured Poster

Pick a project that is interesting to you. I.e. At my University, I've just been assigned to do some research based work with the Leap Motion sensors (I don't know if you've come across those) and instead of using C++ (What I am familiar with) I've chosen to use Python. Have I gone and research and read through 100's of books and documentation regarding it? No. I've sat down, used my brain and realised the things that I picked up in C++ are very similar to those in Python and Googled what I needed.

phorce 131 Posting Whiz in Training Featured Poster

Let me just ask you: Is there really any point in sitting down and learning Python, when you already know C/C++? Let's look at this logically, from gaining knowlege in C/C++ you should have an understanding of syntax and how programming logic works. So, would you benefit from sitting down and actually reading: if x is 10: blah blah - Probably not! Learning the basic structure, is ok. But from there, you should pick a project to do and start from there - Thus meaning you gain quick knowlege and your understanding improves.

phorce 131 Posting Whiz in Training Featured Poster

Why do you want to do this? I don't get the point??

phorce 131 Posting Whiz in Training Featured Poster

Just a very quick question.. Why would you need/want to convert this to an .exe - Why not give them the source code?

Have you tried: http://www.pyinstaller.org/ ?

phorce 131 Posting Whiz in Training Featured Poster

Would it not just be easier to use:

<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';

if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
    echo "This ($email_a) email address is considered valid.";
}

PHP already has this built-in!!

But, what you have used is a function, to call this function you would use:

if(!validate_email($_POST['email']))
{
   die("you have not used a correct email address");
}

// or 

$email = $_POST['email'];
if(!validate_email($email)) {
   die("you have not used a correct email address");
}

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

@cam - No, this has to be outside of the class definition.
You're delcaring a static reference, the class has to know where it is initialised.

phorce 131 Posting Whiz in Training Featured Poster

Like @prit said, are you sure you have the right port? Are you sure this port is open? I Persume that you're using local machines (i.e. not a server) for this?

phorce 131 Posting Whiz in Training Featured Poster

It is all well and good to concentrate on "coding" type security preventions, but, what are you doing in terms of server-side? I.e. "Hackers" or people who want to generally cause a havoc to your website might not generally go down the route of XSS or trying to find vunerabilities inside your code.

What if, for example they managed to get onto your server? Since, all your files, and mysql databases are stored on your server - They don't even need to look for vunerabilities within your code.

What if, they managed to DDoS/DoS your site? Corrupt your database files etc.. I wouldn't just look at coding techniques in terms of security - Make sure your server is 100% secure.

:)

phorce 131 Posting Whiz in Training Featured Poster

C++ is a massive language, that requires years and years of experties in order to do the smallest of tasks. Let me give you a simple example: Let's say I want to develop an algorithm for an FFT (Fast Fourier Transform) pretty common in signal processing.

In Python I would:

from cmath import exp, pi

def fft(x):
    N = len(x)
    if N <= 1: return x
    even = fft(x[0::2])
    odd =  fft(x[1::2])
    return [even[k] + exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)] + \
           [even[k] - exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)]

print fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])

Whereas in C++

#include <complex>
#include <iostream>
#include <valarray>

const double PI = 3.141592653589793238460;

typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

// Cooley–Tukey FFT (in-place)
void fft(CArray& x)
{
    const size_t N = x.size();
    if (N <= 1) return;

    // divide
    CArray even = x[std::slice(0, N/2, 2)];
    CArray  odd = x[std::slice(1, N/2, 2)];

    // conquer
    fft(even);
    fft(odd);

    // combine
    for (size_t k = 0; k < N/2; ++k)
    {
        Complex t = std::polar(1.0, -2 * PI * k / N) * odd[k];
        x[k    ] = even[k] + t;
        x[k+N/2] = even[k] - t;
    }
}

// inverse fft (in-place)
void ifft(CArray& x)
{
    // conjugate the complex numbers
    x = x.apply(std::conj);

    // forward fft
    fft( x );

    // conjugate the complex numbers again
    x = x.apply(std::conj);

    // scale the numbers
    x /= x.size();
}

int main()
{
    const Complex test[] = { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 …
phorce 131 Posting Whiz in Training Featured Poster

This is not going to make much of an impact but: I personally don't think books of programming are a good option. (Ok, in terms of software methodologies: Agile, sofware concents such as lifecycles) but in terms of coding I do not.. Here's why:

1) You learn THEIR coding styles, and THEIR coding techniques on how to do something. Sure, as a reference it's great but you tend to pick up their habbits and their habbits might not be the best way to go.

2) Books become out-dated, very, very quickly. You might be reading references to something that has been published 5 years ago and therefore the particular method becomes depciated. This means that you'll get fustrated with code. For example: Let's say I wanted to learn PHP, and, I picked up a copy of Larry Ullmans book.. It has an example that clearly states that mysql_* is the best option to use.. I then learn that mysql_* functions are now depeciated, so, i've written his solution and yet again, I'm on Google, I'm on forums only to learn that PDO/MYSQLI_* are the new standards.. Do I purchase more books?

If you take forum communities, websites and online referencing to many many things out there in terms of physical programming then you get to pick up multiple techniques. Usually you will see a problem and different members also contribute with their own standards. Languages such as C++ have an array of methods in which you can solve particular problems …

phorce 131 Posting Whiz in Training Featured Poster

@Anima Gives you some great recommendations, with regards to Python. Python is easy to learn and is becoming a lot more popular in commercial sense. Some programmers that have been developing for many, many years are taking up Python now because it offers such a high commercial gain; even if the job isn't in Python.

phorce 131 Posting Whiz in Training Featured Poster

@down-voter - Please could you explain why this post has been downvoted?

phorce 131 Posting Whiz in Training Featured Poster

Because I'm learning Python at the moment, I'm going to give you a start.. Something like this:

import string
import random 

def FlipCoin(): 

    coin = ['heads', 'tails'];

    return random.choice(coin);

def main():

    heads = 0;
    tails = 0;

    for x in range(0, 100):
        print FlipCoin();

main();

I'm sure that you can finish this off. :)

phorce 131 Posting Whiz in Training Featured Poster

What is contained in company[i][j] there isn't a lot to go on from this.

phorce 131 Posting Whiz in Training Featured Poster

Can I just ask.. Why are you reading the words in twice? This cannot be right.. Could you not just read the words into an array, and then perform the word count / unique word count in separate functions?

phorce 131 Posting Whiz in Training Featured Poster

For a start off: This really isn't a PHP related question since it has more to do with CSS. I don't know why you're using PHP, unless, you are generating or rendering the image.

Post some code, otherwise, we cannot help.

phorce 131 Posting Whiz in Training Featured Poster

Please mark this thread as solved and give rep to who you think helped you.

phorce 131 Posting Whiz in Training Featured Poster

if ($return === false) {

Has to be:

if ($return == false) {

What you are saying in your first argument is that: $return is the type of false Attempt to use just == and post what happens. I believe this is the case for here.

phorce 131 Posting Whiz in Training Featured Poster

@mmcdonald

How would this work:

<?php echo number_format($row_total['sub_total'], 2, '.', '')]; ?>

Where did the last ] come from?

It should be:

<?php echo number_format($row_total['sub_total'], 2, '.', ''); ?>

Would work, I guess!

=)

phorce 131 Posting Whiz in Training Featured Poster

I'm no expert on this function, but shouldn't it be:

echo number_format((int)$row_total, 2,'.','');

Since you are denoting an array $row_total[blah];

phorce 131 Posting Whiz in Training Featured Poster

I have no idea what you are trying to do here.

You have two 1D arrays, do you want to merge these arrays so they become a 2D array?

phorce 131 Posting Whiz in Training Featured Poster

I'm having the same problem!! If I upload two images, only one will upload..

phorce 131 Posting Whiz in Training Featured Poster

First off, it's wrong.

It should be:

$id = isset($Telephone) ? trim($Telephone) : " ";

The expression is a Ternary logic operator and it will assign $id to whatever is set. So it's just like doing the following:

if(isset($Telephone)
{
   $id = $Telephone;
}else{
  $id = "";
}

Hope this helps

EDIT:

So in theory what we do is:

1) Initialise a variable "$id" to hold the value passed through $_POST['Telephone'];

2) Using the tinary operator, assign $id with a value based on some logic: `if(isset($Telephone) // is there a vaue ? // yes there is $Telephone) // return $Telephone : // no there isn't a value, so 'id' gets stored as null || empty

phorce 131 Posting Whiz in Training Featured Poster

It looks like it doesn't know what $Telephone = $_POST['Telephone']; is since you are not posting Telephone you are posting: Phone so do this:

$Telephone = $_POST['Telephone'];
    $id=isset($_POST['$Telephone']) ? trim($_POST["$Telephone"]) : "";

// has to be :

$Telephone = $_POST['Phone'];
    $id=isset($Telephone) ? trim($Telephone) : "";

This should work

phorce 131 Posting Whiz in Training Featured Poster

To answer your questions:

With your example - I dont understand the unset($username); // not needed.

Would that remove the username var?

No, since we would store the username in validated_username after we have done the validation.

2) You could use the following:

<?php

    function validateString($str) {

        return $newString = preg_replace('/[^a-z0-9]/i', '', $str);
    }

    $username = "J/A/M/E/S_B/O-N-D";

    echo validateString($username);

    // output: JAMESBOND

The problem with this is: Let's suppose I have a database of usernames, and, each username has to be unique. If the username: "Jamesbond" is taken, and, therefore, someone enters "james_bond" then this function will remove the "_" and if the right measures aren't in place will create another username with this. You could, use the following function which will remove all of the special characters AND then check it against the database.

Protect against xss and sql injecting attacks.

The function ^^ does a pretty good job when it comes to this, of course, it does all depend on how you are handing your SQL queries.. BUT, this function does strip the string against any HTML/JS which could potentially cause XSS.

Does this help?

phorce 131 Posting Whiz in Training Featured Poster

For that, you will need to use regex, and somehow remove the the characters from the username. Or, don't allow for such characters to be entered in the first place.

This function you want limits the chances of XSS by stripping the HTML/JS code from the string.

What is it you're trying to do exactly?

phorce 131 Posting Whiz in Training Featured Poster

Yes.. Since in the example I gave you: var_dump($str2); will print out the result from the function.

If for example, I did this:

    $str = (string) "<script> alert('sff'); </script>";
    $str2 = ft_xss($str);

    echo $str2;

The output would show the "<script>...</script>" because that's what its' been told to do.

So, in your case it would be this:

// Let's look at an example:

$username = $_POST['username']; // posted from a text field.

$validated_username = ft_xss($username);

unset($username); // not needed.

Does this make sense?

phorce 131 Posting Whiz in Training Featured Poster

No, this is a class. Classes are different, you have to create an object of this class in order to call this method. Are you wanting to use multiple methods from this class? If not, here, try this:

<?php

function ft_xss($str, $charset = 'ISO-8859-1') {
    /*
    * Remove Null Characters
    *
    * This prevents sandwiching null characters
    * between ascii characters, like Java\0script.
    *
    */
    $str = preg_replace('/\0+/', '', $str);
    $str = preg_replace('/(\\\\0)+/', '', $str);

    /*
    * Validate standard character entities
    *
    * Add a semicolon if missing.  We do this to enable
    * the conversion of entities to ASCII later.
    *
    */
    $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str);

    /*
    * Validate UTF16 two byte encoding (x00)
    *
    * Just as above, adds a semicolon if missing.
    *
    */
    $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str);

    /*
    * URL Decode
    *
    * Just in case stuff like this is submitted:
    *
    * <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
    *
    * Note: Normally urldecode() would be easier but it removes plus signs
    *
    */  
    $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str);
    $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str);      

    /*
    * Convert character entities to ASCII
    *
    * This permits our tests below to work reliably.
    * We only convert entities that are within tags since
    * these are the ones that will pose security problems.
    *
    */
    if (preg_match_all("/<(.+?)>/si", $str, $matches)) {     
        for ($i = 0; $i < count($matches['0']); $i++) {
            $str = str_replace($matches['1'][$i],
                html_entity_decode($matches['1'][$i], ENT_COMPAT, $charset), $str);
        }
    }

    /*
    * Convert all tabs to spaces
    *
    * This prevents strings like this: …
phorce 131 Posting Whiz in Training Featured Poster

Do you have your own class?

If not, remove the public from it and just do the following:

ft_xss($str)

Where $str is the string you want to pass.

Its difficult to say though, since you've only provided half of the function and therefore cannot determine the return type.

phorce 131 Posting Whiz in Training Featured Poster

If this problem has been solved. Could you mark it as solved please?

phorce 131 Posting Whiz in Training Featured Poster

@Andy - If we pass by reference, we get the actual memory allocations and not the value. Thus meaning we can ensure speed as well as the fact if the values have to be changed in any way.. Then this will be done in direct memory.

phorce 131 Posting Whiz in Training Featured Poster

You are missing the ; off your function prototypes. The ones you have, should work with your compiler..

You could, however, do the following:

void Scanned(std::ifstream& ifp,int i);

but make sure you include <fstream>

Your struct seems fine, is there a reason why you're not using classes - Just out of interest?

You shouldn't really need the typedef and would be just the following:

struct Checker
{
  int age;
  char name[20];
  int  roll_call;
};

Also, in the following: Checker pass in the arrays as references: int Checker(char *s,char *u)

Hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

university they would briefly cover each of these fields.

This totally depends on the University and/or the choice of course you study. Most are programming based (in the UK) but it's very unlikly (unless you study a Games related course) that they will cover "Graphics Porgramming" however, Web Developer and Mobile Development are becoming more dominant in the market so these would be covered.

So what I'm trying to ask is, would I be at least equally competent to a university graduate?

Universties "teach" you how to research independantly and within a group. I wouldn't go to University and expect them to teach you EVERYTHING there is to know about programming/languages/compilers/operating systems/algorithms etc.. So, it depends on your personal prospective; if you decide not to choose a University course, and gain experience and knowlege then I doubt that will go against you when applying for jobs, since, most graduate jobs these days require experience over a "piece of paper" so it all depends.

With regards to your first post:

code a basic operating system

Why? What would be the point in this? The latter, getting involved with the Linux community and helping developing something - This would be ideal.. Not creating your own operating system.

If I learn several programming langauges, assembly, complier design, software architecture, design patterns, to write clean code, electronics, some common libraries, data structures and algorithms, networking, database managamenet systems, front end …