FlashCreations 20 Posting Whiz

Well your problem is here:

if (!in_array($dirArray[$i],$fileName_database['filename'])){

The first parameter of the in_array() function should be the value to seach for, the second, the array:

if (!in_array($fileName_database['filename'],$dirArray)){

EDIT:
To fix the other problem on line 48:

if (!in_array($fileName_database['filename'],$dirArray)){

Wait, this might not work. Let me think about it for a second!

FlashCreations 20 Posting Whiz

I just wrote a pagination script (for another DaniWeb User). Let me find the link to it and I'll show you my code...

EDIT:
Here's the link:
http://files.phpmycoder.net/1209da

I believe mine does 10 a page, but that is easily fixed. Just read the Readme in the ZIP file and you should find something about changing the items per page. If you can't, you can change the number of results per page by passing the number to the constructor of the pmcPagination class when you create it:

//pmcPagination(resultsPerPage, getVariable, data)
$instance = new pmcPagination(20, "page", new paginationData("test"));

You can also set the results per page by calling the function setResultsPerPage() with the number of results per page as the only parameter.

You can even set this number when calling paginate() the same way as you can when creating the instance of pmcPagination.

FlashCreations 20 Posting Whiz

Well the first thing I see is you need an end quote in the first line (You also need to research the first function, mysql_connect: its host, username, password):

$con = mysql_connect('HOST', 'USERNAME', 'PASSWORD') OR die("Error: ".mysql_error());

You also have a problem with your protect function. Use the mysql_real_escape_string() function rather than stripslashes() . I would also not use pass-by-reference so you can modify the actual POST variable instead of creating a new variable for each field.

function protect(&$string) { $string = mysql_real_escape_string($string)); }

I would also suggest cleaning up your variable checking. So fixed you code should look like this:

<?php
function protect(&$string){ $string = mysql_real_escape_string($string); }

mysql_connect('HOST', 'USERNAME', 'PASSWORD') or die("Could establish a connection");
mysql_select_db('my database') or die("Could not connect to the database");

if($_POST['submit']!="Register")
{
    echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"center\">\n";
    echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";
    echo "<tr><td colspan=\"2\" align=\"center\" bgcolor=\"#333333\"><font color=\"#ffffff\">Registration Form</font></td></tr>\n";
    echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
    echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
    echo "<tr><td>Confirm</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n";
    echo "<tr><td>E-Mail</td><td><input type=\"text\" name=\"email\"></td></tr>\n";
    echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Register\"></form></td></tr>\n";
    echo "</form></table>\n";
} 
else 
{
    //Protect $_POST Variables
	protect($_POST['username']);
    protect($_POST['password']);
    protect($_POST['passconf']);
    protect($_POST['email']);
	
	//Define errors array
    $errors = array();

    //Validate POST Variables
	if(empty($_POST['username'])) $errors[] = "Username is not defined!";
	if(!ctype_alnum($_POST['username'])) $errors[] = "Username can only contain numbers and letters!";
	if(strlen($_POST['username'])>=1 && strlen($_POST['username'])<=32) $errors[] = "Username must be between 1 and 32 characters!";
    if(empty($_POST['password'])) $errors[] = "Password is not defined!";
	if(empty($_POST['passconf'])) $errors[] = "Confirmation password is not defined!";
	if(!empty($_POST['password']) && !empty($_POST['passconf']) && $_POST['password'] != $_POST['passconf']) $errors[] = "Passwords do not match!";
    if(empty($_POST['email'])) $errors[] = "E-mail is …
FlashCreations 20 Posting Whiz

Alright, it's done! You can download the demo from: http://files.phpmycoder.net/da0110v

FlashCreations 20 Posting Whiz

So what exactly do you want? Insert the file name into a db?

FlashCreations 20 Posting Whiz

Oh ok, I get it now! What you need to do is just use the $dbroomno variable after the puzz_ like this:

if($puzzleNum<7 && $puzzleNum>0) { 
  mysql_query("SELECT * FROM user_info WHERE id = '".$_SESSION['userid']."' AND puzz_".$puzzleNum." = '". $dbroomno);
}
FlashCreations 20 Posting Whiz

And your probably right, they aren't the best. I believe a plane would be the easiest example. What if you had a table of plane flights that included a departure city and arrival city. It could also include other details such as flight number, departure and arrival times. Then simply find all the flights that depart from the user's city on the day and approximate time requested. Then work a flight plan for each of them and then eliminate the ones that are too long or don't end up in the users requested city. From there you could also filter by distance (Using a table of city distances) and trip time (using the arrival and departure times in the flights table, along with layover times). It's not simple, but I think it could work.

The same principle could be applied to trains, buses, boats, or any kind of transportation with a planned schedule of point A to point B. Cars and walking will be a lot more complex because there's no point A to point B trips. The driver has control and can go pretty much anywhere. For this situation you would need a digital map that you can use to trace a route, obeying street signs. You can calculate times by using the speed limit and miles driven for each street on the route.

EDIT:
For the first solution, may I suggest a recursive function.
Also, I forgot to mention, nice thread. This is a …

FlashCreations 20 Posting Whiz

Hmm, well I'm no Mac expert, so bear with me here. Look in the Mac's equivalent to Program Files and see if there are multiple installations of PHP. Maybe the folders have different names? If that doesn't work, you can always check the Mac's list of processes to see if there are multiple PHP's running. You'd have to ask a Mac expert to be sure, because all I can give you is Windows equivalents!

FlashCreations 20 Posting Whiz

Well, let me ask the simple question: Does GD work? Can you make a simple image with it or does it fail to initialize?

FlashCreations 20 Posting Whiz

I don't think PHP is the appropriate language for this. This project might be a bit beyond it's capabilities. The best I could do with PHP is maybe write some JavaScript to use the Google Maps API. Why re-invent the wheel, when Google has perfected it. I'm sure with the API you can calculate trip distances and times (but I'm not sure).

FlashCreations 20 Posting Whiz

If anyone has any ides this would be amazing as it would save me having to write an if statement for each puzzle.

Daryll

Since there are multiple puzzles, a switch statement would probably be a better option (It's a bit less than an if, but I guess you could use If/Else if you really had your heart set on it).

As for your MySQL, I'm not quite sure what you want. You talked about puzzle tables, yet your SQL has another table in it. What's $dbroomno ? What's Puzz_whatever ?

FlashCreations 20 Posting Whiz

The problem is that C:\Documents and Settings\Sando\Desktop\boys.gif is a file on your desktop. It works on localhost, because that file exists on your desktop. You need to upload the boys.gif file to Bluehost and change the line that opens that file.

EDIT (AFTER EXAMINING YOUR CODE FURTHER)
Just wondering, are you trying to upload a file. It seems to me like you are, and sadly, fopen will only work on the server. To understand how to upload files to a PHP script, read this article by Tizag.

FlashCreations 20 Posting Whiz

I understand what you need. I'm just saying your missing a State/Province field. Do you want one?

FlashCreations 20 Posting Whiz

So I'm assuming you want the mock-up...I'll get started.
Happy New Year!

FlashCreations 20 Posting Whiz

Oh, my bad! Sorry about asking for the code again...don't know what I was looking at! What you need is a simple fix. I'm working on it right now and will post it soon! While working, I did notice you forgot a field for State/Province. Is this intended?

FlashCreations 20 Posting Whiz

Well it looks like the link to images on your index doesn't work. It sets type=Images, but for some reason, with no results. To diagnose this problem, I will need to see your code for index.php. If you don't feel comfortable posting it on the forum, you can PM me. I'll try to do my best at fixing the issue with the different search types.

EDIT:
I will not disclose them here, but I have noticed several extreme security loopholes in your system. If you would like I could also look into these and help you fix them.

FlashCreations 20 Posting Whiz

Well, good luck with whichever solution you chose. If the problem with the colors still persists, try viewing the source of the page and copying the CSS into a CSS validator. If it doesn't check out, you can post back here and we'll help you fix it.

FlashCreations 20 Posting Whiz

Drop-down boxes would certainly seem easier. A word of warning with them. Still validate their values (maybe check it against a valid array), because Firefox addons like Firebug can easily alter their values, which, would not be devastating since the changes only affect them, but still would be a security vulnerability.

You can still allow the user to pick his or her own colors. You just need to think of all of the possibilities and prevent them from being a problem. You already have done some of this and I would suggest it. A looser input is more user friendly...Allowing the user to enter white of #FFF or #FFFFFF or rgb(0,0,0) ensures that all of your bases are covered.

For this loose format you can use Regexes to find if the input matches all of the types you accept. If the field is blank or has an unrecognized type, just send it back with an error message and have the user try again (Best to do this with JavaScript instead of PHP. I've cussed out many website for making me fill out a really long form from scratch because the CAPTCHA is illegible!)

FlashCreations 20 Posting Whiz

Ahh...funny enough I did something similar as one of my first large PHP projects. The code I wrote back then was quite atrocious, but its gotten better :P. It was pretty straightforward then, but if at all possible, I would use OOP. Like you said, you only need a backend now, and I would naturally suggest PHP.

Along the lines of how, you need a MySQL table with a rows for id, IP (or username if you have a user system), and vote. The vote value is the most important, since it holds the user's vote (Surprise there!). Anyway, one of the first things I tried was a MySQL table with candidates and total votes stored as a field in their table. This is a NO! There are so many problems with this system; so trust me, make the votes and the candidates separate in MySQL. I suggest a table of votes, with the vote field being an enum with the id of each candidate or the name of their corresponding radio button.

With this, all you will need to do in PHP is validate that the user hasn't already voted (If they have, you can alter their previous voting row) and then add their IP (or username) and vote to the table. To tally, simply get all of the rows from the table and use an array to count the totals. You can then use sort() to sort the results array.

If you would like, I …

FlashCreations 20 Posting Whiz

Alright, so if the site is targeted towards web developers then you can allow them to enter hex codes. Just make sure that the entered codes are uniform. If the user doesn't put a # at the beginning, put one there for them. If the hex is in shorthand (#F60), elongate it (#FF6600). If there are missing numbers (or letters... #F9), put zeros to fill the empty space (#F90000).

FlashCreations 20 Posting Whiz

You cannot install wordpress just for a function. The functions that come with wordpress are meant to be used within wordpress. Why not create your own user system. It's must easier than trying to piece-meal one together from pre-written scripts.

FlashCreations 20 Posting Whiz

IMO: FlashCreations has answered your query.

Thanks ardav! :)

FlashCreations 20 Posting Whiz

Sure no problem. The solution I provided doesn't require $_GET or $_POST , nor does bodiandras'. Regarding mine, all you have to do is echo the variables from PHP into a script tag. Before you echo the </head> tag, simply output a script tag. Inside it declare some javascript variables and set their values to the values of the PHP variables like so:

<!doctype>
<html>
 <head>
  <?php
    $shared = "hey javascript!"; //A variable to be shared
    //Here we are writing some JavaScript that declares the variables from PHP
    echo "<script type='text/javascript'>\n";
    echo "var shared = '".$shared."'"; //Here I wrote javascript code to set the javascript variable shared equal to the PHP variable
    echo "</script>";
  ?>
 </head>
 <body onload="alert(shared);">
 </body>
</html>

Try this code. It should work. The only thing to note is PHP is server-side so it runs before the javascript which is run on the user's browser. Because of this, PHP can pass its values to JavaScript, but JavaScript cannot change the value in PHP. This is not because of a restriction, but because of the fact that the PHP will have completed execution once the JavaScript begins to run.

FlashCreations 20 Posting Whiz

Alright here's a little example. Simply create an instance of pmcPagination and call $instance->add(); with the only argument being an instance of paginationData() with one data entry to be included in the pagination or an array of these instances. To show the page call $instance->paginate() . You can pass the number of results per page and/or name of a get variable to use as the page number (and will also be used for all links..the default is "page", so the urls will be ?page=1). Most of the other functions of pmcPagination() are pretty self-explanatory. I've provided the file that holds the classes that you should include for pagination and a demo file..so showcase the features:

You can find the zip file: http://files.phpmycoder.net/1209da/

FlashCreations 20 Posting Whiz

sir like this

http://www.eastasiaroyalehotel.com/

im referring to that one, in reserve now area you choose your check in hotel, check out and etc after you choose if you click proceed it goes to this link

http://www.eastasiaroyalehotel.com/reservation.php

how to do that sir? if i choose january 1 in my index.php i will post it on my textfield what he choose in index.php.

But are you willing to share your code?

FlashCreations 20 Posting Whiz

Are you using wordpress?

FlashCreations 20 Posting Whiz

Yes, it could be. I would suggest a static color picker (Most users don't know about hex's) or a backend system that checks a color before it is placed in the database. This way you can ensure that a color is always displayed (Because the user could have entered some color followed by a semicolon and some more css. The user could have even inserted javascript with this loose input system. This is a horrible XSS Vulnerability.)

diafol commented: really good point - he needs a 'real colour' dropdown or something +5
FlashCreations 20 Posting Whiz

If I'm not mistaken, Google frowns upon the checking of page ranks like this. They might have prevented your site from checking.

My guess is that your PHP does not allow sockets, but there could be another reason.

FlashCreations 20 Posting Whiz

Yeah well sorry again about the re-post, but thanks for the perfect geeky joke opportunity!

FlashCreations 20 Posting Whiz

Why not pre-load some data instead of using AJAX. It makes much more sense to me, but if you insist, have you checked out W3SChools AJAX tutorial?

Here's a little demo of what you're looking for:

function getPopulation(country)
{
  ajax = getAjax();
  if(ajax)
  {
    ajax.onreadystatechange = function() { alert(country."'s population is ".ajax.responseText); }
    ajax.open("GET", "population.php?country=".country, true);
    ajax.send(null);
    return true;
  }
  return false; //Browser doesn't support AJAX..possibly fall back to hard-coded numbers
}

function getAJAX()
{
  if (window.XMLHttpRequest) return new XMLHttpRequest();
  else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  else return false;
}
FlashCreations 20 Posting Whiz

I couldn't resist. :D
Now that I think about it, that was a pretty nerdy PHP joke, but oh well. :)

FlashCreations 20 Posting Whiz

Do the values in MySQL have a # before the color hex (or if it's rgb, is there a rgb( ) surrounding the pair of numbers)?

FlashCreations 20 Posting Whiz
echo "Assuming the file you posted is called z_register_parse.php, I would guess that the error is inside z_join_form.php. It's probably a missing PHP end tag ?> , but it could also be a missing bracket or other non-terminated statement. Post your code for this file and we can tell you the exact problem.";

Now there is...sorry about that!

FlashCreations 20 Posting Whiz

Try restarting your machine. I find (On Windows, though, not Ubuntu) that even if I restart apache, the php.ini doesn't update until after a restart.

FlashCreations 20 Posting Whiz

Have you tried an OOP approach. I use an OOP paginator on my site, and I usually find OOP much easier to use. Why not try creating a class to hold a result and then create an array of the result objects. You can figure page numbers by using ceil(count($resultArray)/$itemsPerPage) . If you wish to take this approach, I can write a simple pagination class for you to take a look at. Let me know.

EDIT:
Just to clarify, to determine the number of pages, you need to round up since .5 a page would mean you need an extra page to show those extra results that don't fit perfectly on a page.

FlashCreations 20 Posting Whiz

Assuming the file you posted is called z_register_parse.php, I would guess that the error is inside z_join_form.php. It's probably a missing PHP end tag ?> , but it could also be a missing bracket or other non-terminated statement. Post your code for this file and we can tell you the exact problem.

FlashCreations 20 Posting Whiz

You cannot get an external MAC address of a user without having local LAN access to them... UNLESS: you have access to a good ARP table and only if the client is connected DIRECTLY to the php server (if there are routers/gateways that NAT the traffic, the returned MAC address will be that of the gateway)

Here is a script to retrieve local MAC addresses via PHP (on Windows):

LOCAL MAC via PHP

There are easier methods to restrict access via PHP....
i.e. user/password, ip filtering, etc....

HTH's

I agree, MAC Address filtering seems very difficult, but a word of warning with IP Filtering. If a network connects to the internet through a router or server, several computer could have the same IP address. When banning IP's be careful that your not banning an entire network (such as a school or business).

FlashCreations 20 Posting Whiz

As Shawn said, what you are looking for is a technique used in many programming languages called passing by reference. Instead of giving the function the value the variable, the place where the variable is stored in memory is given so that function is free to edit the variable (or array). If you are familiar with C, they are called pointers (and they are very similar in PHP, with the exception that in C arrays are automatically passed by reference since they are really several variable in sequence).

To replicate what you are trying to do, try this:

<?php
function playerProfile(&$arr) //Here's the magic, add an & before the argument name
{
  $arr["variablename"] = "has a value"; //Changes made within the function will affect the array outside of the function
}

$arr = array(); //Don't give the variable a name reserved by PHP
playerProfile($arr); //There nothing you need to do here to pass by reference 
print_r($arr); //Show the change by printing the array
?>
FlashCreations 20 Posting Whiz

Well why not look into the $_GET and $_POST superglobals of PHP. They will allow you to display and work with form data submitted by a user. Try: W3Schools PHP Forms

If you could elaborate on what you want each of the textfields on confirmreserve.php to contain, I can give you an example.

FlashCreations 20 Posting Whiz

if you are worried about bots or some automated system you put a graphics verification in your page. You use "PHP Contact form with image verification"

When you build a form in your web page, you are susceptible to being spamed by automated systems. In order to make sure that the one who completes the form is human, you can use the system with image verification. (from hotscripts)

And how is this at all relevant? Yes, spam bots may try a DOS attack with several queries a second, and this would require a CAPTCHA, but this thread has nothing to do with a contact form.

FlashCreations 20 Posting Whiz

Oh ok! I get it now...well it appears that the version of PHP your using doesn't have ZIP compression enabled. Your going to need to head into your PHP.ini file and check some settings. You can find it in:

C:\wamp\bin\php\php5.3.0\php.ini
(Install folder) (PHP Version)

Once you open that file, search for this line (or something similar to it):

;extension=php_zip.dll

Replace that line with this:

extension=php_zip.dll

That should enable ZIP compression and decompression in PHP and allow PhpMyAdmin to restore your backup DB.

FlashCreations 20 Posting Whiz

Oh Ok...I understand the problem now! Sorry about that. Well I'm glad you solved your problem, all I ask is that you mark this thread as solved so others don't attempt to solve this already fixed problem.
Thanks!

FlashCreations 20 Posting Whiz

Could you please use clear English? I'm not quite sure what you are asking. Make sure you elaborate on the details of your problem including how to reproduce the problem and what exactly happens.

FlashCreations 20 Posting Whiz

To display the username and display name all you need to do is use get_currentuserinfo() :

<?php
//Declare a global to hold the user's username and display name
global $user_login, $display_name;

//Get the user's information
get_currentuserinfo();

//Then display a welcome message
echo "<strong>Welcome back {$display_name} ({$user_login})!</strong>"
?>

Use the current_user_can('level_x'); function to determine the rank of the user. Here's the different level codes:

Administrator - Level 10 (level_10)
Editor - Level 7 (level_7)
Author - Level 4 (level_4)
Contributor - Level 2 (level_2)
Subscriber - Level 0 (level_0)

Knowing this you can show certain text to authors or above only:

<?php if(current_user_can("level_4")): ?>
   <b>Hey Authors, Editors, and Admins!</b>
<?php endif; ?>
FlashCreations 20 Posting Whiz

Well the first problem is you didn't specify a type of input. This isn't the main problem, but causes the document to be an invalid (X)HTML page. I will look more into your problem and see what the real cause of it is...

EDIT:
I notice that in the first snippet, you have qty containing an array, but in your PHP you are using it as a single variable.

The other thing you should note is making an input an array only works when there is multiple inputs of the same type with that exact name.

FlashCreations 20 Posting Whiz

Well, I'm assuming your a beginner to PHP. This would be like asking a small child to launch a rocket to the moon and back. Can it be done...yes, but I think you should try immersing yourself in PHP and learning about the language before your try something ambitious. Never-the-less, here's some ideas:

  1. You will need to create an engine that spiders the web and indexes words for each website. (This shouldn't be done in PHP, since there is a max execution time on most free accounts of 30 seconds. How about trying C or Java)
  2. You will need a PHP script to search through your keyword database for a query and display relevant results.

It is way more complicated than this. First off, there is enough information on the internet to surpass millions of large hard drives. It is just not feasible to spider the web unless you have access to large server banks. Then you will also need to evaluate each website for reliability and relevance, an algorithm that Google, Yahoo, and others have been perfecting for many years now. In short, this is no small project. Might I suggest trying to create a small version that just spiders your personal website. It's the same principle, just on a much smaller (and more manageable) scale. Good Luck!

FlashCreations 20 Posting Whiz

Yeah, I was guessing that something like this didn't work. It's a shame too, because multi-language highlighting in a single code block would be pretty cool.

You know I'll try it:

<html>
<head>
<title>CODE Tag Test</title>
</head>
<body>
<?php
//Comment
echo "String!";
mysql_connect("localhost", "user", "pass") or die(mysql_error());
$b = 6;
$a  = $b++;
class dummy { private $value; }
include("text.php");
?>
</body>
</html>

EDIT: Well it looks like it doesn't work. Oh well! Thanks anyways.

FlashCreations 20 Posting Whiz

The first step would be to get the server side of your request programmed. This will mean you would need knowledge in a language such as PHP, ASP, or JSP. If you already have a backend coded, the next step would be the javascript frontend. For this you will need to catch a form submit and send the data via AJAX instead. You can do this with the onsubmit="" attribute of the <form> .

<form action="comment_post.php" method="post" onsubmit="postComment();">
...
</form>
function postComment()
{
  //Validate the form here
  if(validate())
  {
    //Initiate AJAX
    //Get Vars
    //Attach POST and GET Vars
    //Send Request
    //Update on Reply
  }
  return(false);
}

For this you will need some basic understanding of AJAX. I would suggest AJAX on W3Schools. If you're using PHP, also look at PHP/AJAX on W3Schools.

FlashCreations 20 Posting Whiz

Hi Everyone,
I was just coding a small mockup example from someone on the PHP forum and it just occurred to be that DaniWeb's code tags will only highlight in one language (To my knowledge). This is somewhat annoying since most PHP files can contain HTML and only one can be highlighted. Are there any plans to include the option of multiple language CODE tags or is there already a way to do this?
Thanks,
PMC

FlashCreations 20 Posting Whiz

How about including a PHP file which contains the javascript you wish to be able to access the PHP variables. Then in this included file pass the PHP variables to the script. You can not alter a PHP variable from javascript, but this should suffice. Here's an example:

index.php:

<?
//Set some vars that JS can access
$something = "Hello Javascript!";
$daniweb = "awesome";
$scriptby = "PhpMyCoder";
?>
<html>
<head>
<title>PHP Vars in JS Example</title>
<?php require_once("js.php"); ?>
</head>
<body onload="phpVars();">
</body>
</html>

js.php:

<?php
//Add the javascript vars with the script tag
echo "<script type='text/javascript'>\n" +
        "something = " . $something . ";\n" +
        "daniweb = " . $daniweb . ";\n" +
        "scriptby = " . $scriptby . ";\n" +
        "</script>\n";

//Now either attach an external JS file
// echo "<script type='text/javascript' src='external.js'></script>";
//Or add the Javascript to this file
echo "<script type='text/javascript'>\n" +
        " function phpVars() { alert(something + ' Daniweb is ' + daniweb + '! Script coded by ' + scriptby + '.') }\n" +
       "</script>\n";
?>