minitauros 151 Junior Poster Featured Poster

I guess so. In your script above you are doing the following:

$password = $_POST['password'];
$hmac = hash_hmac('sha512', $password, file_get_contents('textfiles/key.txt'));

And then you compare the given password to the one in the database as follows:

if(crypt($hmac, $hash) === $hash)
{
    // Login info is correct.
}

Are you using the exact same way of encrypting the user's password when he registers? So is the encrypted password that is generated during the reigstration process the same as the encrypted password that is generated during the login process?

minitauros 151 Junior Poster Featured Poster

Nothing wrong with it. Simple. Maybe you could add some more details :).

minitauros 151 Junior Poster Featured Poster

The inputs will indeed need new names. Maybe you could add square brackets to the names, to make them an array? PHP will be able to work with that. Example:

$(document).ready(function()
{
    $('select[name=options]').change(function()
    {
        var number_of_forms_to_create = $(this).val();
        var form = $('form#form1').clone();
        var target = $('div#test');

        for(var i = 0; i < number_of_forms_to_create; i++)
        {
            var clone = form.clone();

            // Unset the form ID.
            clone.attr('id', '');

            clone.prependTo(target);
        }
    });
});

The input names should be changed to, for example, "name[]" and "email[]".

minitauros 151 Junior Poster Featured Poster

Well I'm not sure, but I don't think you can insert a whole new <thead> and <tbody> into an existing <tbody> straight away. I think you should either insert a whole new <table> into a <td> tag of an existing table, insert <tr> tags into an existing <tbody>, or insert a new <tbody> into an existing <table>. Inserting <thead> into a <tbody> is not how it is supposed to work, for as far as I know.

Therefore, why don't you just clone the whole table you want to clone and copy instead of just the <tbody>, and insert it into the <td> tag of the new table instead of into the <tbody>?

E.g.:

var clone = $('table#scroll').clone();
clone.appendTo('tr#2');
minitauros 151 Junior Poster Featured Poster

Yes I guess that would be it, then :). Check if the password that is inserted during the registration process is the same as the one that is checked against during the login process (by checking if the encrypted values of the exact same password is the same in both places).

minitauros 151 Junior Poster Featured Poster

And have you validated that the password that you are submitting through the form is actually the same as the one in the database? In other words: if you KNOW the password in the database is "shoelace" and if you are also sure the submitted password is "shoelace", but if the encrypted passwords differ from each other, there must be something going wrong in your encryption process.

minitauros 151 Junior Poster Featured Poster

Might be that your webhost has register_globals enabled. Register_globals is deprecated since PHP 5.3, so if this is the case, your webhost is running an older PHP version. I guess you can see if register_globals is turned on or off by using phpinfo(), but I'm not sure.

minitauros 151 Junior Poster Featured Poster

Why don't you just clone the table's <body> element's content and insert it into the other table's body? Why are you cloning the whole table and to which exact element are you cloning it? A <td> element in the other table, or another element?

minitauros 151 Junior Poster Featured Poster

I guess something like this should work:

$('table#your_table_id tr').not(':first').remove();
minitauros 151 Junior Poster Featured Poster

From which point up is it going wrong? Is the user with the given username even being retrieved? Or does shit hit the fan when you compare the given password with the password in the database?

minitauros 151 Junior Poster Featured Poster

If you tell jQuery to element.after('<tr>');, the <tr> part is interpreted as "<tr></tr>" (as a whole tag). Therefore you should use another way to create the table you want. For example (with example data):

var table = $('table#table_id');
var tr = $('<tr>');
var td;

// Create a <td> tag, fill it with text and prepend it to the <tr>.
td = $('<td>');
td.html = 'text';
td.prependTo(tr);

// Create another <td> tag, fill it with text and prepend it to the <tr>.
td = $('<td>');
td.html('text2');
td.prependTo(tr);

// Append the <tr> to the table.
tr.appendTo(table);
minitauros 151 Junior Poster Featured Poster

Well, can't you loop through your queries and validate that the correct data is being inserted? You could break the loop when the error occurs, showing you which data is generating the error.

minitauros 151 Junior Poster Featured Poster

This is not an error, not a warning, but merely a notice. It seems to be caused by $_POST['check'] not being defined, while your script is trying to access it. You can modify which errors are being reported by using the error_reporting() function, if you wish to not display notices, but (for example) only warnings and fatal errors. Besides using error_reporting(), you can also modify the error reporting value in your php.ini file (if I'm not mistaken).

minitauros 151 Junior Poster Featured Poster

Tip: If you use time() or microtime() in your random number somehow, you will generate a number that is much more likely to be unique, which means you may have to execute less database operations (less queries are needed to find out if a number already exists, for the number will probably always be unique).

minitauros 151 Junior Poster Featured Poster

What do you have so far?

minitauros 151 Junior Poster Featured Poster

You could do that, but why don't you just save the image on the server, and save a link to it in the database, which you can use to display the image? :)

Oh, and what is it that you are asking, exactly?

minitauros 151 Junior Poster Featured Poster

What about displaying, for example, no more than 50 records per page, so that a maximum of 50 rows will be updated at a time?

And then about updating a large amount of rows: each row contains data that is unique to that row, so you will probably have to run a query for each row. You modify a row by its primary key, which means each row will need to be updated separately. Except, of course, if changing the values of all rows at once.

minitauros 151 Junior Poster Featured Poster

Interesting point about the life time span of a car and its impact on the environment when people get rid of it to buy a new car. I've never even thought about that :o.

minitauros 151 Junior Poster Featured Poster

Okay, good luck then!

minitauros 151 Junior Poster Featured Poster

Glad that it's working :). But why are you executing the exact same query twice? Seems like you can re-use the result stored in $count1_result instead of having to create $result2.

minitauros 151 Junior Poster Featured Poster

(However, note that the mysql_* functions will be deprecated in the future, so it is recommended you use another extension for making a MySQL connection, for example PDO or MySQLi.)

minitauros 151 Junior Poster Featured Poster

Hmm well, taking that I assume that you will be working with a huge bunch of rows, and that you will probably need to build pagination possibilities.

What you could do is the following:

SELECT *
FROM login
ORDER BY user ASC,
date DESC
LIMIT 50 -- Example limit

This will simply select the first 50 logins from the logins table, starting with the usernames starting with an A, moving up to the Z. Per username the results will be ordered by date.

Then you could use PHP to traverse to the results and display everything you need. For example:

<?php
if($results) {
    foreach($results as $result) {
        $date = $result['date'];
        $username = $result['username'];
        $status = $result['status'];
        $display_username = false;

        if(!$last_used_username || $username != $last_used_username) {
            //* Either we're working with a new username, or this is the first row.
            $display_username = true;
        }

        $last_used_username = $username;
        ?>
        <tr>
            <td>
                <?php if($display_username) echo $username; ?>
            </td>
            <td>
                <?php echo $date; ?>
            </td>
            <td>
                <?php echo $status; ?>
            </td>
        </tr>
        <?php
    }
}

Would this be of any help?

minitauros 151 Junior Poster Featured Poster

Well, it appears to me that he then wants the most recent logins, not necessarily grouped by username. You could solve this problem by simply retrieving the last x number of rows and displaying those one by one. You could use the DISTINCT() selector to select only unique usernames. E.g. SELECT DISTINCT(username), * FROM logins ORDER BY date DESC.

Would that be a solution to your problem?

minitauros 151 Junior Poster Featured Poster

What abouuuut you select the logins only for the user that is logged in? :) For example SELECT * FROM logins WHERE user = "julius".

You will then only fetch the login records for that user, which you can display one by one.

Alternatively, you can use an ORDER BY clause to sort your results per user, or per date. E.g. SELECT * FROM logins ORDER BY user ASC, date DESC to sort by the username (ascending) first, and then by the login date (descending) second.

minitauros 151 Junior Poster Featured Poster

What is it that you want to do, exactly? If you need to "refresh" the content of a div, doesn't that mean you need to check if new data is available?

Or do you just want to load new, already known data into a div after a specific amount of time?

minitauros 151 Junior Poster Featured Poster

I guess that the problem is that you are trying to display XML as XML in an HTML document.

It works like this: Your HTML document has already told your browser it's an HTML document. Therefore your browser will treat your document as an HTML document. If you want the XML to be displayed as how a plain XML file would be displayed if you'd open it with your browser, you need to create a whole new browser window and tell that window that it is an XML - not an HTML - file it should display, and then output the XML.

As M.Qawas Aslam says, using an iframe might do the trick. If that doesn't work, I suggest you open a whole new tab or browser window to display the XML. Or, alternatively, you could search for options to display XML as XML without opening a new window.

M.Waqas Aslam commented: Thanks for explanation :) +7
minitauros 151 Junior Poster Featured Poster

Yes, so that basically means that the returned value is NOT an integer, right? :) So that means that you are comparing a non-integer against an integer, which is why your if() statement isn't working as you want it to. I guess you'll first need to convert the returned value ("+1 day") to an integer, and then throw it into your if() statement.

minitauros 151 Junior Poster Featured Poster

Well, according to the examples in the manual, DateDiff::format() does not always return an integer. That's why I said: you should check what it is returning, because you're comparing it against an integer, and you cannot really compare a string value against an integer. If you know what I mean :). Maybe you can find another way to find out if this is what is happening, if var_dump() isn't returning anything (which I find weird, 'cause for as far as I know it always returns something and prints it on the screen).

minitauros 151 Junior Poster Featured Poster

You should place the var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a')); line before the if statement if you want to make sure it is executed :). Does it return an integer, a boolean, or something else? And what exactly?

minitauros 151 Junior Poster Featured Poster

I'm not sure, but I don't think that that function is returning an integer, which is what you are comparing it against.

I suggest you check out what exactly is being returned by the format() function, e.g.:

var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a'));
minitauros 151 Junior Poster Featured Poster

If your purpose is to hide your PHP code, don't worry, because as diafol says: that isn't visible to the client.

minitauros 151 Junior Poster Featured Poster

This is great, guys, thanks for so many useful tips :). Much appreciated! If anyone still has anything to add: I'm still interested, of course!

minitauros 151 Junior Poster Featured Poster

Thanks for the tips, guys! We're actually more into visiting nature/national parks, less into visiting a lot of cities. What do you think about taking a tent with us and using that in combination with a rental car? I heard it's free camping in most places there. Is there anything to watch out for?

minitauros 151 Junior Poster Featured Poster

So I'm planning to make a trip through the US. More specifically: through the west of the US (San Fransisco, Las Vegas, that area).

I was wondering if you had any tips for me. It would be a 2-person trip of 20 days. Our plan was to rent a car or a campervan (van in which you can sleep). We prefer the campervan but it's fairly expensive (at least it sounds like a lot of money to me, $1450 for 19 days). Anyone know any good alternatives or have any other suggestions? Thanks!

minitauros 151 Junior Poster Featured Poster

You could try using HTML2PDF. It's a (for as far as I know) free PHP class to convert.. HTML to PDF, yea! (guess you didn't see that coming).

Create a PHP file, generate a PDF in it and set the headers so that the file will be seen/handled as a PDF file by the browser. That's a way it should work :).

minitauros 151 Junior Poster Featured Poster

So.. do you have a start on this project? What have you created so far? :)

minitauros 151 Junior Poster Featured Poster

Have you tried opening a new window with Javascript? You can use the window.open() function for that, if I'm not mistaken.

minitauros 151 Junior Poster Featured Poster

I think this post might help you: http://stackoverflow.com/questions/4110907/how-to-decode-a-base64-string-gif-into-image-in-php-html

According to that post and a bit of experience in such matters, you either have a PHP page that outputs ONLY the image, and then put that page inside an <img> element's "src" attribute (e.g. <img src="image.php?id=1">), or you use something like <img src="data:image/gif;base64,<?php echo $base64_encoded_image; ?>">.

minitauros 151 Junior Poster Featured Poster

Maybe you can use curl for that? :) Example: http://davidwalsh.name/curl-post

minitauros 151 Junior Poster Featured Poster

You start a session with session_start(). That should probably be one of the first lines, if not the first line, of any of your files in which you want to use the session.

Then, after starting the session, you can save values to it or retrieve values from it, using $_SESSION. E.g.:

Page 1:

<?php
session_start();
$_SESSION['test'] = 'hello';

Page 2:

<?php
session_start();
echo '<p>The session value for test is now: ' . $_SESSION['test'] . '</p>';

Hope that helps a bit ;). If not, have you tried searching Google for tutorials on PHP sessions?

minitauros 151 Junior Poster Featured Poster

The imagejpeg() function tries to create a JPEG file in the given directory. If the permissions for that directory are set so that an image cannot be created in it, you will get an error such as the one you are currently getting. Permission denied simply means that the server has no rights to write to the target directory.

Regularly you fix such an issue by chmodding the target directory. In FileZilla you can do this by right clicking the folder and clicking "permissions" (I think). Try setting it to 755, or 777 if that doesn't work. Be warned however that the last enables anyone to write to the folder (not an expert on this subject though, so I can't help you any further than this).

minitauros 151 Junior Poster Featured Poster

I'm not sure but maybe the RAND() should be something your select returns. Just a piece of thought, though. Something like

SELECT RAND() AS rand_nr
ORDER BY rand_nr DESC

Just a question though: what use does it have to create a random order, after you've already ordered by relevance?

minitauros 151 Junior Poster Featured Poster

Of course you are encouraged to create such a slideshow yourself, because it's a nice opportunity and a very good way to practice your programming. However, there are thousands of slideshow plugins out there, and if there is no real need or desire to create one yourself, why don't you pick one of those and use that? :)

The basics of a slider:

One viewport div with overflow: none.
One container div.
A lot of slide divs that may contain other divs with images, text, etc.

The slides go into the container div. They should be lined up horizontally, creating one large slide. When the user presses a button, you slide this gigantic slide (the container div) to the left or right, so that a different part of it comes into view in the viewport div.

Hope that's of any help!

minitauros 151 Junior Poster Featured Poster

Well it seems like this should be working. Only thing that I see is wrong (in case you haven't found it yet yourself) is the misplacement of your semicolon on line 23. It shouldn't be include ("inc/OutletsIn" . $country_selected .".php";) but include ("inc/OutletsIn" . $country_selected .".php");.

minitauros 151 Junior Poster Featured Poster

PS: A link table is an extra table that stores which products are connected to which categories. E.g.:

Table categories_products
category_id | product_id
1 | 5
1 | 6
1 | 9
2 | 5
2 | 7
2 | 10
3 | 6
3 | 9

Select all products in category 1:

SELECT products.*
    FROM categories_products
    JOIN products
        ON categories_products.product_id = products.id
    WHERE categories_products.id = 1
minitauros 151 Junior Poster Featured Poster

Not sure but I think it's not recommended you place HTML elements outside your <body> tags (which is what your CSS is doing with the black bar).

minitauros 151 Junior Poster Featured Poster

Are you asking how you can use the item that the user selects in your <select> to fill another <select> element?

minitauros 151 Junior Poster Featured Poster

Yes you can :). Do you have any experience in using AJAX? If not, this might be a nice tutorial to start: http://www.w3schools.com/jquery/jquery_ajax_intro.asp

minitauros 151 Junior Poster Featured Poster

In line 2, you are comparing session to null. However, firstly, there is an error in your code here, as "session" is no PHP language. It should either be $session or $_SESSION. If you want to check if a session has been started, I recommend you use session_id() to check that, instead of just $_SESSION.

Secondly, you are now returning some HTML. I would rather return true or false, and then echo some HTML according to if true or false is returned when you execute the function.

Third, you are not executing your function correctly in your HTML. Instead of executing the function, you are redefining it. You could try this:

<?php
public function isLoggedIn() 
{
    if(!session_id()) {
        // No session ID has been set.
        return false;
    }
    else {
        // Session ID has been set.
        return true;
    }
}
?>

<ul>
    <li><a href="index.php">Home</a></li>

    <?php
    $is_logged_in = isLoggedIn();

    if($is_logged_in) {
        echo '<li><a href="login.php">Login</a></li>';
    }
    else {
        echo '<li><a href="logout.php">Logout</a></li>';
    }
    ?>

    <li><a href="allstock.php">All Our Stock</a></li>
</ul>
minitauros 151 Junior Poster Featured Poster

In your Javascript console, do you get a confirmation of your AJAX request being executed?