Jenk
-
Posts
778 -
Joined
-
Last visited
Never
Posts posted by Jenk
-
-
something like..
[code]<?php
$file = file('/path/to/file.csv');
foreach ($file as $line)
{
foreach (explode("\t", $line) as $num => $col)
{
echo '<p>' . htmlentities($col) . '=' . htmlentities($num) . '</p>';
}
}
?>[/code]
[/code] -
If you want a function that doesn't cut words, read the user notes for substr() over at [url=http://php.net/substr]http://php.net/substr[/url]
-
Ravi - no, that will not work. You have specified for mysql_fetch_array to return a numerically indexed array, but then go on to use associative index's..
still applies to your new example. -
[quote author=SemiApocalyptic link=topic=107879.msg433253#msg433253 date=1158131109]
Yes, register_globals should be switched off, for security reasons over anything else - check the manual for more information on that. As far as I understand, what register_globals actually does, it registers global variables. So, once you create them they are available throughout your PHP pages. For example, on page one we define the variable '$name' and assign the value 'Kris', then on page two we can just echo $name and it will print 'Kris' to the screen, this is without passing it via get, post, cookie or session. Please, anyone, correct me if I have misunderstood register_globals.
[/quote]Not quite correct, it doesn't register session variables for you (your example with $name will not work with register_globals alone.)
All register globals does is define each index of $_REQUEST, $_SESSION and $_SERVER as a standalone variable in the global namespace. -
run the query manually in mysql command prompt/phpmyadmin/mysql administrator to see expected results.
Ravi - no, that will not work. You have specified for mysql_fetch_array to return a numerically indexed array, but then go on to use associative index's..
mysql_fetch_assoc() will do fine, changing to *_array was unecessary. -
Why don't you use code from the umpteen other examples??
.. beacause you rather someone did *all* of your work for you, for free, while you learn nothing at all? -
[code]foreach ($arr as $k1 => $v1) {
foreach ($v1 as $k2 => $v2) {
echo "<input type='hidden' name='arr[$k1][$k2]' value='$v2' />";
}
}[/code] -
Obscurity != Security.
First rule of programming.
You can argue all day long with 'whatifs' but POST'ing SQL statements is a definite 'No.' -
you only need to stripslashes() post data if magic_quotes are on :)
-
Sending an SQL statement over POST... that's the security vulnerability.
You are limiting the accessibility of such functionality to a select few, but for a start you might as well just write down your DB schema on a piece of paper, make a paper plane out of it and launch it out the window :)
I am utterly surpised no one has pointed out mysql_connect() does not have to have the host specified as 127.0.0.1/localhost everytime.. you can use other hosts (machines) .. -
Yes, it can run as CLI.
btw, PHP: [b]P[/b]eople [b]H[/b]ate [b]P[/b]erl.
(though you'll never find that officially stated anywhere.) -
one of the biggest unofficial no-no's in OOP is the use of globals :)
'good' OOP practice is pass values around as parameters when and where needed, not to blanket label something for all to see :)
[code]<?php
$config = new XMLConfig('config.xml');
$db = new DataBaseClass;
$db->connect($config->db_host, $config->db_user, $config->db_pass);
//etc.
?>[/code]
For what you have posted above re: loading, I suggest your read up on the Service Locator pattern, Dependancy Injection and also the use of a Registry. -
[code]<?php
foreach ($array as $value)
{
echo '<input type="hidden" name="array_name[]" value="' . htmlentities($value) . '" />' . chr(10);
}
?>[/code][/code] -
[code]ORDER BY date, id DESC[/code]
-
empty(0) === true, too.
-
start with an sql query:
[code]SELECT * FROM `users`[/code]
The rest, have a go at, and particular problems then post here. Don't just ask someone else to do it for you. -
Easiest/quickest way:
[code]<?php
$string = 'HE11O22';
$numAlpha = strlen(preg_replace('/[^a-z]+?/i', '', $string));
$numNumerical = strlen(preg_replace('/[^0-9]+?/i', '', $string));
?>[/code] -
I did explain, in plain English too. You did not - You asked for advice on your logic, I gave advice on your logic.
Also note, this is a public discussion forum. Hence it being open to discussion.
So next time I explain the use of || or && I have to post an example?
Ok.
[code]<?php
$a = 1 || 2;
$b = 1 && 2;
?>[/code]
done. -
you may want to use || (or) instead of && (and) if you want the user to respond by email if any of the fields are empty.
-
strip_tags() to remove all html tags.
[code]<?php
$string = preg_replace('/<(\s*)img[^<>]*>/i', '', $string);
?>[/code]to remove just img -
A Framework. :)
-
PHP_SELF can be tainted with user input, so don't use it. Use SCRIPT_NAME instead.
and pagination in it's most simplest form:
[code]<?php
$link = mysql_connect(/* db details */) or die('Connection error');
mysql_select_db(/* db */, $link) or die('Db error');
if (!empty(trim((int)$_GET['page'])))
{
$page = (int) $_GET['page'];
}
else
{
$page = 1;
}
$max = 10;
$start = $max * ($page -1);
if (!$result = mysql_query("SELECT * FROM `table` LIMIT $start, $max", $link))
{
die ('Query error');
}
while ($row = mysql_fetch_assoc($result))
{
foreach ($row as $cell => $val)
{
echo '<p>' . htmlentities($cell) . ' => ' . htmlentities($val) . '</p>' . chr(10);
}
}
$result = mysql_query('SELECT COUNT(*) AS A FROM `table`');
$numpages = ceil(mysql_result($result, 0) / $max);
for ($i = 1; $i < $numpages; $i += $max)
{
$j = $i / $max;
echo '<a href="' . htmlentities($_SERVER['SCRIPT_NAME']) . '?page=' . $j . '">' . $i . '</a> ';
}
?>[/code] -
You still haven't posted the code that is rellevant to the error. Post the block of code that causes the error.
-
[code]<?php
$shipping = ($price * 0.075) + 5.5;
?>[/code]
PHP code returns blank
in PHP Coding Help
Posted
Also worth noting that[code=php:0]mysql_fetch_assoc($result);[/code] achieves the same functionality as [code=php:0]mysql_fetch_array($result, MYSQL_ASSOC);[/code]