Yeah I saw that and changed it but in my original code it still didn't work. But it's all good now thanks a lot!
No problem! Glad it's all fixed! :)
Yeah I saw that and changed it but in my original code it still didn't work. But it's all good now thanks a lot!
No problem! Glad it's all fixed! :)
Regarding for your original code, the reason why the IP displayed but you couldn't click the link is because you were missing an = between the href and the first quote. Try this:
<a href="<?= $ip ?>"><?= $ip ?></a>
Also notice that since you have shorttags enabled I used shortened syntax to print variables. It removes the need for print or echo in short, one-line variable outputs and will be compatible with PHP (with shorttags enabled) until 6.0.0.
So is it solved? If not, can you give us a sample of some of the URL's you try? The URL you gave in the first post should work fine and did work fine when I tried it. If it doesn't, have you set your charset to the appropriate one with the meta charset tag?
:D yeah, you're really good at samples- no second thought with that PHP man (former PMC man). Ϋ
Never gotten that before, but PHP Man works too. I'll have to make note of that somewhere on the new site! :)
You can use
as an empty space in any empty table columns and rows. It's HTML's way of representing a space. In case you haven't noticed, a space along usually doesn't work, and multiple spaces (or a new line) do no appear.
is the answer to the multiple space (or single space alone) problem.
Tizag has a great tutorial on getting started with PHP uploads. Read over it and post back if you have any questions.
Tip: Be sure to check the file type so users can't upload exe's, dll's or any non-image files.
EDIT: To DaniWeb: Please update your posting system so if my token has expired when I post, I don't have to hit the back button and re-type everything.
Alright, take two. The gist of it is that there are two problems. The simpler of the two to fix is the problem regarding the URL. To access the var parameter you should use $matches[1]
instead.
The second problem involving the style can be fixed in a similar manner as above, but also requires a Regex fix. Here is your revised code:
$this->avatar = $post->find('div[class=shell] td');
foreach($this->avatar as $avatar) {
preg_match('/url\("([a-z0-9-_\.\/]*\/)?([a-z0-9-_\%\.]+)"\)/i', $avatar->style, $matches); // Thanks "FlashCreations"/"PhpMyCoder"!
$this->avatar = $matches[2];
echo $this->avatar . 'Hello world!';
}
Hope this fixes everything! :)
-PhpMyCoder
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.
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
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
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?
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 …
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!).
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?
Inside a complex syntax brackets ( {$var}
) 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:
$message .= "<td>XXXX-XXXX-XXXX-{substr($_GET['cc_number'] , -4, 4)}</td>";
//Or this....
$message .= "<td>XXXX-XXXX-XXXX-".substr($_GET['cc_number'] , -4, 4)."</td>";
//Or even this...
$message .= "<td>XXXX-XXXX-XXXX-";
$message .= substr($_GET['cc_number'] , -4, 4);
$message .= "</td>";
The first or second ones make most sense to me, so I would chose one of them, but it's totally up to you!
I have updated the script again to fix the notices (Your setup seems to be very picky about $_GET and $_POST variables!). To achieve what you are looking for, you will need some simple css. With the current code, all you need to do is add this style to the top of your page. The only other thing you will need to do is enclose the navigation inside a div with and id of nav like this:
<div id="nav">
<?php
//Show the navigation
$paginator->navigation();
?>
</div>
And here's the CSS to include:
#nav { font: normal 13px/14px Arial, Helvetica, sans-serif; }
#nav a { background: #EEE; border: 1px solid #DDD; color: #000080; padding: 1px 7px; text-decoration: none; }
#nav strong { background: #000080; border: 1px solid #DDD; color: #FFF; font-weight: normal; padding: 1px 7px; }
The only thing it doesn't do is apply the box (possibly a grayed out one) to the disabled Next and Previous links. If You wish for this to happen, reply back and I'll make the slight changes that are necessary for this to happen.
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.
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.)
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.
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";
?>
You need to connect to a database (Such as MySQL) then perform the queries in your arrays (You also need to unescape the quotes after the "tfr", it will stop the query from working).
Try something like this:
<?php
//Why do all three of these have the same name
//Is it your intention to reset them three times?
$qualifiers_array[0] = "SELECT * FROM table WHERE trk is not null AND WHERE tfr = '1'";
$qualifiers_array[1] = "SELECT * FROM table WHERE tfr='2'";
$qualifiers_array[2] = "SELECT * FROM table WHERE tfr='3'";
?>
<html>
<head>
<title>Database Results</title>
</head>
<body>
<?php
include($_SERVER['DOCUMENT_ROOT'].'/*****/*****/*****/*****.php');
mysql_connect("localhost", "INSERT USER HERE", "INSERT PASS HERE");
$result = mysql_query("NAMES QUERY");
if($result)
{
$i = 0;
while($arr = mysql_fetch_array($result))
{
//Transfer values from table to result array
//Ex. $values[0][$i] = $arr['column_name'];
$i++;
}
}
//Repeat for other queries
?>
<table border='1'>
<tr>
<th>Filter Name</th>
<th>Profit</th>
<th>Winners</th>
<th>Qualifiers</th>
<th>%age</th>
</tr>
<?php
for($i=0;$i<count($values[0]);$i++)
{
echo "<tr>\n"
echo " <td width='20%'>". $result[0][$i] . "</td>\n";
echo " <td width='20%'>". $result[1][$i] . "</td>\n";
echo " <td width='20%'> </td>\n";
echo " <td width='20%'>". $result[2][$i] . "</td>\n";
echo " <td width='20%'> </td>\n";
echo "</tr>\n\n";
?>
</table>
</body>
</html>
But there are problems beyond that. Why not PM me and we can get this sorted out. I can help you fix-up, clean-up, and optimize your code!
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).
<?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);
}
?>
There are also lots more problems beyond this one. I'd be glad to fix them all for …
My suggestion stated _before_ the query...
$link = array (); $result = mysql_query($sql): while ($row = mysql_fetch_array($res)) { $link[]=$row; }
Exactly..though it does need one minor fix! (But I'm sure you knew this!):
$link = array();
$result = mysql_query($sql); //<-- Semicolon
while ($row = mysql_fetch_array($res))
{
$link[] = $row;
}
Also, I believe the problem was that instead of $links
, %links
as used, but your solution provides a safety if there are no rows returned (Which is a good thing to have!).
@Dukane
You made the same error as Newbi..the correct code is below (Don't worry about it, I've made worse mistakes :D):
while($info = mysql_fetch_array($result))
The reason for this is as Dukane explained...When you perform a query the query string is executed with the mysql_query()
function. This function returns a special MySQL Result that you can then pass to mysql_fetch_array()
or any other MySQL Result functions.
That's great that you got it to work! If you don't have any more questions...would you please mark this thread as solved?
You would probably want to use a MySQL table to store the emails. Then all you would have to do is write a php script that you can use to send email (Just make sure to password protect it for security!!).
PHPList is a pre-coded, easily customizable PHP mailing list application. Check it out on their website (Note to Mods: I'm not advertising this product as it's free. I'm simply providing a pre-coded resource that might be easier to understand/use).
Ok then, try this:
<?php
session_start();
if(session_is_registered('user'))
{
$user=$_SESSION['user'];
$del="DELETE FROM online WHERE user='$user'";
$result=mysql_query($del);
if($result==true)
{
echo "<h3>Member Offline</h3>\n";
}
else
{
echo "<h3>Failed to Logoff</h3>\n";
}
//Remove the Session Vars
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
//include"index.php";
}
else
{
include "index.php";
}
?>