Will Gresham 81 Master Poster

mysql_fetch_array returns either a resource, or false.

If it returns false, then there is an error in your query. It is always good to check if the query result was false so you can debug and SQL errors.

Will Gresham 81 Master Poster

Lines 24+27: You don't use a comma to concatenate a string.

Actually, you can in an echo.
echo is a language construct, and can take multiple arguments. If you want to get down to micro seconds, it is also slower to use concatenation in an echo instead of comma separated values..

Will Gresham 81 Master Poster

Your include statement needs to come before pretty much anything else, there should not be any whitespace before any opening php tags, or any after the closing tags. This applies both to the detection script and the file(s) it is included from.
Make sure there are no echo statements or anything that would cause the headers to be send in the files that include the detection script too.

Will Gresham 81 Master Poster

$_GET is an array, not a functon.

If your URL was http://localhost/DIRECTORY/FINAL/ref.php?id=category&another=test&another2=test2 for example, you could use

$_GET['id']
$_GET['another']
$_GET['another2']
Will Gresham 81 Master Poster

It might help to post some code, but the most likely reason is an error with the callback function in your ajax call.

Will Gresham 81 Master Poster

No, I know what is causing the issue, what I don't know is the environment and when the script is loaded.

What I am guessing is that the file gets included from every page on the website, rather than a user going directly to it, which based on the functionality the script is supposed to take is a reasonable assumption.

Will Gresham 81 Master Poster

The issue is that the error is caused by output being sent to browser, including the default headers, and then the script tries to send more headers.

I would guess that this file gets included, rather than visited directly, and the files that include this one are sending output before the include/require call is being made.

Will Gresham 81 Master Poster

So much wrong information here, if I were you I'd disregard all the things LastMitch has posted.
1. You can use multiple header() calls.
2. $_SERVER['PATH_INFO'] will not give you the UserAgent, it's to do with the query string.
3. All changing the URL to what LastMitch suggested will do is make the page redirect ho HTTPS
4. There is no reason to use concatenation over a double quoted variable

The problem you are having is caused by some output occuring before the header() function is called, this could be whitespace from files that include this one, an echo, print, etc..

LastMitch commented: Will Gresham you are rude, I don't know why you down vote me -1
Will Gresham 81 Master Poster

fopen gives you a handle to a file, you then need to use another function (Such as fwrite, fputcsv...) to put data into the file.

Will Gresham 81 Master Poster

you will need to also check if the form has been submitted otherwise the IF will always validate to true.

Of course it always shows, becuase until you submit the form $resp->is_valid will validate to FALSE...

Will Gresham 81 Master Poster

You don't need MySQL to store data in a CSV, if you are using CSV for storing data rather than reporting on or exporting data, then I would have to wonder why you aren't just storing it in MySQL.

The function you need is fputcsv, plently of examples on google.

Will Gresham 81 Master Poster

It will be showing all the time because you are checking if the captcha response only, you will need to also check if the form has been submitted otherwise the IF will always validate to true.

Will Gresham 81 Master Poster

mysql_query will return either a resource, or a boolean FALSE depending on the query result.

Boolean FALSE means that there is an error in your query.

It is good practice to try and catch errors in your code, so that messages like this do not appear, for example, on any query I will do something like the following:

$sql = 'Query here';

if(!$res = mysql_query($sql, $connection)) {
    // Query was not successful, handle it here.
    die(mysql_error($connection));
}

Instead of die() on a live page though, you should display a meaningful message to the user, such as 'Error getting (Whatever you are getting)'

Wrapping your mysql_query function in an if means that a failed query can be debugged.

Will Gresham 81 Master Poster

You can set the order that the data comes in your query, example MySQL:

SELECT *
FROM `table`
WHERE `column` = "value"
ORDER BY `column` ASC
Will Gresham 81 Master Poster

The benefit of using DateTime is that you can perform actions on the data in the query, MySQL has a host of functions that will work on DateTime fields.
If you really need the date as a Unix timestamp, then there is a MySQL function to convert DateTime to a timestamp, and also PHP has a function that will do the same.

As for <?=, it is simply shorthand for <?php echo.... It should not be used on projects that will, or could, be deployed on unknown configurations, as it requires the PHP short tags option to be enabled.

Will Gresham 81 Master Poster

@HunainHafeez
Your suggestion of using double quotes over single quotes will not have any effect on the result.
The difference between double and single quotes is whether or not PHP will try to parse variable within the string or not. A single quoted string will be treated as a literal string, wheras a double quoted one will result in any variables being parsed to their values.

$var1 = 'This is a variable';

$string = 'Variable: $var1';
// Will output Variable: $var1
echo $string;

$string2 = "Variable: $var1";
// Will output Variable: This is a variable
echo $string2;
Will Gresham 81 Master Poster

If the example provided in your post is what you are using, then you are not getting any output because of the following errors:
- Your form action is page1.php, not page2.php, so you never POST the data to the second script.
- The value attribute of your hidden tag is empty, so if you echo it you won't see anything.

Also, for the purposes of this script, there would be no reason for using get over post.

Will Gresham 81 Master Poster

Blindly copying $_POST variables into $_SESSION variables is doing nothing different than your first script.

At the very minimum you should be doing a isset() check on them to see if they contain any data before assigning the session variable. That way you won't be overwriting the session contents with null values.

Alternatively, use $_REQUEST to fetch the values, and in any links you create add the key value pairs you need to the query string.

Will Gresham 81 Master Poster

Hello

I am here seeking knowledge of people who actually know what they are talking about.

In mobile development, specifically Andriod, is there any reason to use variable1 = variable1 + variable2 over variable1 += variable2 ?

This was a subject that came up recently and my lecturer simply said not to use += as it is slower and takes more processing power than the other method.

I have googled, but I am unable to find any information either way confirming or denying this, and when asked, the lecturer can provide no reasoning other than 'it just is'.

Based on other inaccuracies he is teaching, I am wondering if there is any truth is this.

Any help appreciated.

Will Gresham 81 Master Poster

Thought as much, I knew MySQL wouldn't make a call to a PHP script, but I wondered if there was a PHP function like the one that gets the ID of the last inserted row that would tell me if a trigger was run.

Ah well, thanks anyway.

Will Gresham 81 Master Poster

Very simple question, looking on google brings up plenty of MySQL resources on triggers but I can't find the answer I am looking for.

What I want to know is; When I perform a query on a database from PHP, Does MySQL provide any way for PHP to know a trigger was called?

I am trying to implement an achievement system in PHP, and MySQL triggers seem to be the best way to track changes to data.

Will Gresham 81 Master Poster

I found the issue, stupid little mistake, I was copying an empty value to itself :(

Changed this line SetM(i, j, GetM(i, j)); to SetM(i, j, m.GetM(i, j)); and it all works.

Thanks for your input.

Will Gresham 81 Master Poster

Using Visual Studio 2010, so I can step through.

Here is the copy constructor:

Matrix::Matrix(const Matrix& m)
{
	Resize(m.NumRows(), m.NumCols());
	Copy(m);
}
Will Gresham 81 Master Poster

Thanks for the replies, I have been playing about with breakpoints to see what is passes where, or not as the case may be.

Like I say in my first post, the operator* fuction works as expected, and result contains the correct data.
However, When I get to the breakpoint on operator= both 'this' and 'rhs' contain nothing but 0 as their values, I would expect 'this' to be empty, since it should contain nothing at this point, so it seems to be an issue passing the returned value from the multiply function to the assignment one.

Any ideas on how I can ensure this value isn't destroyed before it is passed to the assignemnt?

I apologise if this is a simple question, I am still fairly new to C++.

Will Gresham 81 Master Poster

Hello all,

I have an issue with a class I am writing which is supposed to be able to multiple 2 matrices together.

The issue I am having is not the actual multiplication (That bit works, thanks for the pointers yesterday). The problem, or so I assume, is with my overrides as the correct result is not achieved.

This is the code in question:

class Matrix 
{
	public:
		Matrix(void);
		Matrix(int rows, int cols);
		Matrix(const Matrix& m);
		~Matrix(void);

		Matrix& operator=(const Matrix &rhs);
		Matrix operator* (const Matrix &matrix2);

	private:
		vector<vector<float>> _matrix;
		void Copy(const Matrix& m);
};

I have taken out methods I don't think are causing the issue to save space here.

And the code for them:

// Operator Overloads

Matrix& Matrix::operator=(const Matrix &rhs)
{
	if (this != &rhs)
	{
		Copy(rhs);
	}
	return *this;
}

Matrix Matrix::operator* (const Matrix &matrix2) 
{
	Matrix result;
	result.Resize(NumRows(),matrix2.NumCols());
	int i, j, k;
    float sum;
    for (i = 0; i < 3; i++) 
	{
		for (j = 0; j < 3; j++) 
		{
			sum = 0;
			for (k = 0; k < 3; k++) 
			{
				cout << "i: " << i << " j: " << j << " k: " << k;
				sum += GetM(i, k) * matrix2.GetM(k, j);
				cout << " Sum: " << sum << "\n";
			}
			result.SetM(i, j, sum);
		}
    }
	return result;
}

// Private Methods

void Matrix::Copy(const Matrix& m)
{
	Resize(m.NumRows(), m.NumCols());
	for(int i = 0; i < m.NumRows(); i++)
	{
		for(int j = 0; …
Will Gresham 81 Master Poster

What he meant to do (I believe) is:

sum += GetM(i, k) * matrix2.GetM(k, j);

I'll try that and see if it works.

Care to explain why I cannot use _matrix in this case when I can in the other functions I have?

Will Gresham 81 Master Poster

Hello, I am having an issue with C++. I am relatively new to this language.

The issue I am having is that I am unable to use a variable declared as private in my class.

Definition:

class Matrix 
{
	public:
		Matrix(void);
		Matrix(int rows, int cols);
		Matrix(const Matrix& m);
		~Matrix(void);

		float GetM(int row, int col) const;
		void SetM(int row, int col, float data);

		Matrix& operator=(const Matrix &rhs);
		Matrix operator*(const Matrix &matrix2);

		int NumRows() const;
		int NumCols() const;

		void Resize(int rows, int cols);

	private:
		vector<vector<float>> _matrix;
		void Copy(const Matrix& m);
};

When I try to access _matrix in the operator* function as follows:

Matrix Matrix::operator* (const Matrix &matrix2) 
{
	int i, j;
	float sum;
	Matrix result;

    int i, j, k;
    float sum;
    for (i = 0; i < _matrix.NumRows(); i++) {
		for (j = 0; j < matrix2.NumCols(); j++) {
        sum = 0;
        for (k = 0; _matrix.NumCols(); k++) {
            sum += _matrix.GetM(i, k) * matrix2.GetM(k, j);
                    }
            result.SetM(i, j, sum);
            }
    }
	return result;
}

I get the error message:
IntelliSense: class "std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>" has no member "GetM".

However, I am able to use _matrix in other classes without an issue:

float Matrix::GetM(int a, int b) const
{
	return _matrix[a][b];
}

void Matrix::SetM(int a, int b, float x)
{
	_matrix[a][b] = x;
}

void Matrix::Resize(int rows, int cols) 
{
	_matrix.resize(rows);
	for(int i = 0; i < rows; i++)
	{
		_matrix[i].resize(cols);
	}
}

Hopefully someonce can point out what I am doing wrong. …

Will Gresham 81 Master Poster

An array holds data, it does not display anything.

As Ardav says, I suspect that the output of your <input> or <button> tag is what is causing the issue here.

Will Gresham 81 Master Poster

Generally speaking, you should not (as a web developer) be attempting to alter the browser functionality.

There are very few cases where this should be considered acceptable.

If you are interested in the javascript, a very quick Google search will tell you what you need to know.

Ezzaral commented: Agreed. +14
Will Gresham 81 Master Poster

If by control key you mean the key on the keyboard, you cannot with PHP.

While it is possible to disable keys using Javascript, the user turning off Javascript would render this useless.

Why would you want to disable a key anyway?

Will Gresham 81 Master Poster

Hi,This is code

if(isset($_POST['submit']))//for email
{
	$subject=$_POST['subject'];
	$desc=$_POST['desc'];
    $category=$_POST["category"];
	$experience=$_POST['experience'];
	$location=$_POST['location'];
	$company=$_POST['company'];
	$dop=$_POST['dop'];

1. Go read this:http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
2. Implement this: http://php.net/manual/en/function.mysql-real-escape-string.php
3. Never trust submitted values

if(isset($_POST['submit']))//for email
        $result= mysql_query("INSERT INTO `ihm` (`subject`, `desc`, `category`, `experience`, `location` ,`company` ,`dop`) VALUES ('$subject', '$desc', '$category', '$experience', '$location' ,'$company' ,'CURDATE()');");

Why have you got );"); at the end?
Correct structure for your query is:

mysql_query("INSERT INTO `...` (`...`, `...`, `...`) VALUES('...', '...', '...')");
Will Gresham 81 Master Poster

Windows 7 Home Premium, all software and drivers from the old card were removed.

Have also reinstalled Windows which has not helped.

Will Gresham 81 Master Poster

Hello all.

I am receiving Bluescreens when I boot my PC up, randomly one of the 3 above. This is not every time I boot the system, but at least 70% of the time.

This started when I installed a new graphics card into the PC (ATI HD5770), so my first assumption would be that this is causing the problem.
However, I would like to call on the community here and see if there are any solutions I can try myself to get this working, or if I should get on the blower to the retailer and seek a replacement card.

I have updated the drivers for the card to the newest ones available on ATI's website, I have also updated windows and the problem still occurs.
My other reason for suspecting the Graphics Card/driver would be that the system will boot into Safe Mode, although once in Safe Mode the system will generally boot to windows (a few exceptions) if I select restart. So mainly the problem is only happening on a 'cold boot'.

Any suggestions? Would it be worth calling ATI, any suggestions appreciated :)

Will Gresham 81 Master Poster

Hi all.

I am building a program to emulate a game 'Boggle', and have hit a dead end.
I have tried to search for hints online as to what I need to do from here, but everything I find is either just a block of code sparingly commented or doesn't help.

So far I have got it to find words in straight lines from any edge letter; i.e.:

Letters:
R V G E
N T W U
S D H I
V L H O

Found Words:
RVGE
RNSV
RTHO
NTWU
SDHI
VLHO
VSNR
VDWE
VTDL
LDTV
GWHH
HHWG
EUIO
EGVR
EWDV
UWTN
IHDS
OHLV
OIUE
OHTR

However, I need it to search from each letter in all directions as well.
Any hints on what I need to alter?
I stand by my signature, so no walls of code please :)

The search code:

static bool FindWord(string word = null) {
    int width = 4; // Grid width
    int height = 4; // Grid Height
    int cX = 0; // x coordinate
    int cY = 0; // y coordinate
    int d = 0; // Search direction

    for (cX = 0; cX < width; cX++) {
        for (cY = 0; cY < height; cY++) {
            for (d = 0; d < 8; d++) {
                Search(cX, cY, d, "", width, height);
            }
        }
    }

    return true;
}

static string Search(int cX, int cY, int d, string word, int width, int height) {
    string oneLetter; …
Will Gresham 81 Master Poster

Any reputable search engine will provide details of the company in their user agent string, use $_SERVER['HTTP_USER_AGENT'] to check this. There is plenty of information online with lists of search engine agents.

Even going to google and entering the exact title of this thread brings up enough information that you should be able to work out where you should be looking.

Will Gresham 81 Master Poster
Will Gresham 81 Master Poster

Look closely as the line:

echo '<script type="text/javascript">
doDecryption("<?php $myValue; ?>");
</script>';

See anything wrong?
I would suggest not outputting HTML code in an echo statement, but it is entirely up to you.

If you still don't see the problem, hint ' != "

samarudge commented: Didn't answer the question +0
Will Gresham 81 Master Poster

Vague question is vague.

Are you storing the images as BLOB data? Are you storing a relative or absolute path to the location of the image?

Your question cannot be answered without further details.

Will Gresham 81 Master Poster

A checkbox is a boolean value, look at your database field options; I am fairly confident you will find a boolean option there.

Will Gresham 81 Master Poster

Check the braces, your || is not within them.

Will Gresham 81 Master Poster

If you implement a permissions table, then you will need to add 1 new row for each relationship.

How/where you implement this is up to you, wherever it fits best in your site, or even on a new page entirely.

However, this should follow the same guidelines, only allow people who should be able to assign the permissions access to it.

Will Gresham 81 Master Poster

That all makes a lot of sense, but it seems like a lot of coding.

Not really, although if it were simple and quick to make a secure script, then everyone would be doing it.

So by coding it as indicated above, I would have to individually create a page for each member and provide access to only certain staff members. That is a lot of work.

Again, no.

Lets take an example I have knocked up quickly, replace any comments with relevant code. Note this isn't a copy-paste job, it will still require work. This will be the basic design for the 'memberinfo.php' page, I'm going to leave the previous page to you and assume that the memberid is still sent in the GET.

<?php
session_start(); //Start the session

/* Ideally this chunk should be done on another page when the staff member logs in, not on every page.
//Insert SQL statement here to get the staff

$_SESSION['id'] = $mysql_result['id'];
*/

$memberid = $_GET['memberid'];
$staffid = $_SESSION['id'];

// Sample SQL to check permission: SELECT * FROM `permissions` WHERE `staff_id` = $staffid AND `member_id` = $memberid

if(mysql_num_rows($permission query) == 0) {
  // Display an error, the staff member is not allowed to view this
} else {
  // Insert code to display info
}

?>

As I said, this will require some thought and modification on your part, I don't believe providing you with all the code will benefit you in any way. Read through that and by …

alrefai.abdulrahman commented: 5 +0
Will Gresham 81 Master Poster


The problem with benjaminFowl87s idea is that it isn't a certain user type that can generally be used. For instance, I have 5 staff members, each staff member needs to be able to see certain people, but only people in their group. And since this is done dynamically via php scripts, we don't want them to change the id and be able to access another person.

1 word. Permissions.

I will assume (bad thing to do, I know) that the data is coming from a database. Lets assume my assumption is correct.

You will need somewhere in the database to hold permissions, be that another column on a 'users' (for example) table containing the ID of the staff member responsible. Or, if there is more than one member of staff who should be able to access the details, possibly another table with multiple entries for staff/users:

id   staff_id   user_id
1    2          3
2    2          4
3    1          4
4    5          2

etc.

You should query this table, and only display the information if there is an entry in the database where the staff id and user id appear in the same row.

While you have removed the ID from the URL using the above mentioned methods, it is still absurdly easy to go into the source, alter the values in the HTML and submit the form with values other than those you supplied originally. Not secure. A will reiterate my above statement: Never, ever, …

Will Gresham 81 Master Poster

Re-reading your post, session data is set by the server, you cannot set it on the page without the data being passed to the server, so you will still require use of _GET or _POST to send the data to a server-side script.
A redirection page may serve the purpose of abstracting the data from the URL, however, it will still need to be sent.
When you say 'security' what do you actually mean? Data passed to the server can be read regardless. If you are trying to stop people from altering the query string so that they get pages or information that they are not supposed to be able to access, then I would suggest you need some data checking on your current scripts. Never, ever, trust the data a client sends, always check it was what you were expecting.

Will Gresham 81 Master Poster

The session is a server-side temporary data store, you can initialise the session by putting session_start() at the top of any page you with so utilise the session data on.

Storing and retrieving information from a session is similar to _GET, they are both arrays of data.

$_SESSION['somedata'] = 'somevalue'; //Store data
echo"somedata is set to: " . $_SESSION['somedata']; //Get data

Nothing special, as long as you put the session_start on any page you want to use session data in, it will work (Session needs to be initialised before any output is made, to at the very top of the page is a good place.

Will Gresham 81 Master Poster

I thought my collection was big...
Sega Master System II
N64
Gameboy (Original, Pocket and Colour)
PlayStation (Both big and small case)
SNES

All working and still used from time to time :D

I also have an XBOX, PS2 and PSP... but they don't count as vintage yet..
Though I doubt I will be getting the new generation of consoles for a while yet.. they seem too focused on 'pretty pictures' rather than the actual game.

Will Gresham 81 Master Poster

Change

<tr><div class=\"divider\"></div></tr>

to

<tr><td colspan=\"3\"><div class=\"divider\"></div></td></tr>
Will Gresham 81 Master Poster

You do realise this thread was almost 5 yeas old...

Will Gresham 81 Master Poster

Make sure that ldap is enabled in your php.ini file.

Will Gresham 81 Master Poster

Rather than sending the entire query through POST, it may be a better idea to send the separate bits in individual POST fields, for example, use multiple fields as follows:
- The method (select/insert/update)
- The table name
- The column name
- The value

You can then piece together the query in PHP and execute it.