FlashCreations 20

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:
[code=PHP]
<?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>

Person Information 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", "?name="+escape(this.value), true); x.onreadystatechange = function() { if(this.readyState == 4) { response = eval('('+this.responseText+')'); if(response.result == -1) { details.innerHTML = 'There was an error with your request.'; } else if(response.result == 0) { details.innerHTML = 'Person was not found'; } else { details.innerHTML = response.data; } } }; x.send(); }; };

Person: Bob Doe

[/code]

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. ...

FlashCreations 20

Maybe try nl2br() on the code:
[code=PHP]
<?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 "
".nl2br($row['code'])."
";
}
}
?>
[/code]

FlashCreations 20

Actually funny enough, he does have some sort of security in place. The tag 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():

[code=PHP]
<?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 "

Your Code was Added to the Quiz.

";
?>
Return to the Code List
[/code]

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

FlashCreations 20

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:

[code=PHP]
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));
}
[/code]

[b]Usage:[/b]
[code=PHP]
$query = selectWhereNotNull(array("fields", "to", "select"), "table", array("fields", "that", "are", "not", "null"));
[/code]

FlashCreations 20

[QUOTE=Wraithmanilian;1137095]Please use the code tags in future posts to enclose your code in. :)[/QUOTE]
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:

[code=PHP]
$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
[/code]

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

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.

[b]EDIT:[/b]
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

Inside a complex syntax brackets ([icode]{$var}[/icode]) you can call any function with a return value that can be converted to casted to a string. So using your code that would be:
[code=PHP]
$message .= "XXXX-XXXX-XXXX-{substr($_GET['cc_number'] , -4, 4)}";

//Or this....
$message .= "XXXX-XXXX-XXXX-".substr($_GET['cc_number'] , -4, 4)."";

//Or even this...
$message .= "XXXX-XXXX-XXXX-";
$message .= substr($_GET['cc_number'] , -4, 4);
$message .= "";
[/code]
The first or second ones make most sense to me, so I would chose one of them, but it's totally up to you!

drewpark88 commented: Helped me alot! +1

FlashCreations 20

What you are looking for is file writing/reading operations. For this you use fopen along with the w parameter which tells PHP you want to write to the file (and create it if it doesn't already exist).
[code=PHP]
$name = $_GET['name']; //Or where-ever you get the file name
//Sanatize
$name = str_replace('\', '', $name);
$name = str_replace('/', '', $name);

//Open the file
$f = fopen('safedir/'.$name.'.php' , 'w');
//Write to the file
fwrite($f, "Hello World! Your code or HTML should go here.");
//Close file
fclose($f);

//Next, redirect to the new file
header("Location: safedir/{$name}.php");
[/code]

FlashCreations 20

Then append the search variable to all of the pagination links. If the keyword is what's missing, also append this and add a snippet at the top to get the keyword from the URL like this:
[code=PHP]
if(isset(@$_GET['keyword']) $keyword = $_GET['keyword'];
[/code]

If your code is still throwing notices like this when you allow users to access it, I would suggest turning error reporting off...

[code=PHP]
error_reporting(0); //Turn off all errors
error_reporting(E_ALL ^ E_NOTICE); //Allow fatal errors, but mute notices, this is the default setting for most PHP installations
[/code]

If you do hide errors from users, but still want to be able to see them yourself, you can set up an errorlog file. Suppressing problem functions with @ will also work too as long as you don't have any surprise problems.

FlashCreations 20

No that's perfectly correct, I just had a little trouble understanding you. So with that in mind, the links to other pages should include the search parameter. I don't know where the [icode]$keyword[/icode] variable comes from, but it also should remain constant throughout the pagination.

FlashCreations 20

Without having an internet connection. Wouldn't that defeat the purpose of writing a PHP script. You could use localhost and maybe XAMPP or LAMP, but without an internet connection. Why?
If you insist, you could always try a CSS graph like I had suggested before. It's not as elegant as the Google API and its sure not as easy, but it doesn't need an internet connection (It does need a browser, though!)

FlashCreations 20

[QUOTE=rajabhaskar525;1098791][CODE]i think you arenot pass searching text for every page. you are passing only start veriable only. check once[/CODE][/QUOTE]

What?

FlashCreations 20

It is possible with JavaScript and the Google API or a CSS chart (again updated by JavaScript constantly polling a server page. This server page will echo data to the AJAX request and you can update your table there)

FlashCreations 20

Just a note:
When you find the number of pages, you want to find the ceiling (or highest integer) of the division since 1.5 of a page is actually two.

[code=PHP]
$pages = ceil($item_count / $per_page);
[/code]

Also, does the error message (notice) given you a line number?

FlashCreations 20

Well there's SWF charts that rely on XML files for data. You could make the XML file dynamic with PHP and have the SWF poll the file every fifteen seconds or so. [URL="http://www.maani.us/xml_charts/"]XML/SWF Charts[/URL] would be an option for this.

The other way, would be with Javascript and CSS. Sometime ago I read an article about creating graphs in CSS. I'll look for it and post back when I find it.

[b]EDIT:[/b]
Here's the link: [URL="http://cssglobe.com/post/1272/pure-css-data-chart"]Pure CSS Graphs[/URL]

FlashCreations 20

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

FlashCreations 20

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

[code=php]
if($puzzleNum<7 && $puzzleNum>0) {
mysql_query("SELECT * FROM user_info WHERE id = '".$SESSION['userid']."' AND puzz".$puzzleNum." = '". $dbroomno);
}
[/code]

FlashCreations 20

[QUOTE=daryll1;1092113]
If anyone has any ides this would be amazing as it would save me having to write an if statement for each puzzle.

Daryll[/QUOTE]

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 [icode]$dbroomno[/icode]? What's [icode]Puzz_whatever[/icode]?

FlashCreations 20

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.

[b]EDIT:[/b]
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

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 [URL="http://www.w3schools.com/PHP/php_ajax_intro.asp"]W3SChools AJAX tutorial[/URL]?

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

[code=javascript]
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;
}
[/code]

FlashCreations 20

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

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

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

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:

[LIST=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)
[
]You will need a PHP script to search through your keyword database for a query and display relevant results.
[/LIST]

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

Another suggestion: If you are worried about search engines accessing pages other than the first, you can either set the robots.txt to allow a web spider access to the first page of every article. You might also want to try setting up a simple script that you include on pages other than the first that checks if the referrer is from a search engine and add some Javascript to manually force Google Analytics to track the user.

If you are satisfied with your solution to the problem, I ask that you close the forum and continue to post on the DaniWeb forums!

FlashCreations 20

Well by simple logic, why not assume that one unique view is viewing the first page of an article. If so, why not just count the unique views on the first page of each article.

[b]A note about search engine bots:[/b] Most search engines identify themselves with a special HTTP header. If you can write your own unique view counter (Cookies will work; it's how Google does it!), simply set it to ignore search engine spiders. Googlebot uses the Useragent String "Googlebot", so simply ignore the view counter when the [icode]$_SERVER['HTTP_USER_AGENT'][/icode] is "Googlebot".

[I]Read [URL="http://ditio.net/2008/09/07/detecting-search-engine-bots-with-php/"]Detecting Search Engine Bots in PHP[/URL] for more information on search engine spider detection.[/I]

[b]Side Note:[/b] I would strongly advise against using an IP to track a user. First, if a user is on a large network running through a central router, all the computers on that network would have the same IP address. Large businesses and colleges usually have several IP addresses, but not a unique IP for each computer. This means that if 100 unique people on one network view an article once in a 24 hour period, it will only register as 1 unique view, instead of 100. Beyond this, IP addresses are easily masked. Users can hide behind a proxy or use a client such as Tomato to change IP addresses.

FlashCreations 20

Try this..you need some quotes (You also need a form action..which can be easily fixed by PHP_SELF which will insert the name of the current PHP page):

[CODE=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Untitled Document

FlashCreations 20

You can check for a search by the employee's name. Then you can check for a space. If there is a space you can split the two names with explode and then perform a query that matches first and last name. If there isn't any spaces only perform a query for the first or last name (Depending on what you want).
[CODE=php]
<?php
if(isset($_POST['searchType'])) //Check first, get values later
{
$method=$_POST['searchType'];
$search=$_POST['query'];

switch ($method)
{
    case 'EmployeeFName': //Switch is not like if...you don't need an expression, just a value will do
        if(empty($_POST['query'])) exit("Please Fill in a name of an employee you want to search. Click <a href=search.php>here</a> to go back.</p>");
        else
        {
            echo"<i>Your search for {$search} had the following results:</i>";
            //Here's the magical splitting of the names
            $arr = explode(" ", $search);
            $search_first = $arr[0];
            $search_last = $arr[1];

            $query = mysql_query("SELECT * FROM Employee WHERE EmpFName = '".$search_first."' AND EmpLName = '".$search_last."'");
            $result = mysql_query($query);
            if(mysql_num_rows($result)==0) echo exit("<font color='red'>No Record Found</font>");
            echo"<table class='full'>";
            echo"<th></th><th>ID</th><th>Employee Name</th><th>Title</th><th>Team</th><th>Department</th></tr>";
            while ($row = mysql_fetch_array($result)) //Ohh! You can only fetch from a result RETURNED by mysql_query, not the actual query
            { 
                //No need to setup individual variables...just use the $row array!
                echo"<tr><td class='view'><form action='employee.html' method='post'><div><input type='submit' value='View' class='button' /></div></td><td name='userID' class='id'>".$row["EmployeeID"]."</td></form><td name='userName' class='record'>".$row["EmployeeFName"];." ".$row["EmployeeLName"]."  </td><td name='userTitle' class='record'>".$row["EmployeeTitle"]."</td><td name='userTeam' class='record'>".$row["EmployeeTeam"]."</td><td name='userDept' class='record'>".$row["EmployeeDepart"]."</td></tr>";
            }
        }      
        break;
    //And on, and on, etc.
}

}

function mysqlConnectAndSelect()
{
checkLogin();
sqlConnect();
mysql_select_db("titans", $con);
}
?>
[/CODE]
There are also lots more problems beyond this one. I'd be glad to fix them ...

FlashCreations 20

Alright then, have you replaced all your files (for this project) with one file called paycheck.php and added [b]only[/b] my code to it. Line 10 is the end of the first if block. I tried it on my XAMPP and it worked perfectly and didn't have any errors. (And the reason why the form is being filled out again is because a value is missing...it simply fills in the values you gave it and leaves the other required ones blank). On a side note: Don't worry about all the questions. When you are new to a language it's hard at first, but you'll get it eventually and maybe answer people's questions on DaniWeb!

EDIT:
One little fix that I just remembered. It shouldn't fix your error, but it should fix and output problem:
[code=PHP]

Paycheck Calculator

FlashCreations 20

Try this, you were missing some semicolon's at the end of your lines:

[b]paycheck.php:[/b]
[CODE=php]

Paycheck Calculator