Re: [PHP] /tmp/directory

2013-07-22 Thread Ken Robinson

At 11:50 AM 7/22/2013, Tedd Sperling wrote:

On Jul 22, 2013, at 11:20 AM, Tedd Sperling t...@sperling.com wrote
 Hi gang:

 I should know this, but I don't.

 Where is the /tmp/ directory?

 You see, I have a client where his host has apparently changed 
the /tmp/ directory permissions such that old php/mysql scripts 
cannot write to the /tmp/ directory anymore -- they did at one time.


 So, how do I fix it?

 Cheers,

 tedd

Let me add -- the PHP version I am working with is 4.3.10.

I know...

tedd


The version of PHP should have nothing to do with this problem.

The /tmp directory should be writable by everyone. If it's not, you 
need to talk to the hosting company support people.


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Guaranteed Way to Get Error Message Wanted

2013-07-05 Thread Ken Robinson
Check the permissions on the files/directories involved. I get this 
on Linux when the files/directories are too open.


Ken

At 05:38 PM 7/5/2013, Brian Smither wrote:
I have an application running under PHP-5.4.17-TS-VC9 (and .14 as of 
yesterday) with Aprelium's Abyss X1 v2.8 web server in FastCGI mode 
on WinXPSP3.


An earlier version of this application works. The current version 
causes a 500 Internal Server Error. There is no entry in PHP's 
(fully active) error log. I cannot decipher Abyss's logging, so I 
cannot determine if a clue was reported by Abyss or not.


The current version works on a different system (Server 2003, PHP 
5.3.5-TS-VC6 (Apache module), Apache 2.2).


What I would like to have is a method of getting PHP to report in 
some undeniable manner, short of total system failure, what it 
doesn't like about whatever killed it.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] scandir doesn't find all files

2013-06-22 Thread Ken Robinson


Sent from my iPhone

On Jun 22, 2013, at 3:10 PM, Daniel Pöllmann poellmann.dan...@gmail.com wrote:

 Hi,
 I have some files in a directory - some are uploaded via ftp and some other
 are created by a php script.
 
 Scandir just finds the uploaded files, but none of the created files.
 I can't run chown() because the server is part of shared hosting.
 
 I can't find anything about this behavour in the documentation.
 
 Best wishes,
 Daniel

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] scandir doesn't find all files

2013-06-22 Thread Ken Robinson
Did you try the glob function? http://php.net/glob

Ken

Sent from my iPhone

On Jun 22, 2013, at 3:10 PM, Daniel Pöllmann poellmann.dan...@gmail.com wrote:

 Hi,
 I have some files in a directory - some are uploaded via ftp and some other
 are created by a php script.
 
 Scandir just finds the uploaded files, but none of the created files.
 I can't run chown() because the server is part of shared hosting.
 
 I can't find anything about this behavour in the documentation.
 
 Best wishes,
 Daniel

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] iterate javascript verification

2013-05-27 Thread Ken Robinson
When you do validation of the form in the same script that shows the 
form, the normal way to do this is


?php
   if (isset($_POST['submit'])) {
//
//  validation here
//
}
?

This won't work if you're getting to the page via another form, since 
the $_POST['submit'] is set. There two ways of avoiding this:


1) use hidden fields in each form to indicate which form was submitted
2) use a different name for each form's submit button and use that in 
the above code


Ken


At 12:52 PM 5/27/2013, Tim Dunphy wrote:

Hey guys,

Thanks for the input! This is pretty nice, and DOES work. I like the fact
that the fields have been into an iterative array. It's a very elegant
solution. However the problem with this approach is that if you load the
page directly it works. But if you call the page from the index.php page
you get an initial error on all fields as they are all quite naturally
empty when you first load the page.

Here's the index.php page. All it is is HTML, no php:

html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en
head
  meta http-equiv=Content-Type content=text/html; charset=utf-8 /
  titleLDAP Request Form/title

body
  centerh3LDAP Request Form/h3
   form name=form_request method=post action=ldap.php
onsubmit=return validateForm()
label for=requestor_emailYour Email Address:/labelbr /
input type=text required id=requestor_email name=requestor_email
/br /br /
label for=num_formsHow Many Forms Do You Need:/labelbr /
input type=text required maxlength=2 size=5 id=num_forms
name=num_forms /br /br /
input type=submit name=submit value=Submit /
  /form/center
/body
/html

And here is ldap.php as was suggested:

body

  ?php

   if (isset($_POST['submit'])) {
$requestor_email = $_POST['requestor_email'];
$num_forms  = $_POST['num_forms'];
}


echo centerYou will be creating $num_forms accounts
today./centerbr /;
for($counter = 1;$counter=$num_forms;$counter++) {
echo 'centerform name=ldap_accounts method=post
action=sendemail.php onsubmit=return validateForm()';
echo 'br /br /';
echo Enter user: $counterbr /br /;
echo label for=\first_name_.$counter.\First Name:/labelbr
/;
echo input type=\text\ id=\first_name_.$counter.\
name=\first_name_.$counter.\ /br /br /;
echo label for=\last_name_.$counter.\Last Name:/labelbr /;
echo input type=\text\ id=\last_name_.$counter.\
name=\last_name_.$counter.\ /br /br /;
echo label for=\department_.$counter.\Department:/labelbr
/;
echo input type=\text\ id=\department_.$counter.\
name=\department_.$counter.\ /br /br /;
echo label for=\title_.$counter.\Title:/labelbr /;
echo input type=\text\ id=\title_.$counter.\
name=\title_.$counter.\ /br /br /;
echo label for=\email_.$counter.\Email:/labelbr /;
echo input type=\text\ id=\email_.$counter.\
name=\email_.$counter.\ /br /br /;
echo label for=\phone_$counter.\Phone:/labelbr /;
echo input type=\text\ id=\phone_.$counter.\
name=\phone_.$counter.\ /br /br /;
  }

  echo input type=\hidden\ id=\num_forms\ name=\num_forms\
value=\$num_forms\ /br /br /;
  echo input type=\hidden\ id=\requestor_email\
name=\requestor_email\ value=\$requestor_email\ /;
  echo input type=\submit\ name=\submit\ value=\Create Ticket\ /;
  echo /form/center;




   ?


Why this happens when you call the ldap.php page from index.php but not
when you load the page directly beats me. But maybe someone can shed some
light on that?

Thanks!



On Sat, May 25, 2013 at 3:45 AM, tamouse mailing lists 
tamouse.li...@gmail.com wrote:

 On Fri, May 24, 2013 at 9:51 PM, Ken Robinson kenrb...@rbnsn.com wrote:
  I took your code and modified it to use HTML5 validation (and few other
  changes). You can see the results at
  http://my-testbed.com/test1/form_validation.php
 http://my-testbed.com/test1/form_validation.php
 
  My code follows:
 
?php
$fields =
  array('first_name','last_name','department','title','email','phone');
$num_forms = 1;
$tmp = array();
$errors = array();
 
 
 if (isset($_POST['submit'])) {
  $requestor_email = $_POST['requestor_email'];
  $num_forms  = $_POST['num_forms'];
  for ($i = 1;$i = $num_forms; ++$i) {
  foreach ($fields as $fld) {
  if ($_POST[$fld][$i] == '') {
  $errors[] = ucwords(str_replace('_',' ',$fld)) .
 
  for account $i can not be blank;
  }
  }
  }
}
  if (!empty($errors)) {
  $tmp[] = The following fields are in
 error:br;
  $tmp[] = implode(br\n,$errors);
  $tmp[] = br;
  }
  $tmp[] = div style='text-align:center'You will be creating
 $num_forms
  accounts today./divbr;
  $tmp[] = 'div style=text-align:centerform name=ldap_accounts
  method=post action=';
  $tmp[] = 'br /br /';
 
  for($counter = 1;$counter

Re: [PHP] iterate javascript verification

2013-05-24 Thread Ken Robinson
You do realize that you shouldn't rely on Javascript to validate 
values returned in a form?  Also, if you use HTML5, you can use the 
required attribute in the input tag and the browser won't let a 
user submit a form with a required field not filled. Of course, you 
should still validate within your PHP script, in case a user is using 
a browser that doesn't understand HTML5.


At 08:07 PM 5/24/2013, Tim Dunphy wrote:

Hello list,

 I have a php script that creates a variable number of forms based on a
$_POST variable from a preceding page. It then takes the data input into
the form and neatly packages the result into an email sent to an email
address (eventually to be a ticketing system).


Almost everything on the page works great. The only thing I can't seem to
get working is how to verify that the fields in the form are not left empty
using javascript. The syntax I'm using seems like it should work, however
when I leave one or more of the fields empty, the email gets sent anyway
with the missing data.

Here's the app I was hoping someone might be able to suggest a successful
approach:

html
head
titleLDAP Form/title
body
  ?php

   if (isset($_POST['submit'])) {
$requestor_email = $_POST['requestor_email'];
$num_forms  = $_POST['num_forms'];
}

echo centerYou will be creating $num_forms accounts
today./centerbr /;
for($counter = 1;$counter=$num_forms;$counter++) {
echo 'centerform name=ldap_accounts method=post
action=sendemail.php onsubmit=return validateForm()';
echo 'br /br /';
echo Enter user: $counterbr /;
echo label for=\first_name_.$counter.\First Name:/labelbr
/;
echo input type=\text\ id=\first_name_.$counter.\
name=\first_name_.$counter.\ /br /br /;
echo label for=\last_name_.$counter.\Last Name:/labelbr /;
echo input type=\text\ id=\last_name_.$counter.\
name=\last_name_.$counter.\ /br /br /;
echo label for=\department_.$counter.\Department:/labelbr
/;
echo input type=\text\ id=\department_.$counter.\
name=\department_.$counter.\ /br /br /;
echo label for=\title_.$counter.\Title:/labelbr /;
echo input type=\text\ id=\title_.$counter.\
name=\title_.$counter.\ /br /br /;
echo label for=\email_.$counter.\Email:/labelbr /;
echo input type=\text\ id=\email_.$counter.\
name=\email_.$counter.\ /br /br /;
echo label for=\phone_$counter.\Phone:/labelbr /;
echo input type=\text\ id=\phone_.$counter.\
name=\phone_.$counter.\ /br /br /;
  ?
   script
function validateForm()
 {
   var a=document.forms[ldap_accounts][first_name_].value;
   if (a==null || a==)
   {
alert(User $counter first name must be filled out.);
return false;
   }
var b=document.forms[ldap_accounts][last_name_].value;
if (b==null || b==)
{
alert(User $counter last name must be filled out.);
return false;
}
var c=document.forms[ldap_accounts][department_].value;
if (c==null || c==)
{
alert(User $counter department must be filled out.);
return false;
}
var d=document.forms[ldap_accounts][title_].value;
if (d==null || d==)
{
alert(User $counter title must be filled out.);
return false;
}
var d=document.forms[ldap_accounts][email_].value;
if (d==null || d==)
{
alert(User $counter address must be filled out.);
return false;
}
var d=document.forms[ldap_accounts][phone_].value;
if (d==null || d==)
{
alert(User $counter phone name must be filled out.);
return false;
}
  }
 /script
 ?php
  }

  echo input type=\hidden\ id=\num_forms\ name=\num_forms\
value=\$num_forms\ /br /br /;
  echo input type=\hidden\ id=\requestor_email\
name=\requestor_email\ value=\$requestor_email\ /;
  echo input type=\submit\ name=\submit\ value=\Create Ticket\ /;
  echo /form/center;

   ?
/body
/html

Thanks,
Tim

--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] iterate javascript verification

2013-05-24 Thread Ken Robinson
I took your code and modified it to use HTML5 validation (and few 
other changes). You can see the results at 
http://my-testbed.com/test1/form_validation.phphttp://my-testbed.com/test1/form_validation.php 



My code follows:

  ?php
  $fields = 
array('first_name','last_name','department','title','email','phone');

  $num_forms = 1;
  $tmp = array();
  $errors = array();

   if (isset($_POST['submit'])) {
$requestor_email = $_POST['requestor_email'];
$num_forms  = $_POST['num_forms'];
for ($i = 1;$i = $num_forms; ++$i) {
foreach ($fields as $fld) {
if ($_POST[$fld][$i] == '') {
$errors[] = ucwords(str_replace('_',' 
',$fld)) .  for account $i can not be blank;

}
}
}
  }
if (!empty($errors)) {
$tmp[] = The following fields are in error:br;
$tmp[] = implode(br\n,$errors);
$tmp[] = br;
}
$tmp[] = div style='text-align:center'You will be creating 
$num_forms accounts today./divbr;
$tmp[] = 'div style=text-align:centerform 
name=ldap_accounts method=post action=';

$tmp[] = 'br /br /';
for($counter = 1;$counter=$num_forms;$counter++) {
$tmp[] = Enter user: $counterbr /;
$tmp[] = label for='first_name_$counter'First Name:/labelbr/;
$tmp[] = input type='text' required 
id='first_name_$counter' name='first_name[$counter]'br /br /;

$tmp[] = label for='last_name_$counter'Last Name:/labelbr /;
$tmp[] = input type='text' required 
id='last_name_$counter' name='last_name[$counter]' /br /br /;

$tmp[] = label for='department_$counter'Department:/labelbr/;
$tmp[] = input type='text' required 
id='department_$counter.' name='department[$counter]' /br /br /;

$tmp[] = label for='title_$counter'Title:/labelbr /;
$tmp[] = input type='text' required id'title_.$counter' 
name='title[$counter]' /br /br /;

$tmp[] = label for='email_.$counter'Email:/labelbr /;
$tmp[] = input type='email' required id='email_.$counter' 
name='email[$counter]' /br /br /;

$tmp[] = label for='phone_$counter'Phone:/labelbr /;
$tmp[] = input type='text' required id='phone_$counter' 
name='phone[$counter]' /br /br /;

  }
  $tmp[] = input type='hidden' id='num_forms' name='num_forms' 
value='$num_forms' /br /br /;
  $tmp[] = input type='hidden' id='requestor_email' 
name='requestor_email' value='$requestor_email' /;

  $tmp[] = input type='submit' name='submit' value='Create Ticket' /;
  $tmp[] = /form/div;

?
!DOCTYPE html
html
head
titleLDAP Form/title
body
?php echo implode(\n,$tmp) . \n; ?
/body
/html

You will notice that I moved the code for the form to above the HTML 
section. I believe that very little PHP should be interspersed with 
the HTML -- it makes for cleaner code. You can use single quotes 
around form attributes so you don't have to escape the double quotes. 
The names in the form are now arrays. This makes your life much 
easier when extracting the values later in PHP.


When you check the page in a HTML5 aware brower, you will see how the 
validation is done.


Ken

At 10:17 PM 5/24/2013, musicdev wrote:

You can validate via JS if required, for example: (JS CODE):

if(element.value.length == 0){
   // handle 0 length value
}

I do agree with Ken that you SHOULD NOT perform JS validation.  It is
preferable to use php or the new HTML5 features.  JS can be turned-off by
the user which will make JS validation impossible.


On Fri, May 24, 2013 at 8:07 PM, Tim Dunphy bluethu...@gmail.com wrote:

 Hello list,

  I have a php script that creates a variable number of forms based on a
 $_POST variable from a preceding page. It then takes the data input into
 the form and neatly packages the result into an email sent to an email
 address (eventually to be a ticketing system).


 Almost everything on the page works great. The only thing I can't seem to
 get working is how to verify that the fields in the form are not left empty
 using javascript. The syntax I'm using seems like it should work, however
 when I leave one or more of the fields empty, the email gets sent anyway
 with the missing data.

 Here's the app I was hoping someone might be able to suggest a successful
 approach:

 html
 head
 titleLDAP Form/title
 body
   ?php

if (isset($_POST['submit'])) {
 $requestor_email = $_POST['requestor_email'];
 $num_forms  = $_POST['num_forms'];
 }

 echo centerYou will be creating $num_forms accounts
 today./centerbr /;
 for($counter = 1;$counter=$num_forms;$counter++) {
 echo 'centerform name=ldap_accounts method=post
 action=sendemail.php onsubmit=return validateForm()';
 echo 'br /br /';
 echo Enter user: $counterbr /;
 echo label for=\first_name_.$counter.\First Name:/labelbr
 /;
 echo input type=\text\ id=\first_name_.$counter.\
 

Re: [PHP] Symfony?

2013-05-20 Thread Ken Robinson

Drupal 8 is being built using Symfony, which means I have to learn it.

Ken

At 12:44 PM 5/20/2013, Bastien wrote:



Bastien Koert

On 2013-05-20, at 12:40 PM, Tedd Sperling t...@sperling.com wrote:

 Hi gang:

 Who uses Symfony?

 Cheers,

 tedd


 _


I do. It's not my preferred framework. It's very powerful, but very 
complex and has a ton of yaml config files for the app. The learning 
curve is steep.


What's the question?

Bastien
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] significance of escape character in string in PHP

2013-03-18 Thread Ken Robinson



On 18.03.2013 09:10, Norah Jones wrote:

I am having an string which was have few ' (single quote) and few 
(double quotes) and was not able to insert into the mysql database. I
have replaced them with \' and \ and everything is fine.
Though this are fine now but don't understand the working and I could
have missed few corner cases also. Please suggest the working and 
also

if there is some better way to achieve this.


You should be using either mysql_real_escape_string or 
mysqli_real_escape_string (preferably the later) depending on how you're 
accessing the DB.


Ken

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date problem

2013-01-03 Thread Ken Robinson

At 04:57 PM 1/3/2013, Marc Fromm wrote:

I am comparing to dates.

define('WSOFFBEGIN','09/16/2012');
$jes = 01/03/2012;

if ( date(m/d/Y, strtotime($jes))  date(m/d/Y, strtotime(WSOFFBEGIN)) )
{
$error =  MUST begin after  . WSOFFBEGIN . \n;
}

I cannot figure out why the $error is being assigned inside the if 
statement, since the statement should be false. 01/03/2012 is not 
less than 09/16/2012.


You shouldn't be comparing the date strings, but the UNIX timestamp values:

define('WSOFFBEGIN','09/16/2012');
$jes = 01/03/2012;

if ( strtotime($jes)  strtotime(WSOFFBEGIN) )
{
$error =  MUST begin after  . WSOFFBEGIN . \n;
}

Ken



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Strange string stuff -- maybe everything is ending...

2012-12-21 Thread Ken Robinson
A much easier way to do this would be to use a temporary array and 
then explode:


$tmp = array();
while($row = mysql_fetch_array($result)) // pulling stuff 
from a database

{
$tmp[] = $row['category'];
}

$topic = explode('~',$tmp); // put the delimiter between 
each entry

echo($topic);   // this result is used in an AJAX script


No more worrying about whether the delimiter is the last character.

Ken

At 04:38 PM 12/21/2012, Tedd Sperling wrote:

Hi gang;

I just ran into something I have never had a problem with before.

Here's the code:

--- start of code

$topic = '';
while($row = mysql_fetch_array($result))  // pulling stuff 
from a database

{
$topic .= $row['category'] . '~';   // adding a 
delimiter between categories

}

$str_length = strlen($topic);
if($topic[$str_length-1] == '~')
{
$topic[$str_length-1] = ''; // remove last ~ delimiter
}

echo($topic);   // this result is used in an AJAX script

--- end of code

Now, when the result is displayed (i.e., echoed) to Javascript 
routines running in Safari and FireFox, everything is OK.


But when the result is displayed on IE, the end of the string 
causes problems with the exact same javascript routine as used above.


Now, I realize that I have altered the string by removing the last 
character and I have not shortened the string to reflect that, but I 
never thought it would cause any problems.


Would someone please enlighten me as to why this would work in 
Safari, FireFox, but not in IE?


Cheers,

tedd

PS:  Also, please don't beg the answer by saying It's IE -- what do 
you expect?


_
t...@sperling.com
http://sperling.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Strange string stuff -- maybe everything is ending...

2012-12-21 Thread Ken Robinson
Can you post the javascript that's causing the problem? And, yes, 
it's IE, what did you expect... :-)


Ken

At 05:10 PM 12/21/2012, Tedd Sperling wrote:

On Dec 21, 2012, at 5:05 PM, Ken Robinson kenrb...@rbnsn.com wrote
 A much easier way to do this would be to use a temporary array 
and then explode:


 $tmp = array();
while($row = mysql_fetch_array($result)) // pulling stuff 
from a database

{
$tmp[] = $row['category'];
}

$topic = explode('~',$tmp); // put the delimiter 
between each entry

echo($topic);   // this result is used in an AJAX script


 No more worrying about whether the delimiter is the last character.

 Ken

Ken:

Slick -- I like it.

But, the question remains -- if you make the last character in a 
string a '' (or null), then what's the problem with doing that?


Cheers,

tedd

_
t...@sperling.com
http://sperling.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] re:Switch - Case Statement Questions

2012-11-16 Thread Ken Robinson

At 07:10 AM 11/16/2012, Omar Muhsin wrote:

Hello,

I was just wondering after writting the code in version 2 here 
below, it turns out in testing that it actually PHP is not 
validating the expressions instead always I get the first case.


1.Using nested if statement {THE INTENDED BEHAVIOR}:
if ($count  14)
$boxes = 3;
elseif($count  7  $count = 14)
$boxes = 2;
else
$boxes = 1;

2. Using Switch {ALWAYS FIRST CASE!!!}

//$boxes = 1;
//switch ($count) {
//case ($count  14):
//$boxes = 3;
//break;
//case ($count  7  $count = 14):
//$boxes = 2;
//break;
//case ($count = 7):
//default :
//$boxes = 1;
//break;
//}


For the switch statement to work, you need to use switch (true)
   $boxes = 1;
   switch (true) {
case ($count  14):
$boxes = 3;
break;
   case ($count  7  $count = 14):
$boxes = 2;
   break;
   case ($count = 7):
default :
   $boxes = 1;
   break;
}

BTW, you don't need the break statement at the end of the last case 
and you don't really need the case ($count = 7) since that 
condition is what remains anyway.


Ken


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php can't insert data mysql table

2012-09-30 Thread Ken Robinson

At 12:32 AM 10/1/2012, Tim Dunphy wrote:

Hello list,

 I'm trying to learn and get comfortable with HTML forms in PHP. In one
example I am trying to include a file upload in one of the forms. I can
connect to the database but for some reason the MySQL query string is bad.
I've been over this for a while now and I think the problem is with the
form. I was hoping to get the esteemed opinion of the list in where I may
be going wrong.

This code:

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
  http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en
head
  meta http-equiv=Content-Type content=text/html; charset=utf-8 /
  titleGuitar Wars - Add Your High Score/title
  link rel=stylesheet type=text/css href=style.css /
/head
body
  h2Guitar Wars - Add Your High Score/h2

?php
  if (isset($_POST['submit'])) {
// Grab the score data from the POST
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = $_FILES['screenshot']['name'];

if (!empty($name)  !empty($score)) {
  // Connect to the database
  $dbc = mysqli_connect('localhost', 'xxx', 'xxx', 'gwdb')
  or die('Cannot connect to database');

  // Write the data to the database
  $query = INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score',
'$screenshot');
  mysqli_query($dbc, $query)
 or die('Cannot insert query');

  // Confirm success with the user
  echo 'pThanks for adding your new high score!/p';
  echo 'pstrongName:/strong ' . $name . 'br /';
  echo 'strongScore:/strong ' . $score . '/p';
  echo 'pa href=index.phplt;lt; Back to high scores/a/p';

  // Clear the score data to clear the form
  $name = ;
  $score = ;

  mysqli_close($dbc);
}
else {
  echo 'p class=errorPlease enter all of the information to add
your high score./p';
}
  }
?


[snip]

First -- NEVER post code with your database username/password. Since 
you did, change your db password immediately.


Second, when debugging, if you use the die() function, put out 
something meaningful like

... or die(Problem with the insert query: $querybr . mysqli($dbc));

Once you see the database error, you will probably be able to figure 
out the problem.


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array unset()

2012-09-23 Thread Ken Robinson

At 08:50 PM 9/23/2012, Ron Piggott wrote:

I am wondering if there is a way to remove from 
an array where the value is 0 (“zero”)


Array example:

$total_points_awarded = array(  1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 );

In this example I would like to remove element # 4 and # 6.

The “key” ( 1,3,4,5,6 ) represents the 
member’s account #.  It is an auto_increment value in a mySQL table

The “value” ( 17,14,0,1,0 ) represents their score.

The application for this is a list of the top 
users.  If someone has 0 points I don’t want to include them.


Any thoughts?  Any help is appreciated.


Look at array_filter()  ... http://php.net/array_filter

?php
$total_points_awarded = array(  1 = 17, 3 = 14, 4 = 0, 5 = 1, 6 = 0 );
print_r(array_filter($total_points_awarded));


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Find/count different word in a text

2012-04-25 Thread Ken Robinson

At 12:59 PM 4/25/2012, Karl-Arne Gjersøyen wrote:

Hello again.
I am looking for a way to find and count different word in a text..
I am thinking on save the text as array and iterate through the array.
Then I like to register all different words in the text.
For example. If bread is used more than one time, I will not count it.
After the check were I have found single (one) word of every words, I
count it and tell how many different word that is in the text.

Is this difficult to do? Can you give me a hint for were I shall look
on www.php.net for a solution to fix this problem? What function am I
in need of?


I would use a combination of the functions 
str_word_count and array_count_values.


?php
$str = This is a test of word counting and this 
sentence repeats words a a a a a is is is is;

print_r(array_count_values(str_word_count($str, 1)));
?

Ken Robinson 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] http_referer. what's wrong with that?

2012-01-11 Thread Ken Robinson

At 12:27 AM 1/12/2012, Haluk Karamete wrote:

Because I got this

echo $_SERVER['HTTP_REFERER'];

I end up with this

Notice: Undefined index: HTTP_REFERER in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 16
die;

Now, this is of course after the ?php error_reporting (E_ALL); ?  change.

One solution is to dodge it by

echo @$_SERVER['HTTP_REFERER'];


The better way to avoid the error is to do something like

echo (isset($_SERVER['HTTP_REFERER']))?$_SERVER['HTTP_REFERER']:'No 
referrer set';


Which checks to see if it's set before echoing the value. If it's not 
set, you get a message saying so.


Ken



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] number_format

2011-12-19 Thread Ken Robinson

Quoting Floyd Resler fres...@adex-intl.com:

In the previous version of PHP we were using, I could pass a string  
to number_format and it would just change it to a 0 without  
complaint.  With 5.3.6 I get an expects double error.  I don't  
suppose there's a way to make it work like it used to???  I'm  
dealing with really old code that wasn't very well structured.


The way I would get around this would be to create a function like this:

function my_number_format($number, $decimals = 0, $dec_point = '.',  
$thousands_sep = ',') {

   $number += 0;  //convert value to a number.
   return number_format($number, $decimals, $dec_point, $thousands_sep);
}

The just do a global replace of number_format with my_number_format.

That should work, although I haven't tested it...

Ken


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] FW: parse error

2011-10-13 Thread Ken Robinson

At 01:26 PM 10/13/2011, Robert Williams wrote:

On 10/13/11 10:06, David Savage dsav...@cytelcom.com wrote:


php -l voip_cdrs.php
PHP Parse error:  parse error, unexpected T_STRING in
/usr/local/cytrex/voip_cdrs.php on line 1050
Errors parsing voip_cdrs.php

 $alias_sql_stmt=SELECT ani FROM ldrates WHERE
ani='$termnum10';// -this is line 1050

Could you please tell me what's wrong with the line 1050 ?   I've been
pulling my hair out (figuratively speaking) trying to understand why the
compiler sees this line as a problem.  Thanks for whatever help you can
give.

My suspicion is that there's is an unmatched curly brace earlier in the
file. With this type of error, you'll generally get a report of a bad line
further down the file--sometimes way down--because the parser can't
recognize until it hits the later point that something is wrong. Try
double-checking that the {Š} blocks prior to line 1050 properly balance,
and you'll probably find there's an extra one, or that one is missing, etc.


It's more likely an unterminated quoted string. 
It looks like PHP is giving up after finding 
unrecognizable stuff after either the first 
double or single quote on that line. If you're 
using an editor that doesn't do syntax high lighting, get one.


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] FW: parse error

2011-10-13 Thread Ken Robinson

At 02:06 PM 10/13/2011, Steve Staples wrote :

[snip]



It's more likely an unterminated quoted string.
It looks like PHP is giving up after finding unrecognizable stuff 
after either the first double or single quote on that line. If 
you're using an editor that doesn't do syntax high lighting, get one.


Ken

I would suggest that you figure out what is the value of the 
variable your passing into your query  is it possible that the 
value is getting a ' character, in which case it would be crapping 
out the line...


That would only occur when the script is actually executed. It's not 
getting that far yet, since it's dying on a syntax error during the parse.



For now, try adding [addslashes]:
 $termnum10=addslashes(substr($dest, $start_from_which_offset,10));
 $alias_sql_stmt=SELECT ani FROM ldrates WHERE 
ani='$termnum10';// -this is line 1050


No, mysql_real_escape_string 
(http://php.net/mysql_real_escape_string) should be used, not 
addslashes, although there are some people who have suggested that 
even that function is not enough and that only using stored 
procedures is good enough.


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Local variable protection

2011-10-12 Thread Ken Robinson

Quoting Benjamin Coddington bcodd...@uvm.edu:

Are there any assurances that function local variables are protected  
from code calling the function?


For example, I would like to provide some cryptographic functions such as

function org_secure_string($string) {
$org_key = a very random key;
return hash($string, $key);
}

function org_reveal_string($hash) {
$org_key = a very random key;
return unhash($hash, $key);
}

I'd like to protect $org_key from any code following or using these  
functions.  I've not yet found a way that it can be revealed, but I  
wonder if anyone here can give me a definitive answer whether or not  
it is possible.


It's called the scope of the variable. See  
http://us3.php.net/manual/en/language.variables.scope.php


Variables defined in a function are only available to the function  
where they are defined.


Ken


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help on number matching function

2011-09-16 Thread Ken Robinson

At 08:36 AM 9/16/2011, Dare Williams wrote:
Dear PHP Group, I need a Function of any category in  either PHP or 
MySQL RDBMS customize Function, Class, Methods or anything that 
could help me compare a particular set of number and return their 
matching result. e.g If I have a 5 Digits set of number  and need to 
match it with another set of five  digits and return how many number 
are match and the figures that are match. 1.(62,39,47,25,14) - 
(14,39,62,25,47) - match 5 (all) 2.(55,11,27,62,39) - 
(66,39,12,13,27) - match 2 (27,39) 3.(20,04,56,17,16) - 
(16,01,17,04,79) - match 3 (16,17,04) Any Help will be appreciated. Thank you.


Turn your sets of number into an array and then use the function 
array_intersect, http://php.net/array_intersect


Ken



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP within XML?

2011-08-25 Thread Ken Robinson

Quoting Ron Piggott ron.pigg...@actsministries.org:



I am trying to figure out if it is possible to have PHP work within  
an XML document.


The application is tracking RSS subscribers IP addresses within the database.

I have wrote functions so the PHP code required is below is minimal,  
after the XML declaration line.


Prior to posting this question I tried to have the PHP at the very  
start, but that doesn’t work, the declaration line needs to be first.


Right now the PHP is displayed as a comment.


In order for your PHP code to be processed the file should be named  
with a .php extension. Since you're writing XML code, you need to send  
an XML header type first:

?php
header (Content-Type:text/xml);

#load RSS XML function

require_once(rss_subscribers_xml.php);

$ip_address = _ip;
rss_subscriber_update($ip_address);

echo '?xml version=1.0 encoding=utf-8?' . \n;
?
Rest of your XML content.


This should work.

Ken


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] form handling

2011-08-11 Thread Ken Robinson

At 02:25 PM 8/11/2011, Chris Stinemetz wrote:

I have two forms on the same php script. Is it possible to submit both
forms to the same action=processform.php with a single submit
button?


If you want to submit at the same time, why do you have two forms?

Ken


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with inserting numbers...

2011-08-10 Thread Ken Robinson

At 09:22 PM 8/10/2011, Jason Pruim wrote:
So here I am attempting to generate some numbers to be inserted into 
a database... eventually they will make up a phone number (Which 
I've emailed about before and know about the bad ideas with it.. But 
it's the customer :))


Here is the code I am working with:

?PHP
function number_pad($number,$n) {
return str_pad((int) $number,$n,0,STR_PAD_LEFT);
}

$SQL = SELECT * FROM Test WHERE `areacode` = '907' AND `prefix` = 
'200' LIMIT 5;


$result = mysql_query($SQL);

while ($num != 1) {
while($row = mysql_fetch_assoc($result)) {
$padnum = number_pad($num, 4);
echo $row['areacode'] . - . $row['prefix'] . - . 
$padnum . BR;

$num++;
}


}

?


Try to avoid putting a database query in a loop. In the query only 
ask for the fields you are going to use, it's faster. Why use your 
own function to pad a string, when there is a built-in function?


Try this code (untested):
?php
$nums = range(0,);
$q = SELECT areacode, prefix FROM Test WHERE `areacode` = '907' AND 
`prefix` = '200' LIMIT 5;

$rs = mysql_query($q);
while ($row = mysql_fetch_assoc($rs)) {
foreach ($nums as $n) {
echo 
sprintf('%03d-%03d-%04d',$row['areacode'],$row['prefix'],$n) br\n;

}
}
?

Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating

2011-08-10 Thread Ken Robinson

At 12:03 AM 8/11/2011, Chris Stinemetz wrote:

Is it possible to concatenate a string and an element from a
mysql_fetch_assoc array? I haven't had much luck searching google.

Such as concatenating results with ' . $posts_row['store_tptest'] .
' so that if there are no elements returned nothing will be displayed?


Sure, do something like this:

?php
  echo ($posts_row['store_tptest'] != '')?results 
{$posts_row['stor_tptest']}:'';

?

Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Serveside Printing w/ PHP

2011-07-12 Thread Ken Robinson

At 02:06 PM 7/12/2011, Marc Guay wrote:

Bonus feature:  The server is running Windows 7.  I suspect the
crickets are going to win this one.


Take a look at http://www.php.net/printer -- this might be what 
you're looking for.


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session variable problem

2011-03-25 Thread Ken Robinson

At 01:09 PM 3/25/2011, markb wrote:

Very rusty with PHP.
We moved our web site to a new hosting service (godaddy).  PHP 
changed from 4x to 5.2.17.

I can no longer change $_SESSION variables after the first use.
First call to form - start session create variables
Second call - can read variables, change existing ones (but they do 
not persist to next call) - cannot create new variable without an error


What's the error you're getting?

Also, do you have a call to session_start() at the beginning of each 
script before any output is sent to the browser?


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] looking for a newsgroup for JS

2011-03-23 Thread Ken Robinson

At 04:20 PM 3/23/2011, Jim Giner wrote:

Anyone know of a working Javascript newsgroup?  I googled and tried adding
several to my OE newsgroups but couldn't find the servers.


I frequent an on-line PHP forum at phpfreaks.com. There is a 
Javascript section there that seems to be quite active: 
http://www.phpfreaks.com/forums/index.php?board=6.0


Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: left

2005-04-06 Thread Ken Robinson

Marco J.L wrote:
 Hello,

 how can I change the lenght of an value in basuc it's called LEFT or
RIGHT
 and MID . I read the filenames but I want to strip the extension from
the
 filename.

  SCRIPT ==
 table style=font-family: tahoma,helvetica,arial; font-size: 12px;
 font-weight: bold; color: #00
 ?php
 $handle=opendir('news');
 while (false!==($file = readdir($handle))) {
 if ($file != .  $file != ..) {
 echo \nTRTD$file\n;
 }
 }
 closedir($handle);
 ?

/body
 /html
 ===RESULT 
   20050329.txt
   20050330.txt
   20050331.txt
   20050401.txt

 ===But I want this result : ==
   20050329
   20050330
   20050331
   20050401

 ===

I'm not sure what your Subject line or the first part of your
question has to do with the second part, but you should take a look at
the substr() function http://www.php.net/substr and the pathinfo()
function http://www.php.net/pathinfo.

Combining those should give you what you're looking for.

Ken

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php