minitauros 151 Junior Poster Featured Poster

If you want to obtain just the name of the file, you could also do it as follows:

<?php
    $file = 'folder1/folder2/image.jpg';
    $file_name = substr($file, strrpos($file, '/') + 1, strrpos($file, '.') - strrpos($file, '/') - 1);
    echo $file_name; // Will output "image".
minitauros 151 Junior Poster Featured Poster

Yes sir it appears to be correct :). See this page for more information.

minitauros 151 Junior Poster Featured Poster

Maybe you could try something like:

href="mailto:?subject=Welcome to my site&body=<?php echo urlencode($your_post); ?>"

minitauros 151 Junior Poster Featured Poster

Hey there. I think the array_walk_recursive function might work for you. Check it out here on the php.net website: http://www.php.net/manual/en/function.array-walk-recursive.php

You'll have to write a custom function to check the values of your array keys, though.

minitauros 151 Junior Poster Featured Poster

I think it should be working. Did you check if your $array really does contain all the values of the checkboxes you want to be checked?

minitauros 151 Junior Poster Featured Poster

Try using mysql_real_escape_string. You may be inserting a special character that messes up your PHP code. Try

$query = mysql_query('INSERT INTO Improv (
ID, 
Impressions, 
Appearance, 
Use, 
Content, 
Comments, 
Date
) VALUES (
NULL, 
"' . mysql_real_escape_string($Impressions) . '",
"' . mysql_real_escape_string($Appearance',
"'  mysql_real_escape_string($Use) . '",
"' . mysql_real_escape_string($Content) . '",
"' . mysql_real_escape_string($Comments) . '",
"' . mysql_real_escape_string($Date) . '"
)') or die (mysql_error());

Or maybe it's what pritaeas says ^^. // Edit: damn I'm a newb, must be what he says :).

minitauros 151 Junior Poster Featured Poster
$query = 'SELECT city_name, other_stuff FROM table';
$result = mysql_query($query);

while($fetch = mysql_fetch_assoc($result)
{
  $city_name = $fetch['city_name'];

  if(in_array($city_name, $array)
  {
    echo '<input type="checkbox" name="city[]" value="' . $city_name . '" checked="checked"/>';
  }
  else
  {
    echo '<input type="checkbox" name="city[]" value="' . $city_name . '"/>';
  }
}

This would print a checkbox for each city that is retrieved from the database, but only prints those with a value that occurs in $array as checked.

minitauros 151 Junior Poster Featured Poster

You could explode the comma separated string.

$array = explode(',', $comma_separated_string);

This would return an array. Then you could check for each checkbox if it's value is in the array, and if it is, check it? E.g.:

while(...)
{
 if(in_array($value, $array)
 {
  // Make checkbox checked.
 }
}
minitauros 151 Junior Poster Featured Poster

To create a radio button list (which allows only one option to be selected at a time, like in a <select>), you can create a list of radio buttons.

Instead of adding <option>s to the <select> you should just add <input type="radio">'s to your page.

<input type="radio" name="city" value="city1"/>
<input type="radio" name="city" value="city2"/>
<input type="radio" name="city" value="city3"/>

Now when the form is submitted, $_POST will have the value of the radio input that was selected. In case you're using checkboxes, which allows multiple items to be selected, the code process should be the same. For example:

<input type="checkbox" name="city[]" value="city1"/>
<input type="checkbox" name="city[]" value="city2"/>
<input type="checkbox" name="city[]" value="city3"/>

When the user submits this form, there will be an array called $_POST in PHP. If for example boxes 1 and 2 were checked, it will contain $_POST[0] = city1, and $_POST[1] = city2. Was this then what you meant? :)

minitauros 151 Junior Poster Featured Poster

Can you please wrap your code in [ code ] tags for our convenience? ;)

As for your question: If you store a password encrypted in your database, you will also have to retrieve it encrypted.

So for example if you do this:

mysql_query('INSERT INTO table (username, password) VALUES ("' . $_POST['username'] . '", '" . md5($_POST['password']) . '")

Then you would have to retrieve it like this

mysql_query('SELECT username, password FROM table WHERE username = "' . $_POST['username'] . '" AND password = "' . md5($_POST['password']) . '"

So both in your insert and select query, you should use the encrypted password. To explain this: if you insert an md5'd password, your database will contain a password like 26lj2asdf8y80sdf8y (which is an md5 encrypted password). Then, when you retrieve that password, you cannot simply retrieve the password as the user submitted it. User password "mypw" will be jasdo8gyas80ga9sg79asg6 in md5 encryption, so beware that you dont match "mypw" against the md5 version in your db. You should first encrypt the password that the user submitted when he logs in and THEN match it against the encrypted password in your database.

minitauros 151 Junior Poster Featured Poster

Hm I'm still not sure what you mean, but if you for example have this checkbox

<input type="checkbox" name="imacheckbox" value="hello"/>

then $_POST will have the value "hello". Is that then what you mean?

minitauros 151 Junior Poster Featured Poster

Its not loading slowly at all. And yea, I see now, it's the white banner at the top I was talking about. I thought it was just plain white space. No problems there, then, only that the quality of your background image is a bit low hehe ;). Oh yeah, and the "Enter site" button remains unclickable - the text slides to the right before I can click it.

minitauros 151 Junior Poster Featured Poster

So the problem is solved? ;)

minitauros 151 Junior Poster Featured Poster

If you have a multiple-steps form, you could consider temporarily saving form information in a session. If you don't know which information your post data contains, you can print the post data on your screen as follows:

<?php
print_r($_POST);
?>

This will print all the data the user has submitted through a post on your screen. It will also contain the values of your checkboxes, in case you need to check what those values are.

Hope that's what you meant? :)

minitauros 151 Junior Poster Featured Poster

I have no problems viewing your page, but I seem to be unable to click the Enter Site button: it moves away when I try to click it :P. Also after I have entered, the background does not fill up the entire screen as it does on the intro page.

minitauros 151 Junior Poster Featured Poster

If you put

alert('datas: ' + datas);

(or console.log, whatever you like) in your AJAX' success: ... part, does it output the correct data?

minitauros 151 Junior Poster Featured Poster

Is there a specific need to show it as JSON? Also, if you want to display it as HTML output, why not just make your headers output it as HTML?

minitauros 151 Junior Poster Featured Poster

It might be me, but I don't completely understand what your question is. Or, better said, I understand your question, but the context is kind of unclear to me.

minitauros 151 Junior Poster Featured Poster

For example if you have two computers (that are on the same local area network!), the computer with the name "ComputerA" is running XAMPP, and you want to access this XAMPP server from the computer with the name "ComputerB", then here's what you do:

On ComputerB, start up your web browser. In the address bar, type: ComputerA/projectname. For example if you have a project called "testproject" in your XAMPP's htdocs folder, you can access it by going to "ComputerA/testproject". Hope this helps :).

minitauros 151 Junior Poster Featured Poster

Here's a good tutorial on regular expressions:

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

In your case, I think you're looking for something like

preg_match('/^[0-9A-Za-z_\-]+$/', .....)

Which returns true if the input string contains nothing more than letters, numbers, underscores and dashes, or indeed, like pritaeas says

preg_match('/^[\w-]+$/', .....)

which is similair to that.

minitauros 151 Junior Poster Featured Poster

For example you could create a 128 length password field for a sha512 hash, which is much more secure than a sha1 hash.

You would compare the form result with the database result, and if it matches, the user will be logged in. Something like:

$password = hash('sha512', $_POST['password']); // Encrypts the $_POST['password'] to a 128 character hash.
$query = 'SELECT ..... FROM .... WHERE password = "'.$password.'"';

The password in your database must be stored encrypted to make this work.

etc.

Then:

if(retrieved user rank == 1)
{
  header('location: admin.php'); // Redirect to admin.php
}
elseif(retrieved user rank == 2)
{
  header('location: user.php'); // Redirect to user.php
}
minitauros 151 Junior Poster Featured Poster

$string_exp = "/^[A-Za-zé\.¸UûÙùàÀèÈéÉïÏîÎôÔêÊçÇ \,\\\'\-]+$/";

Although I'm not sure if all those special characters will work. Never tried it, so I'm not certain.

minitauros 151 Junior Poster Featured Poster

I don't know everything about regexps, but a dot should be escaped, or it will be treated as "any character". A dot matches any charachter if it is not escaped properly.

Same goes for the comma and dash, backslash and ', in other words, all characters that have a function within a regexp. They should all be escaped properly. [A-Z] means A to Z, while [A\-Z] means A, - and Z.

minitauros 151 Junior Poster Featured Poster

The "var" prefix was used in PHP 4. In PHP 5, you don't need to use the word "var" to declare a variable. In PHP 5, however, a warning will be generated if error handling is set to E_STRICT.

minitauros 151 Junior Poster Featured Poster

It should be:

if (!preg_match("/^[A-Za-z0-9]{3, 20}$/i", $_POST['brugernavn']))

The {3, 20} part checks if the length is between 3 and 20 characters.

pritaeas commented: Well spotted, missed the comma. +13
minitauros 151 Junior Poster Featured Poster

If you put a "From:...." in your $headers, there's no need to add it again in your additional parameters :).

minitauros 151 Junior Poster Featured Poster

Well, I don't think there's much difference between executing 4 different queries in one query and executing 4 different queries apart from eachother.

I've never tried it, but I don't think executing 4 counts in one query will work. Besides that, COUNT just counts the rows that are selected, so if your first query counts 3 rows, and the second one counts 6 rows, the result will be 6, not both 3 and 6 (for as far as I know).

So I'd say: just execute the 4 queries apart from eachother. That'll work for sure.

minitauros 151 Junior Poster Featured Poster
minitauros 151 Junior Poster Featured Poster

For as far as I know, executing a COUNT instead of count_num_rows is faster, performance wise.

Your new query would look like

SELECT COUNT(a_unique_field_occuring_in_every_record_that_is_selected) AS num_rows, * FROM products ORDER BY dateadded DESC

I'm not 100% sure if it is faster though, but with this query, you could use mysql_fetch_assoc to fetch your results. $fetch will then be the number of rows.