FlashCreations 20 Posting Whiz

Well you'll need to find a way to get the short code SMS to communicate with your PHP script. I have no idea how to do this. When it comes to the PHP, it seems easy enough.

switch(strtolower($_GET['command'])) {
    case 'pizza':
        $r = mysql_query("SELECT * FROM pizza ORDER BY popularity DESC LIMIT 5");
        if(mysql_num_rows($r) != 0) {
            while($arr = mysql_fetch_array($r)) { echo $arr['name']; }
        } else { echo "No pizzas found. Sry!"; }
        break;
}

This would work assuming you have already connected to your database and your table structure is similar to my little demo. You would also need to have texts to the number routed to your script, assuming the command parameter contains the contents of the text and the stdout is returned to the sender of the text message.

FlashCreations 20 Posting Whiz

For the first URL, you can retrieve the var parameter by exploding the string returned by parse_url. You can also use a Regex if you want.

$param = explode('&', parse_url($url, PHP_URL_QUERY));
if(is_int($param['var'])) {
//$param['var'] for the var parameter
}

//OR

preg_match("/var=([0-9]+)/i", $url, $matches);
//$matches[1][0] for the var parameter

EDIT: As a rule, everything is usually faster than a Regex...Keep that in mind :)

The URL from the CSS command can be found with a simple Regex:

preg_match('/url\("([^\/]+\/)*([a-z0-9-_\%\.]+)"\)/i', $css, $matches);
//$matches[2][0] contains the file name from the URL

If either Regexes need to be refined or you need clarification, just write back!
Cheers,
PhpMyCoder

FlashCreations 20 Posting Whiz

The basics of a user system involves three main parts.

  1. Registration - The user provides details such as desired username, password, and email. Some verification should be done to make sure that the user names and emails are unique to that user. If they are, insert this information into a users table of your database. This table should include a unique ID, username, password (encrypted with the md5() function, a one way hash), email, and session id. As an extra layer of security and to prevent spam you can filter for valid emails and send email verifications to ensure users give you valid addresses.
  2. Authentication - The user provides login details such as username and password or email and password. The username/email should be checked against the database. If it does exist, run the given password through an md5 hash to verify that the passwords match. From here, store the unique user id and a random session id as cookies on the users browser. To validate login, check to see if the unique id stored in the cookie matches a record in the table along with the session id. You can regenerate the sessionid for maximum security.
  3. Management - Something as simple as PhpMyAdmin can be used for user administration. You can update, delete, and add users with little to no extra work. If you prefer a more targeted admin panel, you can add advanced options that includes all of the above and other features such as banning by …
FlashCreations 20 Posting Whiz

This is not true at all!
The following will work assuming that you are connected to a mysql database with a table named foo:

mysql_query("SelECt FRom foo");

Your problem most likely is that your query doesn't return any results. In that case, mysql_fetch_array() will not work because there are no rows to return.
If this is the issue, make sure to use mysql_num_rows() to verify there are results before getting them.

<?php
include "mysql.php";
$res=mysql_query("select * from pagelay");
if(mysql_num_rows($res) != 0) {
$mygrow = mysql_fetch_array($res);
}
?>

This might not be the case. If you have all errors suppressed, there might be a MySQL connection, database selection, or query error. Be sure error_reporting() is set to E_ALL to make sure you can see these errors. Also you should add or die(mysql_error(); to any query function to make sure that the query doesn't raise any errors.

Also please make sure you question hasn't already been answered elsewhere. Especially if your answer is in a read me thread at the top of the PHP forum.
http://www.daniweb.com/forums/thread191031.html

FlashCreations 20 Posting Whiz

Ah, W3Schools is such a great resource isn't it! I'm glad you check it for help.

Regarding tpl files, Ancyent is correct. They are mostly associated with Smarty. However, if I may throw in a suggestion: Don't bother with Smarty unless you really don't want to learn PHP. If you are interested in diving into programming, learn by example. Search around for scripts that others have made and try to mimic their results without coping-and-pasting. Once you feel comfortable with the basics, you can move on to OOP, which may be confusing to some, but pays off in the long run. With all of your newfound knowledge, you'll be able to use a MVC framework such as CodeIgniter or CakePHP. They provide a power way to organize and control your content and application, including views (the equivalent of templates).
MVC's and frameworks are becoming more popular with developers and are a great time-saver and organizer when you become familiar with PHP.

Good Luck!
PhpMyCoder

FlashCreations 20 Posting Whiz

Assuming that the downloads are routed through a PHP script, it should be simple enough to record user download data. The devil is in the database and how you store this information. Here's my recommendation:
You only need one table to store download information along with hit counts. I recommend three columns for tracking download numbers: A total downloads column, a weekly downloads column, and a monthly downloads column. When a user requests a file download, simply increment all three fields for that file by one.
You stats are simply a MySQL query away:

//Get total downloads
mysql_query("SELECT downloads FROM files WHERE id='".$id."'");

//Get weekly downloads
mysql_query("SELECT weeklyDownloads FROM files WHERE id='".$id."'");

//Get monthly downloads
mysql_query("SELECT monthlyDownloads FROM files WHERE id='".$id."'");

*Depending on what you name your columns

You will need CRON jobs to run once every Sunday and once at the end of every month. The weekly script should contain something along the lines of:

//Set all the files to a 0 weekly download count for the new week
mysql_query("UPDATE files SET weeklyDownloads=0");

As you can assume the monthly CRON will look something like this:

//Set all the files to a 0 monthly download count for the new month
mysql_query("UPDATE files SET monthlyDownloads=0");

**These all assume that you have already connected to MySQL and a DB, and perform the necessary mysql_fetch_array() 's after if the query requires it.

Cheers,
PhpMyCoder

phplover commented: Fantastic post made in helping me :) +1
FlashCreations 20 Posting Whiz

*Cringe* Please, please, please mysql__real_escape_string() any user given value before using it in a query. Without doing so you are putting yourself at high risk of SQL Injection!

Now on to your problem. I would check the query (it seems you've outputted it out as a comment) on the second line and verify that there isn't anything wrong with it.
It would be a tremendous help if you could provide us with the value of $_GET['id_proiect'] or the final query that produces this error.

FlashCreations 20 Posting Whiz

Instead of relying on a guest's cookies to determine a guest's name (whether it be Guest1 or Guest34582), I would turn to PHP when the guest enters the room.
Each time a guest navigates to a room I would add them to your users table, assign them a unique ID and session key for authentication, making sure to flag their account as a guest not a registered user. The flagging can be done with a MySQL ENUM or a simple short int (for example: 0 for guest, 1 for user). To determine a guest's username, simply query MySQL for the last user flagged as a guest. If there is one, the guest's username should be set to "Guest1". Otherwise, all you need is a simple str_replace() to isolate the last guest number. From there, you can then easily calculate the new guest's name and add it to the database.
Along with this, you might want to check for a guest user's inactivity. Have a Cron job purge all the guest accounts that haven't posted a message in a set amount of time.
Let me know if you would like some sample PHP for any of this.
Best of Luck,
PhpMyCoder

FlashCreations 20 Posting Whiz

Yeah, the MVC usually doesn't vary between frameworks; you only have to get used to the little quirks (such as CI Models) and extras. If your ambitious enough, you could design your own framework (something I've been working on as a side project), but thats a lot of work compared to downloading & learning CI!

FlashCreations 20 Posting Whiz

Thanks Steve!
It is a great framework, though I am embarrassed to say that I haven't worked with it that much either. :D
Someone on the PHP form has to be a CI guru. If there isn't and vizz has a question about CI, I guess we have some reading to do...
-PhpMyCoder

EDIT: It's been so long since I've been on Daniweb, I almost forgot how strange the smilies looked!

FlashCreations 20 Posting Whiz

How stupid of me! In a effort to save resources I closed the cURL connection before I checked for errors. The code should read:

$result = @curl_exec($c);
    if(curl_error($c) !== '') {
        curl_close($c);
        return(false);
    }
    curl_close($c);
    return($result);
}

It also might help at the bottom, to remove one of the demos. Otherwise, you'll get a double result.
Sorry for the confusion!

FlashCreations 20 Posting Whiz

Is this what you're doing:
testfile.php:

<?php
//Define either your function or my function here

echo simpleCURL('url.com/curl.php', 'id=1');
?>

curl.php:

<?php
echo $_REQUEST['id'];
?>

It would really help if I could see the exact code you are using in both the curl.php files and your test file! If you could provide the source for both of these, the problem could be fixed quicker!

Best,
PhpMyCoder

FlashCreations 20 Posting Whiz

My mistake, I forgot a $ before the value variable in the definition of curl_setopt_array() . Here's the redo:

<?php
function simpleCURL($url, $get = NULL, $post = NULL, $opts = array()) {
    //Init cURL, returning false with any errors
    if(!($c = @curl_init())) {
        return(false);
    }
    
    //Append any get vars
    if(is_array($get)) {
        $get = array2params($get);
    }
    if(isset($get)) {
        $url .= '?'.$get;
    }

    //Set the cURL URL
    curl_setopt($c, CURLOPT_URL, $url);

    //Set any post vars
    if(is_array($post)) {
        $post = array2params($post); //Turn into a string to prevent multipart/form-data
    }
    if(isset($post)) {
        curl_setopt($c, CURLOPT_POST, true);
        culr_setopt($c, CURLOPT_POSTFIELDS, $post);
    }

    //Set required opts
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_HEADER, false);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

    //Set additional opts
    curl_setopt_array($c, $opts);

    //Execute cURL query, close connection, and return
    $result = @curl_exec($c);
    curl_close($c);
    if(curl_error($c) !== '') {
        return(false);
    }
    return($result);
}

function array2params($array) {
    $params = array();
    foreach($array as $param => $value) {
         $params[] = $param.'='.urlencode($value);
    }
    return(implode('&', $params));
}

if(!function_exists('curl_setopt_array')) {
    function curl_setopt_array(&$c, $options) {
        foreach($options as $option => $value) {
            if(!curl_setopt($c, $option, $value)) {
                return(false);
            }
        }
        return(true);
    }
}


//It can be called like so:
echo simpleCURL('http://www.mysite.com/curl.php', 'id=1');
//Or...
echo simpleCURL('http://www.mysite.com/curl.php', array('id' => 1));
?>

As for line #52, I ran this code on my own server and it complied and ran fine. Are you sure that Dreamweaver isn't just making a mistake? What error is it giving you?
Also, since we've digressed, I forgot to ask: Did I answer your curl.php question?

FlashCreations 20 Posting Whiz

Got it! I mentioned it above, but I've included it again in this post if you need it.

curl.php:

<?php
echo 'Hello cURL! ID: '.$_POST['id'];
?>

Might I suggest a more robust cURL function:

function simpleCURL($url, $get = NULL, $post = NULL, $opts = array()) {
    //Init cURL, returning false with any errors
    if(!($c = @curl_init())) {
        return(false);
    }
    
    //Append any get vars
    if(is_array($get)) {
        $get = array2params($get);
    }
    if(isset($get)) {
        $url .= '?'.$get;
    }

    //Set the cURL URL
    curl_setopt($c, CURLOPT_URL, $url);

    //Set any post vars
    if(is_array($post)) {
        $post = array2params($post); //Turn into a string to prevent multipart/form-data
    }
    if(isset($post)) {
        curl_setopt($c, CURLOPT_POST, true);
        culr_setopt($c, CURLOPT_POSTFIELDS, $post);
    }

    //Set required opts
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_HEADER, false);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

    //Set additional opts
    curl_setopt_array($c, $opts);

    //Execute cURL query, close connection, and return
    $result = @curl_exec($c);
    curl_close($c);
    if(curl_error($c) !== '') {
        return(false);
    }
    return($result);
}

function array2params($array) {
    $params = array();
    foreach($array as $param => $value) {
         $params[] = $param.'='.urlencode($value);
    }
    return(implode('&', $params));
}

if(!function_exists('curl_setopt_array')) {
    function curl_setopt_array(&$c, $options) {
        foreach($options as $option => value) {
            if(!curl_setopt($c, $option, $value)) {
                return(false);
            }
        }
        return(true);
    }
}


//It can be called like so:
simpleCURL('http://www.mysite.com/curl.php', 'id=1');
//Or...
simpleCURL('http://www.mysite.com/curl.php', array('id' => 1));

Does this answer your question?

FlashCreations 20 Posting Whiz

If I may add my ten cents, I believe that CodeIgniter.com has a great 20 minute tutorial on creating a basic blog. Not sure if you consider CI "a feature", but its a great way to create applications without having to worry about internals. This way you can learn the structure and required parts before you have to dive in and start from scratch. You can use some of the models ardav described and implement them in CI as a starting point. After you understand how everything fits together, then move on to starting from scratch.
If you are one of those dive-in-and-try-it people, then by all means, disregard the above and take a shot at it. Post any questions you may have here or in a new appropriate thread.
--
For the purists out there, I'm not endorsing CI as a start to PHP. I believe it's much better to learn and be comfortable with PHP basics & OOP before using a framework. In this case, I think a framework could help illustrate relationships and basic functionality.

All the Best,
PhpMyCoder

FlashCreations 20 Posting Whiz

Line 17 in my code is the call to your function. In your code, that line is blank! :P

my page names curl.php is simple a get variable that echo's the id parameter, all within the same domain.

Umm, what? Your curl.php page takes a GET variable that echoes the id? Does it already, or is that what you want. If you haven't created curl.php yet, it seems simple enough!

curl.php

<?php
echo $_GET['id']; 
echo $_POST['id']; //You use post in cURL, so I included it for good measure
?>

You know: If curl.php is on the same domain, you can just include or require the file. It will have the same effect.

<?php
require('curl.php?id=1');
?>

Best,
PhpMyCoder

FlashCreations 20 Posting Whiz

EDIT: No need to be rude LRNPHP. We're trying the best we can to help. If you didn't think you'd get help with your question, why did you post in the first place? All of us are volunteers here. Please respect that!

If you want a new window, I suggest looking into JavaScript's window.open(). It's ugly, outdated, and sometimes doesn't play nice with pop-up blockers, but it's what you asked for. Gunnarflex has a better solution for this as modal windows are much more elegant than pop-ups. You might also benefit from a neat trick such as replacing the original search box with several ones prefixed with refined options.
If this is not the solution to your problem, can you please explain your question. Exactly what are you looking for? I think we satisfied the need of the pop-up/modal window you asked for. Would you like help with the actual advanced search page?
We're not mind readers here! ;)
Help us help you.

Best,
PhpMyCoder

FlashCreations 20 Posting Whiz

Forgive me for being obvious:
If you're not calling the function, that might be the problem.

<?php
function request($url, $postdata) {
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($curl, CURLOPT_POST, 1);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
   curl_setopt($curl, CURLOPT_HEADER, 0);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   $result = curl_exec($curl);
   curl_close($curl);
   return($result); 
}

$url = "mydomain.com/curl.php?";
$postdata = "id=1";
echo request($url, $postdata);
?>

But I'm assuming you are calling the function since most of your 400+ posts are in this forum. If you are, my guess is that the website you are querying with cURL has blocked your server from requesting its pages. Google does this when bots & scripts overuse its search page. Other popular sites might employ similar techniques.

FlashCreations 20 Posting Whiz

My first instinct would be to ask whether you want the $key variable to contain the key of the array or the value. If you want the former your foreach will need to look like this:

<?php
//Php doesn't implicitly assume you want the key if you call the variable key
foreach($value as $key => $dummy) {
...
?>

If this is not the case, why not try some simple debugging? It can often uncover small issues & typos that you overlook with a quick glance. How about something like this first:

foreach($value as $key) {
echo 'Key: '.$key."<br>\n";
...
}

Make sure that it outputs:

Key: testa
Key: testb

If it doesn't then there's your problem! Otherwise, let's keep going. The next thing I would try is echoing out each of the queries and trying them in PhpMyAdmin. Just looking at the query sometimes can reveal the problem.
If you don't find the problem here, try reformatting your code; it might not help, but its worth a try:

foreach($value as $key) {
    $r = mysql_query("SELECT * FROM Stacks WHERE keywords LIKE '%".$key."%'");
    echo 'Key "'.$key.'": '.$upnum."<br>\n";
}

Let us know how it goes!

EDIT: I forgot to ask: Do you have PHP set to report all errors? Trying the query in PhpMyAdmin will show any errors with the MySQL, but you can also try enabling errors in PHP (so you can see if MySQL triggers any).

//We'll ignore E_STRICT for now :)
error_reporting(E_ALL);
FlashCreations 20 Posting Whiz

Something like this will have to be achieved with a combination of AJAX and PHP. The frontend (JavaScript) will call your backend (PHP) with a request when a new name is selected from the list. At its most basic form, that would like something like this:

<?php
//If a name was requested
if(isset($_GET['name'])) {
    //Connect to MySQL and select DB
    @mysql_connect($dbHost, $dbUser, $dbPass) or die('{result: -1');
    @mysql_select_db($db) or die('{result: -1}');
    //Get details on person via MySQL query
    $result = @mysql_query('SELECT data FROM person WHERE Name="'.mysql_real_escape_string($_GET['name']).'" LIMIT 1');

    //Return an error if person wasn't found
    if(mysql_num_rows($result) == 0) {
        die('{result: 0}');
    }
    //Otherwise, return user details
    $person = mysql_fetch_array($result);
    die('{"result": 1, "data": "'.$person['data'].'"}');
}
?>
<!doctype html>
<html>
<head>
<title>Person Information</title>
<script>
document.onload = function() {
    var x, details = document.getElementById('details');
    document.getElementById('pSelect').onchange = function() {
        if(window.XMLHttpRequest) {
            x = new XMLHttpRequest();
        } else {
            x = new ActiveXObject("Microsoft.XMLHTTP");
        }
        x.open("GET", "<?=$_SERVER['PHP_SELF']?>?name="+escape(this.value), true);
        x.onreadystatechange = function() {
            if(this.readyState == 4) {
                response = eval('('+this.responseText+')');
                if(response.result == -1) {
                    details.innerHTML = '<em>There was an error with your request.</em>';
                } else if(response.result == 0) {
                    details.innerHTML = '<em>Person was not found</em>';
                } else {
                    details.innerHTML = response.data;
                }
            }
        };
        x.send();
    };
};
</script>
</head>
<body>
<p>Person: <select name="person" id="pSelect"><option name="Bob">Bob Doe</option></select></p>

<div id="details"></div>
</body>
</html>

I've combined the backend and frontend into one file, but you can just as easily separate them if you wish. The JavaScript can also be sped up with the help of a library such as JQuery. Of course, …

FlashCreations 20 Posting Whiz

Try this:
Include the normal navigation as if every browser required it but enclose it in a tag with a special class (I would use something like noie6). Then include the IE nav in between the IE conditional tags and include the styling in the head as you already have done.

<div class="noie6">
<?php @include("normal-nav.php"); ?>
</div>

<!--[if IE 6]><?php @include("ie6-nav.php"); ?>
<![endif]-->

Now all you have to do is include this line of CSS in your IE6 stylesheet (The one included in the conditional tag):

div.noie6 { display: none; }

This way on all IE6 browsers the normal navigation will be hidden. Does this solve your problem?

FlashCreations 20 Posting Whiz

Maybe try nl2br() on the code:

<?php
include("contentdb.php");
include("data.php");
 
$display = mysql_query("SELECT code FROM $table ORDER BY id", $db);
if (!$submit)
{
       echo "Code:"
        while ($row = mysql_fetch_array($display)) {
        echo "<br><b>".nl2br($row['code'])."</b><br>";
        }
}
?>
FlashCreations 20 Posting Whiz

I haven't had very much experience with FPDF, but is this what you are looking for: http://www.fpdf.org/en/tutorial/tuto4.htm

FlashCreations 20 Posting Whiz

Ahh! Use code tags please! You problem is the first couple characters: ''1. The single-quote starts a string and ends a string, then you have a number after it. Did you mean: '1' or '', 1? Both of these are valid SQL, but to be sure, can we see the query that is causing the problem.
Edit
My bad, I was oblivious to the fact that the query was there (I should have noticed it though, because I mentioned the code tags.) I'm looking into your problem now.
---
The only thing I could think of its that one of the variables you are inserting contains ''1, which would produce an SQL error. Did you mysql_real_escape_string() all strings you are inserting?

FlashCreations 20 Posting Whiz

Actually funny enough, he does have some sort of security in place. The tag <iostream> was removed because of it's containing < and > (which generally signifies an HTML tag). What needs to be done though, is not stripslashes or addslahses. It's mysql_real_escape string():

<?php
include("contentdb.php"); //Connect to MySQL
include("data.php"); //Declares Variables
//Perform query
if(mysql_query("INSERT INTO $table (code) VALUES ('".mysql_real_escape_string($code)."')")) echo "<br><br>Your Code  was Added to the Quiz.<br><br>";
?>
<a href="editquizlist.php">Return to the Code List</a>

To really diagnose the problem, we would need to see the data.php file. Can you post it?

FlashCreations 20 Posting Whiz

Well this is directly from the FPDF site. It's about columns: http://www.fpdf.org/en/tutorial/tuto4.htm
You want something aligned? How? Centered? (Left, which should be the default) Right? Can you detail exactly what you are looking for. Maybe provide a graphic to show what you're looking for.

FlashCreations 20 Posting Whiz

There is no shorter way to ensure that several fields aren't blank in SQL, but you could write a PHP function to make it slightly easier:

function selectWhereNotNull($fields, $table, $where) {
    //Init Query
    $query = "SELECT ";
    //Append fields to Select
    if(is_array($fields)) {
        $query .= implode(", ", $fields);
    } else {
        $query .= $fields;
    }
    //Append table to select data from
    $query .= " FROM {$table} WHERE ";
    //Append IS NOT NULL for each statement
    $statements = array();
    foreach($where as $field) {
        $statements[] = "{$field} IS NOT NULL";
    }
    $query .= implode(" AND ", $statements);
    return(mysql_query($query));
}

Usage:

$query = selectWhereNotNull(array("fields", "to", "select"), "table", array("fields", "that", "are", "not", "null"));
FlashCreations 20 Posting Whiz

What is exiration? Did you change something in the code? As far as I remember, there were no spelling mistakes in the one I sent to you (I always double check!).

FlashCreations 20 Posting Whiz

Well then try this. And yes it will still work. You just have to do is change the way the data is added to the class. Check the readme file for more (It should be similar though, what does your demo query return?).

Try this with the old query:

<?php
/***********************************
 * PhpMyCoder Paginator            *
 * Created By PhpMyCoder           *
 * 2010 PhpMyCoder                 *
 * ------------------------------- *
 * You may use this code as long   *
 * as this notice stays intact and *
 * the proper credit is given to   *
 * the author.                     *
 ***********************************/
 
class pmcPagination {
	private $pageVar = "page";     //$_GET variable to get page # from
	private $items = array();      //Array of items to paginate
	private $resultsPerPage = 10;  //Results to be displayed per page
	private $paginated = false;    //Has the paginate() function been called?
	
	public function __construct($resultsPerPage="", $pageVar=0, $items=NULL)
	{
		//Set pageVar if arg is valid
		if($this->isValidPageVar($pageVar)) $this->pageVar = $pageVar;
		
		//Set resultsPerPage if arg is valid
		if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage;
		
		//Add items passed
		$this->add($items);
	}
	
	public function add($items)
	{
		//If the item is null, exit function
		if(is_null($items)) return;
				   
		//If arg is not an array, make it one
		if(!is_array($items)) $items = array($items);
		
		//Cycle through items passed
		foreach($items as $item)
		{
			//Add them to the $items array if they are valid
			if($item instanceof paginationData) $this->items[] = $item;	
		}
	}
	
 	public function paginate($resultsPerPage="", $pageVar=0, $items=NULL)
 	{
 		//Prevent set function form changing values
 		$this->paginated = true;
 		
 		//Set pageVar if arg is valid
 		if($this->isvalidPageVar($pageVar)) $this->pageVar = $pageVar;
 		//Set …
FlashCreations 20 Posting Whiz

It needs to be this:

<?php
/***********************************
 * PhpMyCoder Paginator            *
 * Created By PhpMyCoder           *
 * 2010 PhpMyCoder                 *
 * ------------------------------- *
 * You may use this code as long   *
 * as this notice stays intact and *
 * the proper credit is given to   *
 * the author.                     *
 ***********************************/
 
class pmcPagination {
	private $pageVar = "page";     //$_GET variable to get page # from
	private $items = array();      //Array of items to paginate
	private $resultsPerPage = 10;  //Results to be displayed per page
	private $paginated = false;    //Has the paginate() function been called?
	
	public function __construct($resultsPerPage="", $pageVar=0, $items=NULL)
	{
		//Set pageVar if arg is valid
		if($this->isValidPageVar($pageVar)) $this->pageVar = $pageVar;
		
		//Set resultsPerPage if arg is valid
		if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage;
		
		//Add items passed
		$this->add($items);
	}
	
	public function add($items)
	{
		//If the item is null, exit function
		if(is_null($items)) return;
				   
		//If arg is not an array, make it one
		if(!is_array($items)) $items = array($items);
		
		//Cycle through items passed
		foreach($items as $item)
		{
			//Add them to the $items array if they are valid
			if($item instanceof paginationData) $this->items[] = $item;	
		}
	}
	
 	public function paginate($resultsPerPage="", $pageVar=0, $items=NULL)
 	{
		print_r($this->items);
		/*
 		//Prevent set function form changing values
 		$this->paginated = true;
 		
 		//Set pageVar if arg is valid
 		if($this->isvalidPageVar($pageVar)) $this->pageVar = $pageVar;
 		//Set parVar to previous value
 		else $pageVar = $this->pageVar;
 		
 		//Set resultsPerPage if arg is valid
 		if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage;
 		//Set resultsPerPage to previous value
 		else $resultsPerPage = $this->resultsPerPage;
 		
 		//Add any extra items
 		$this->add($items);
 		
 		//Get Page #, Staring Result #, and Ending Result #
 		if(isset($_GET[$pageVar]) …
FlashCreations 20 Posting Whiz

Impossible, you should have at least see:

Array
(
)

Something must be wrong. Can you post the pmcPagination.php file so I can make sure that you put the print_r in the right place?

FlashCreations 20 Posting Whiz

Just the code inside this function:

public function paginate($resultsPerPage="", $pageVar=0, $items=NULL)
	{
		//Prevent set function form changing values
		$this->paginated = true;
 
		//Set pageVar if arg is valid
		if($this->isvalidPageVar($pageVar)) $this->pageVar = $pageVar;
		//Set parVar to previous value
		else $pageVar = $this->pageVar;
 
		//Set resultsPerPage if arg is valid
		if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage;
		//Set resultsPerPage to previous value
		else $resultsPerPage = $this->resultsPerPage;
 
		//Add any extra items
		$this->add($items);
 
		//Get Page #, Staring Result #, and Ending Result #
		if(isset($_GET[$pageVar]) && $_GET[$pageVar] > 0) $page = $_GET[$pageVar];
		else $page = 1;
		$result = ($page - 1) * $resultsPerPage + 1;
		$max = $result + $resultsPerPage;
		if($max >= count($this->items)) $max = count($this->items);
 
		//Are there results?
		if($result<count($this->items))
		{
			//Cycle through results on current page
			for(;$result<$max;$result++)
		 	{
				//Show the result 
				$this->items[$result]->display();
		 	}
		}
		//Display a "no results" message
		else echo "<strong>No Results found on this page.</strong>";
	}

As I said, comment it out, and add:

print_r($this->items);
FlashCreations 20 Posting Whiz

In the paginate function (comment everything inside of that functions out first) in pmcPagination.php.

FlashCreations 20 Posting Whiz

Hmm, well if that works, I guess you could use it as a viable workaround, but I still wonder why some of the records don't display. If you would like to investigate this further, try commenting out the paginate function in the pmcPagination class and replace it with:

print_r($this->items);

Then, check if the missing records are outputted (part of the array).

FlashCreations 20 Posting Whiz

Did you try the query that I suggested? Are the missing programs appearing in the results of the query?

FlashCreations 20 Posting Whiz

So does the date work now? If so, that's great! Regarding the events: Did you check and see if they are in the database? Also, did you check their expiration date (I remember something about the expiration date being filtered in MySQL). To test this, you can perform the query you use to get the programs and attempt to find the missing ones. If they aren't their, the problem is with you query (I can help with this). If they are there, it's a slight bug in my code (Which I can also fix!).

FlashCreations 20 Posting Whiz

This all appears ok. One last thing I want to try: Can you post all of your code. (I know I wrote it, but maybe something was accidentally changed when I sent you the files)

FlashCreations 20 Posting Whiz

Ok so can you try this:

mysql_connect("HOST", "USER", "PASSWORD");
mysql_select_db("housemdepisodes");
$result = mysql_query("SELECT airdate FROM epdata");
$count = 0;
while($arr = mysql_fetch_array($result)) 
{
  echo $count.'. '.date("m-d-Y h:i:s A", strtotime($arr['airdate'])).'<br>';
  $count++;
}

Then report back with it's results.

FlashCreations 20 Posting Whiz

Oh no! Well right about now I don't know what to tell you. I've tried the code on my server, and it works fine. I also just ensured that the date formats you gave me from MySQL formats properly into the UNIX Epoch (which it does). Are you running this site on your own dev server (using XAMPP, WAMP, etc), or do you have it setup on a testing server?

whitestream6 commented: Excellent source of help. Much recommended. +2
FlashCreations 20 Posting Whiz

Alight then, try changing line 153 of pmcPagination.php to:

$this->airdate = strtotime($airdate);

That should convert the $airdate to the UNIX Epoch time format, which is what the date function requires.

FlashCreations 20 Posting Whiz

Oh, I was a little unclear. I want some of the actual values from the table. For example, let's say there was an episode called Pilot. I'm looking for the number in the airdate column of the row with the episode name of pilot. Basically, I want to make sure that the airdate field isn't invalid. To simplify things, try running this script (With the proper MySQL login credentials provided):

mysql_connect("HOST", "USER", "PASSWORD");
mysql_select_db("housemdepisodes");
$result = mysql_query("SELECT airdate FROM epdata");
$count = 0;
while($arr = mysql_fetch_array($result)) 
{
  echo $count.'. '.$arr['airdate'].'<br>';
  $count++;
}

After you run this script on your server report back with what the script outputs.

FlashCreations 20 Posting Whiz

Wow! This has been very problematic! Sorry about all of this (It should be much easier than this)! I've, though, tested the code on my personal server again and it works fine for me (I used the time function and subtracted a random interger for random dates). Can you post some of the values of your airdate field in the episodes table? The problem has to be there!

Also, while re-testing, I found a little error in my code:
Line 68 of pmcPagination.php should be

$result = ($page - 1) * $resultsPerPage;

This shouldn't fix the problem, but it should be corrected. :)

FlashCreations 20 Posting Whiz

Please use the code tags in future posts to enclose your code in. :)

You can say that again!

To check for a valid AID, try querying for all records with that id and then counting the number of rows returned:

$result = mysql_query("SELECT AID FROM Employeeinfo WHERE AID='".mysql_real_escape_string($aid)."' LIMIT 1");
if(mysql_num_rows($result)==1)
  //Valid AID
else
  //Invalid AID

The problem regarding the empty textboxes has to do with the fact that their respective values can't be found in POST (unless you passed them to the page through a POST Form). You need to query the Database for their values and insert them instead.

FlashCreations 20 Posting Whiz

The problem is with your MySQL. Try quoting the values you are inserting. Also, on a side note, instead of using session you could use hidden inputs to pass the required values to form_process.php. Though it won't make much of a difference, substituting another technique in place of session saves you some (Very little, except on servers that serve millions of users) space since values are stored on the server.
One other thing: Why are you passing the value of a terms and conditions box to MySQL? It seems unnecessary since if the user doesn't agree to the TOS, then they won't be added, but again, your choice.

EDIT:
While I think about it: It looks like you are handling credit card numbers in your script. If I'm not mistaken, it is illegal in most countries to transmit a credit card number over HTTP. Are you using HTTPS?

FlashCreations 20 Posting Whiz

Yeah, you need the TIMESTAMP format because it stores the time as a large int containing the time in seconds since the Unix Epoch. This is what the date() function accepts (You can convert, but it would just be easier to change your MySQL DB row type to TIMESTAMP).

FlashCreations 20 Posting Whiz

Oh ok! Yeah that's your problem! Try using TIMESTAMP instead.

FlashCreations 20 Posting Whiz

Alright then, that would be the problem. ID is not id, so lets fix that:

index2.php (Parts)

<?php $result = mysql_query("SELECT id, book_name FROM iin_books"); ?>
...
<option value="<?=$nt['ID']?>"><?=$nt['book_name']?></option>

getDescription.php

<?php 
require_once("includes/connection.php");
require_once("includes/functions.php");

function return_description($id) 
{
	$result = mysql_query("SELECT book_description from iin_books WHERE ID= '".mysql_real_escape_string($title)."'");
	if(mysql_num_rows($result) != 0) 
	{
		$row = mysql_fetch_row($result);
		//Replace book description with the name of the description field in your MySQL DB
		return($row['book_description']);
	}
	else return("Book not found!");
}

if(isset($_GET['title')) echo return_description($_GET['title']);
?>
FlashCreations 20 Posting Whiz

WickidGRAFX wants to fill the textfield with the result of an AJAX call to incldues/getDescription.php. That's why there's no value in the textarea (I guess, though, it could be improved to degrade gracefully without AJAX).

What is the structure of the iin_books table?

FlashCreations 20 Posting Whiz

The problem is that when you populate the SELECT no ids are placed in the value attribute. That means that the problem is here:

<option value="<?=$nt['sub_cat_id']?>"><?=$nt['book_name']?></option>

Based on the MySQL query above this, may I suggest:

<option value="<?=$nt['id']?>"><?=$nt['book_name']?></option>

I did notice a few quotes and semicolons that I left accidentally. It shouldn't be causing this error, but you might want to correct your index2.php script:

<?php
session_start();
// Checks if the user isn't registered in session
if (!isset($_SESSION['user'])) echo header("Location: login.php");
?>
<!doctype html>
<html>
	<head>
<?php
require_once("includes/connection.php");
require_once("includes/functions.php");
include("includes/header.php");
?>
	</head>
    <body>
<?php
include("includes/nav.php"); 
include("includes/upper_content.php"); 
include("includes/getDescription.php"); 
?>
<div id="main_body">
<table width="936" align="center" cellpadding="10">
	<tr>
		<td align="center">
			<p align="center">Enter your addition to one of the books in the drop-down list. There is no length limit.</p>
      		<hr />
      		<table>
            	<tr>
                	<td align="center">
      					<form method="post" action="submit_contribution.php">
        					<fieldset>
          						<legend>Select a Book:</legend><br />
          						<?php $result = mysql_query("SELECT id, book_name FROM iin_books"); ?>
		  						<select name="category" onchange="ajaxGetInfo(this.value)">
		  							<option>Select a book title...</option>
		  							<?php if(mysql_num_rows($result)!=0): ?>
                                    <?php while($nt=mysql_fetch_array($result)): ?>
			  						<option value="<?=$nt['sub_cat_id']?>"><?=$nt['book_name']?></option>
                                    <?php endwhile;
										  endif; ?>
			  					</select>
          						<p>Contribution:<br /> <textarea name="contribution" id="contribution" cols="50" rows="10"></textarea></p>
          						<p style="color:#F00; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:12px;">
            						<input type="checkbox" /> I accept <a href="tou.php" style="color: #09F;">Terms of Use</a> and <a href="privacy.php" style="color:#09F;">Privacy Policy</a>.
								</p>
          						<p><input type="submit" value="   Submit Your Contribution   " /></p>
        					</fieldset>
                        </form>
        			</td>
        			<td valign="top">
      					<p>Book Description</p>
      					<textarea name="info" id="info" cols="20" rows="5" readonly></textarea>
      				</td>
				</tr>
      		</table>
      		<br />
      		<br />
      		<a href="logout.php">Logout</a>
		</td>
	</tr>
</table>
</div>
<?php include("includes/footer.php"); ?>
</body>
</html>
FlashCreations 20 Posting Whiz

I suspect you are still using the same code I gave you some time ago. If so, The problem is with the date function. Maybe you could try echoing (or vardumping) the UNIX timstamp you are feeding to it and check and see if the number is right. You can convert that number at the Online Unix Timestamp Converter.