Re: [PHP] PHP Database Problems -- Code Snippets

2012-05-05 Thread Matijn Woudt
On Thu, May 3, 2012 at 4:20 PM, Ethan Rosenberg eth...@earthlink.net wrote:
 At 06:47 PM 5/2/2012, Matijn Woudt wrote:

 On Wed, May 2, 2012 at 11:43 PM, Ethan Rosenberg eth...@earthlink.net
 wrote:  Dear list -   Sorry for the attachment. Â Here are code snippets
 --- Ethan, I don't want to sound rude, but it appears to me you don't have
 any understanding of what you're doing. It might help if you understand what
 the code is doing... Let me explain.   GET THE DATA FROM INTAKE3:   Â  Â
 function handle_data()  Â  Â {  Â  Â  Â  global $cxn;  Â  Â  Â  $query =
 select * from Intake3 where  1;   Â  Â
  if(isset($_Request['Sex']) trim($_POST['Sex']) != '' ) $_Request does not
 exists, you're looking for $_REQUEST. And why are you mixing $_REQUEST and
 $_POST here?  Â  Â  Â  {  Â  Â  Â  Â  Â  Â if ($_REQUEST['Sex'] === 0) 
 Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â  Â  Â  $sex = 'Male';  Â  Â  Â  Â  Â  Â
 }  Â  Â  Â  Â  Â  Â else  Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â  Â  Â  $sex =
 'Female';  Â  Â  Â  Â  Â  Â }  Â  Â  Â  }   Â  Â } What is the point of
 the handle_data function above? It doesn't do anything.  Â  Â
 $allowed_fields = array  Â  Â  Â  ( Â 'Site' =$_POST['Site'], 'MedRec' =
 $_POST['MedRec'], 'Fname' =  $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
  Â  Â  Â  Â  Â  Â  'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex'] Â ,
 'Height'  = $_POST['Height'] Â );   Â  Â if(empty($allowed_fields))  Â
  Â {  Â  Â  Â  Â  Â echo ouch;  Â  Â }   Â  Â $query = select * from
 Intake3  where  1 ;     Â foreach ( $allowed_fields as $key = $val )
  Â  Â {  Â  Â  Â  if ( (($val != '')) )   Â  Â {  Â  Â  Â  $query .= 
 AND ($key  = '$val') ;    Â }    Â  Â  $result1 = mysqli_query($cxn,
 $query);  Â  Â } First, this will allow SQL injections, because you insert
 the values directly from the browser. Second, you should move the last line
 ($result1=...), outside of the foreach loop, now you're executing the query
 multiple times. Third, you should check if $result1 === FALSE, in case the
 query fails   Â  Â $num = mysqli_num_rows($result1);  Â  Â if(($num =
 mysqli_num_rows($result1)) == 0) Doing the same thing twice?  Â  Â {  ? 
 Â  Â br /br /centerbp style=color: red; font-size:14pt; No
 Records  Retrieved #1/center/b/style/p  ?php  Â  Â exit();  Â
  Â }   DISPLAY THE INPUT3 DATA:   THIS SEEMS TO BE THE ROUTINE THAT
 IS FAILINGÂ  Â centerbSearch Results/b/centerbr /   Â
  Â centertable border=4 cellpadding=5 cellspacing=55 Â rules=all
  Â frame=box  Â  Â tr class=\heading\  Â  Â thSite/th  Â  Â
 thMedical Record/th  Â  Â thFirst Name/th  Â  Â thLast Name/th
  Â  Â thPhone/td  Â  Â thHeight/td  Â  Â thSex/td  Â  Â
 thHistory/td  Â  Â /tr   ?php   Â  Â  Â  while ($row1 =
 mysqli_fetch_array($result1, MYSQLI_BOTH))  Â  Â  Â  {  Â  Â  Â  Â  Â  Â
 print_r($_POST); Doesn't really make sense to print $_POST here..  Â  Â  Â
  Â  Â  Â  Â  global $MDRcheck;  Â  Â  Â  Â  Â  Â  Â  $n1++;  Â  Â  Â  Â  Â
  Â  Â  echo br /n1 br /;echo $n1;  Â  Â  Â  Â  Â  Â {  Â  Â  Â  Â  Â
  Â  Â  if (($n1  2)  ($MDRcheck == $row1[1]))  Â  Â  Â  Â  Â  Â  Â  { 
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 2== Â ;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo $MDRcheck;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[0] /td\n;
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[1] /td\n;  Â  Â  Â  Â  Â
  Â  Â  Â  Â  Â echo td $row1[2] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo td $row1[3] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[4] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[5]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[6] /td\n;  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[7] /td\n;  Â  Â  Â  Â  Â  Â
  Â  Â  Â  Â echo /tr\n;  Â  Â  Â  Â  Â  Â  Â  }  Â  Â  Â  Â  Â  Â  Â
  elseif (($n1  2)  ($MDRcheck != $row1[1]))  Â  Â  Â  Â  Â  Â  Â  {  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 2!= Â ;   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo $MDRcheck;Â  Â  Â  Â  Â  Â  Â  Â  Â  Â continue; continue
 doesn't do anything here.  Â  Â  Â  Â  Â  Â  Â  }  Â  Â  Â  Â  Â  Â  Â
  elseif ($n1 == 2)  Â  Â  Â  Â  Â  Â  Â  {   Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 define( MDR , Â $row1[1]);  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo br /row1
 br;echo $row1[1];  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo tr\n;   Â  Â
  Â  Â  Â  Â  Â  Â  Â  Â $_GLOBALS['mdr']= $row1[1];  Â  Â  Â  Â  Â  Â  Â  Â
  Â  Â $_POST['MedRec'] = $row1[1]; You're not supposed to set variables in
 $_POST...  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â $MDRold = $_GLOBALS['mdr']; It
 appears you want the old value of mdr, if so, then you should do this before
 you set it again 2 lines above..  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[0] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[1]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[2] /td\n;  Â
  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[3] /td\n;  Â  Â  Â  Â  Â  Â
  Â  Â  Â  Â echo td $row1[4] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
 echo td $row1[5] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td
 $row1[6] /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo td $row1[7]
 /td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  

[PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Ethan Rosenberg
I am sending this again to see if more ideas for solution of this 
problem are available.


Ethan
===
Dear list -

Sorry for the attachment.  Here are code snippets ---

GET THE DATA FROM INTAKE3:

function handle_data()
{
   global $cxn;
   $query = select * from Intake3 where  1;



   if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )
   {
if ($_REQUEST['Sex'] === 0)
{
   $sex = 'Male';
}
else
{
   $sex = 'Female';
}
   }

}

$allowed_fields = array
   (  'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 
'Fname' = $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
 'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex']  , 
'Height' = $_POST['Height']  );


if(empty($allowed_fields))
{
  echo ouch;
}

$query = select * from Intake3  where  1 ;

foreach ( $allowed_fields as $key = $val )
{
   if ( (($val != '')) )

{
   $query .=  AND ($key  = '$val') ;
}
   $result1 = mysqli_query($cxn, $query);
}

$num = mysqli_num_rows($result1);
if(($num = mysqli_num_rows($result1)) == 0)
{
?
br /br /centerbp style=color: red; 
font-size:14pt; No Records Retrieved #1/center/b/style/p

?php
exit();
}

DISPLAY THE INPUT3 DATA:

 THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 

centerbSearch Results/b/centerbr /

centertable border=4 cellpadding=5 
cellspacing=55  rules=all  frame=box

tr class=\heading\
thSite/th
thMedical Record/th
thFirst Name/th
thLast Name/th
thPhone/td
thHeight/td
thSex/td
thHistory/td
/tr

?php

   while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
   {
print_r($_POST);
   global $MDRcheck;
   $n1++;
   echo br /n1 br /;echo $n1;
{
   if (($n1  2)  ($MDRcheck == $row1[1]))
   {
echo 2==  ;
echo $MDRcheck;
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }
   elseif (($n1  2)  ($MDRcheck != $row1[1]))
   {
echo 2!=  ;

echo $MDRcheck;


continue;
   }
   elseif ($n1 == 2)
   {

define( MDR ,  $row1[1]);
echo br /row1 br;echo $row1[1];
echo tr\n;

$_GLOBALS['mdr']= $row1[1];
$_POST['MedRec'] = $row1[1];
$MDRold = $_GLOBALS['mdr'];
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }

}
   }

?

SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

?php
$query2 = select * from Visit3 where  1 AND (Site = 'AA')  AND 
(MedRec = $_GLOBALS[mdr]);

$result2 = mysqli_query($cxn, $query2);
$num = mysqli_num_rows($result2);


global $finished;
$finished = 0;


while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
{
   global $finished;
   echo tr\n;
   echo td $row2[0] /td\n;
   echo td $row2[1] /td\n;
   echo td $row2[2] /td\n;
   echo td $row2[3] /td\n;
   echo td $row2[4] /td\n;
   echo td $row2[5] /td\n;
   echo td $row2[6] /td\n;
   echo /tr\n;

}

echo /table;

ENTER MORE DATA:

function More_Data()
{
   $decision = 5;
?

Do you Wish to Enter More Data?
form method=post action=
centerinput type=radio name=decision value=1 /Yes 
input type=radio name=decision value=0 /No/centerbr /

centerinput type=submit value=Enter more Data //center
input type=hidden name=next_step value=step10 /
 /form

?php
} //end function More_Data



switch ( @$_POST[next_step] )
{

   case step10:
   {
if (!isset($_POST['decision']))
{
   $_POST['decision'] = 5;
}

if ($_POST['decision'] == 0)
{
   exit();
}
if ($_POST['decision'] == 1)
{
 ;
   echo form method=\post\ action=\\;
echo input type=\hidden\ name=\next_step\ 
value=\step4\ /;

echo enterbr /;
echo Medical Record: nbspinput 

Re: [PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Jim Giner
I don't think posting the same voluminous code is going to generate any 
better responses.

The suggestion to start over and make your insert/retrieve queries fool 
proof before starting to write some logic into your code was a very good 
one.  Why don't you work on that so that any requests for help can focus on 
just that instead of the 100+ lines of code you are posting?  Reading some 
documentation on sql and some html/php relationships would be VERY 
beneficial to your long-term success as a programmer as well. 



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



Re: [PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Jim Giner
Nor will posting to multiple lists.(Sorry to the rest of you - didn't 
realize it until now.)

Jim Giner jim.gi...@albanyhandball.com wrote in message 
news:c6.f8.38082.efae3...@pb1.pair.com...
I don't think posting the same voluminous code is going to generate any 
better responses.

 The suggestion to start over and make your insert/retrieve queries fool 
 proof before starting to write some logic into your code was a very good 
 one.  Why don't you work on that so that any requests for help can focus 
 on just that instead of the 100+ lines of code you are posting?  Reading 
 some documentation on sql and some html/php relationships would be VERY 
 beneficial to your long-term success as a programmer as well.
 



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



Re: [PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Govinda
Ethan, 

before you get   frustrated or feel abandoned, let me *sincerely* try to help:

Here is honestly what I am utterly convinced you need to do to get any where in 
the medium/long run:

Break everything down into very small steps.  Making web apps is just building 
a whole lot of layers/collections of very small simple things.  Nothing is out 
of your grasp.. it only appears mysterious or complicated because you are not 
familiar with the terms/code structures and have not spent enough time with the 
little things to recognize them like english speakers do when reading written 
english.  So what you do to get out of the woods (and it works every time), 
regardless of the problem, is just focus on one small thing at a time.  

START OVER.  

Throw out all the code, especially everything you borrowed from other sources.  
Write everything yourself, from scratch.  Just print hello to a web page.  
Then add in the ability to do ONE more thing that you need... like reading from 
a db, or writing to a db...  and then processing/manipulating things, as you 
need.  Test everything every time you add even ONE little feature.  Then as 
soon as something breaks, you know instantly where the issue lays.. and focus 
on solving why that one little thing is broken.  If re-reading the docs about 
whatever code structures you used at that point (of your newly-added broken 
feature) does not clear it up for you, then post just that ONE little issue to 
this list.. asking why that one thing is behaving that way.  Like this (using 
this tedious but effective method) , you will get your code into shape so it 
works, you will not alienate yourself from the help you need (by posting 
volumes of broken code with no evidence that you are actually trying to learn), 
and best of all - you will, step by step, come to master all this stuff!

Everyone loves to help answer/clear up one little thing, but no one has time to 
digest a whole broken page/app and tell you where all the issues are.  Even if 
they did have the time and inclination, they would lose it after the very first 
time they saw you take what they gave you and come back 3 weeks later with 
evidence that you never learned anything from the last episode.  Believe me you 
will always have people climbing over each other to help you, if you can just 
break down your problems into such small portions that you will be able to 
realize you have the smarts to answer them yourself.  ;-)   

There is a very lively, effective and popular coders community (and Q/A tool 
set) here:
http://stackoverflow.com/

..where you get almost instant help to any coding question.. because there are 
so many people who really care to give quality help, because they get 
recognized for their contributions.  But  if you try to use the tools at 
stackoverflow.com then you will find there, in that very professional 
atmosphere, that (to get anywhere) you HAVE to ask questions that are distilled 
down to something very specific and answerable in a specific/factual kind of 
way, as opposed to question that bring up more fuzzy-boundaried topics, like 
questions of preference or style, or questions that show an utter lack of 
homework/effort on the part of the asker which require more than a couple 
specific facts to answer.

You can train here or on stackoverflow.com, but anywhere you go, you will find 
the same situation, that you have to use baby steps (as necessary) - for your 
own learning, and to get any decent help.

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



[PHP] RE: [PHP-DB] [PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Gavin Chalkley
Ethan,

You have been given advise and break down on your code.

Have you taken the advise given?

Which part of the code isn't working? Not which chunk, but break it down and
show which part

BR,

Gav

-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: 04 May 2012 15:10
To: php-db-lists.php.net; php-general@lists.php.net
Subject: [PHP-DB] [PHP] PHP  Database Problems -- Code Snippets - Any more
Ideas?

I am sending this again to see if more ideas for solution of this problem
are available.

Ethan
===
Dear list -

Sorry for the attachment.  Here are code snippets ---

GET THE DATA FROM INTAKE3:

 function handle_data()
 {
global $cxn;
$query = select * from Intake3 where  1;



if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )
{
 if ($_REQUEST['Sex'] === 0)
 {
$sex = 'Male';
 }
 else
 {
$sex = 'Female';
 }
}

 }

 $allowed_fields = array
(  'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 'Fname' =
$_POST['Fname'], 'Lname' = $_POST['Lname'] ,
  'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex']  ,
'Height' = $_POST['Height']  );

 if(empty($allowed_fields))
 {
   echo ouch;
 }

 $query = select * from Intake3  where  1 ;

 foreach ( $allowed_fields as $key = $val )
 {
if ( (($val != '')) )

 {
$query .=  AND ($key  = '$val') ;
 }
$result1 = mysqli_query($cxn, $query);
 }

 $num = mysqli_num_rows($result1);
 if(($num = mysqli_num_rows($result1)) == 0)
 {
?
 br /br /centerbp style=color: red; font-size:14pt; No
Records Retrieved #1/center/b/style/p ?php
 exit();
 }

DISPLAY THE INPUT3 DATA:

  THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 

 centerbSearch Results/b/centerbr /

 centertable border=4 cellpadding=5 
cellspacing=55  rules=all  frame=box
 tr class=\heading\
 thSite/th
 thMedical Record/th
 thFirst Name/th
 thLast Name/th
 thPhone/td
 thHeight/td
 thSex/td
 thHistory/td
 /tr

?php

while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
{
 print_r($_POST);
global $MDRcheck;
$n1++;
echo br /n1 br /;echo $n1;
 {
if (($n1  2)  ($MDRcheck == $row1[1]))
{
 echo 2==  ;
 echo $MDRcheck;
 echo td $row1[0] /td\n;
 echo td $row1[1] /td\n;
 echo td $row1[2] /td\n;
 echo td $row1[3] /td\n;
 echo td $row1[4] /td\n;
 echo td $row1[5] /td\n;
 echo td $row1[6] /td\n;
 echo td $row1[7] /td\n;
 echo /tr\n;
}
elseif (($n1  2)  ($MDRcheck != $row1[1]))
{
 echo 2!=  ;

 echo $MDRcheck;


 continue;
}
elseif ($n1 == 2)
{

 define( MDR ,  $row1[1]);
 echo br /row1 br;echo $row1[1];
 echo tr\n;

 $_GLOBALS['mdr']= $row1[1];
 $_POST['MedRec'] = $row1[1];
 $MDRold = $_GLOBALS['mdr'];
 echo td $row1[0] /td\n;
 echo td $row1[1] /td\n;
 echo td $row1[2] /td\n;
 echo td $row1[3] /td\n;
 echo td $row1[4] /td\n;
 echo td $row1[5] /td\n;
 echo td $row1[6] /td\n;
 echo td $row1[7] /td\n;
 echo /tr\n;
}

 }
}

?

SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

?php
 $query2 = select * from Visit3 where  1 AND (Site = 'AA')  AND (MedRec
= $_GLOBALS[mdr]);
 $result2 = mysqli_query($cxn, $query2);
 $num = mysqli_num_rows($result2);


 global $finished;
 $finished = 0;


 while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
 {
global $finished;
echo tr\n;
echo td $row2[0] /td\n;
echo td $row2[1] /td\n;
echo td $row2[2] /td\n;
echo td $row2[3] /td\n;
echo td $row2[4] /td\n;
echo td $row2[5] /td\n;
echo td $row2[6] /td\n;
echo /tr\n;

 }

echo /table;

ENTER MORE DATA:

 function More_Data()
 {
$decision = 5;
?

 Do you Wish to Enter More Data?
 form method=post action=
 centerinput type=radio name=decision value=1 /Yes 
input type=radio name=decision value=0 /No/centerbr /
 centerinput type=submit value=Enter more Data //center
 input type=hidden name=next_step value=step10 /
  /form

?php
 } //end

Re: [PHP] PHP Database Problems -- Code Snippets - Any more Ideas?

2012-05-04 Thread Marco Behnke



Am 04.05.2012 16:09, schrieb Ethan Rosenberg:

function handle_data()
{
global $cxn;


What does this function? It neither takes any parameters nor returns any 
value. And it does not write back anything to its global $cxn. So it is 
quite useless and can be deleted.



$query = select * from Intake3 where 1;



if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )


there is no variable $_Request, it is $_REQUEST.
Why do you test on $_REQUEST and compare it with trimmed $_POST?


{
if ($_REQUEST['Sex'] === 0)
{
$sex = 'Male';
}
else
{
$sex = 'Female';
}


Why do you set a variable that is never used?


$allowed_fields = array
( 'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 'Fname' =
$_POST['Fname'], 'Lname' = $_POST['Lname'] ,
'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex'] , 'Height' =
$_POST['Height'] );
if(empty($allowed_fields))
{
echo ouch;
}
$query = select * from Intake3 where 1 ;
foreach ( $allowed_fields as $key = $val )
{
if ( (($val != '')) )
{
$query .=  AND ($key = '$val') ;


Why the hell do you put unverified data into an sql query?


DISPLAY THE INPUT3 DATA:

  THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 


What fails?
I do not have access to your database, so I can not run your code to see 
what fails.



?php

while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
{
print_r($_POST);
global $MDRcheck;
$n1++;
echo br /n1 br /;echo $n1;
{
if (($n1  2)  ($MDRcheck == $row1[1]))


What is $MDRcheck and what does this comparision mean?


SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

?php
$query2 = select * from Visit3 where 1 AND (Site = 'AA') AND (MedRec =
$_GLOBALS[mdr]);


Quotes around mdr missing


$result2 = mysqli_query($cxn, $query2);
$num = mysqli_num_rows($result2);


global $finished;
$finished = 0;


while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
{
global $finished;


No need to global that twice.
And why ndo you use global and $_GLOBALS? STick to one or better skip it 
anyways. Globals are not to be used!



switch ( @$_POST[next_step] )


Remove all @ from your code or you won't see any errors on this.
Do proper checking and do NOT suppress errors or warnings.


echo form method=\post\ action=\\;
echo input type=\hidden\ name=\next_step\ value=\step4\ /;
echo enterbr /;
echo Medical Record: nbspinput type=\text\ name=\MedRec\ value=\
$_GLOBALS[mdr]\ /;


Quotes.


$Weight = $_POST['Weight'];
$Notes = $_POST['Notes'];
$sql2 = INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI,
Date) VALUES(null, '$Site', '$MDRold', '$Notes',


Do NOT NEVER put data that is user input unchecked into a query.


?

?


Double closing tag?


echo td $_GLOBALS[mdr] /td\n;


Quotes.


$flag = 1;


What's this?

You really really should seperate your code from HTML.
Please truncate your apache and php error log.
Add

error_reporting(E_ALL);
ini_set('display_errors', 'On');

at the top of every php file right after ?php onto a new line.
Remove all @ from your lines and execute your script another time and 
see what errors are appear into your browser and your logfiles. Post 
them and the codelines for these errors on the list.


--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz



smime.p7s
Description: S/MIME Kryptografische Unterschrift


Re: [PHP] PHP Database Problems -- Code Snippets

2012-05-03 Thread Ethan Rosenberg

At 06:47 PM 5/2/2012, Matijn Woudt wrote:
On Wed, May 2, 2012 at 11:43 PM, Ethan Rosenberg 
eth...@earthlink.net wrote:  Dear list -   
Sorry for the attachment. Â Here are code 
snippets --- Ethan, I don't want to sound rude, 
but it appears to me you don't have any 
understanding of what you're doing. It might 
help if you understand what the code is doing... 
Let me explain.   GET THE DATA FROM 
INTAKE3:   Â  Â function handle_data()  Â  Â 
{  Â  Â  Â  global $cxn;  Â  Â  Â  $query = 
select * from Intake3 where  1; 
      if(isset($_Request['Sex']) 
trim($_POST['Sex']) != '' ) $_Request does not 
exists, you're looking for $_REQUEST. And why 
are you mixing $_REQUEST and $_POST here?  
      {             if 
($_REQUEST['Sex'] === 0)  Â  Â  Â  Â  Â  Â 
{  Â  Â  Â  Â  Â  Â  Â  $sex = 'Male';  
           }             else  
           {                $sex = 
'Female';  Â  Â  Â  Â  Â  Â }  Â  Â  Â  }   
   } What is the point of the handle_data 
function above? It doesn't do anything.  Â  Â 
$allowed_fields = array  Â  Â  Â  ( Â 'Site' 
=$_POST['Site'], 'MedRec' = $_POST['MedRec'], 
'Fname' =  $_POST['Fname'], 'Lname' = 
$_POST['Lname'] ,  Â  Â  Â  Â  Â  Â  'Phone' = 
$_POST['Phone'] , 'Sex' = $_POST['Sex'] Â , 
'Height'  = $_POST['Height'] Â );   Â  Â 
if(empty($allowed_fields))  Â  Â {  
         echo ouch;     }      
$query = select * from Intake3  where  1 
;   Â  Â foreach ( $allowed_fields as $key = 
$val )  Â  Â {  Â  Â  Â  if ( (($val != '')) 
)      {        $query .=  AND ($key  
= '$val') ;  Â  Â }  Â  Â  Â  $result1 = 
mysqli_query($cxn, $query);  Â  Â } First, this 
will allow SQL injections, because you insert 
the values directly from the browser. Second, 
you should move the last line ($result1=...), 
outside of the foreach loop, now you're 
executing the query multiple times. Third, you 
should check if $result1 === FALSE, in case the 
query fails   Â  Â $num = 
mysqli_num_rows($result1);  Â  Â if(($num = 
mysqli_num_rows($result1)) == 0) Doing the same 
thing twice?  Â  Â {  ?  Â  Â br /br 
/centerbp style=color: red; 
font-size:14pt; No Records  Retrieved 
#1/center/b/style/p  ?php  Â  Â 
exit();  Â  Â }   DISPLAY THE INPUT3 
DATA:   THIS SEEMS TO BE THE ROUTINE THAT 
IS FAILINGÂ  Â centerbSearch 
Results/b/centerbr /   Â  Â 
centertable border=4 cellpadding=5 
cellspacing=55 Â rules=all  Â 
frame=box  Â  Â tr class=\heading\  
   thSite/th     thMedical 
Record/th  Â  Â thFirst Name/th  Â  Â 
thLast Name/th  Â  Â thPhone/td  Â  Â 
thHeight/td  Â  Â thSex/td  Â  Â 
thHistory/td  Â  Â /tr   ?php   
      while ($row1 = 
mysqli_fetch_array($result1, MYSQLI_BOTH))  
      {             print_r($_POST); 
Doesn't really make sense to print $_POST 
here..  Â  Â  Â  Â  Â  Â  Â  global 
$MDRcheck;  Â  Â  Â  Â  Â  Â  Â  $n1++;  
              echo br /n1 br /;echo 
$n1;  Â  Â  Â  Â  Â  Â {  
              if (($n1  2)  ($MDRcheck 
== $row1[1]))  Â  Â  Â  Â  Â  Â  Â  {  
                   echo 2==  ;  
                   echo $MDRcheck;  
                   echo td $row1[0] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[1] /td\n;  
                   echo td $row1[2] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[3] /td\n;  
                   echo td $row1[4] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[5] /td\n;  
                   echo td $row1[6] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[7] /td\n;  
                   echo /tr\n;  
              }  
              elseif (($n1  2)  
($MDRcheck != $row1[1]))  
              {  
                   echo 2!=  ;   
                   echo 
$MDRcheck;Â  Â  Â  Â  Â  Â  Â  Â  Â  Â 
continue; continue doesn't do anything here.  
              }  
              elseif ($n1 == 2)  
              {   
                   define( MDR ,  
$row1[1]);  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
br /row1 br;echo $row1[1];  
                   echo tr\n;   
                   $_GLOBALS['mdr']= 
$row1[1];  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â 
$_POST['MedRec'] = $row1[1]; You're not supposed 
to set variables in $_POST...  
                   $MDRold = 
$_GLOBALS['mdr']; It appears you want the old 
value of mdr, if so, then you should do this 
before you set it again 2 lines above..  
                   echo td $row1[0] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[1] /td\n;  
                   echo td $row1[2] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[3] /td\n;  
                   echo td $row1[4] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[5] /td\n;  
                   echo td $row1[6] 
/td\n;  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â echo 
td $row1[7] /td\n;  
                   echo /tr\n;  
      

[PHP] PHP Database Problems -- Code Snippets

2012-05-02 Thread Ethan Rosenberg

Dear list -

Sorry for the attachment.  Here are code snippets ---

GET THE DATA FROM INTAKE3:

function handle_data()
{
   global $cxn;
   $query = select * from Intake3 where  1;



   if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )
   {
if ($_REQUEST['Sex'] === 0)
{
   $sex = 'Male';
}
else
{
   $sex = 'Female';
}
   }

}

$allowed_fields = array
   (  'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 
'Fname' = $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
 'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex']  , 
'Height' = $_POST['Height']  );


if(empty($allowed_fields))
{
  echo ouch;
}

$query = select * from Intake3  where  1 ;

foreach ( $allowed_fields as $key = $val )
{
   if ( (($val != '')) )

{
   $query .=  AND ($key  = '$val') ;
}
   $result1 = mysqli_query($cxn, $query);
}

$num = mysqli_num_rows($result1);
if(($num = mysqli_num_rows($result1)) == 0)
{
?
br /br /centerbp style=color: red; 
font-size:14pt; No Records Retrieved #1/center/b/style/p

?php
exit();
}

DISPLAY THE INPUT3 DATA:

 THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 

centerbSearch Results/b/centerbr /

centertable border=4 cellpadding=5 
cellspacing=55  rules=all  frame=box

tr class=\heading\
thSite/th
thMedical Record/th
thFirst Name/th
thLast Name/th
thPhone/td
thHeight/td
thSex/td
thHistory/td
/tr

?php

   while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
   {
print_r($_POST);
   global $MDRcheck;
   $n1++;
   echo br /n1 br /;echo $n1;
{
   if (($n1  2)  ($MDRcheck == $row1[1]))
   {
echo 2==  ;
echo $MDRcheck;
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }
   elseif (($n1  2)  ($MDRcheck != $row1[1]))
   {
echo 2!=  ;

echo $MDRcheck;


continue;
   }
   elseif ($n1 == 2)
   {

define( MDR ,  $row1[1]);
echo br /row1 br;echo $row1[1];
echo tr\n;

$_GLOBALS['mdr']= $row1[1];
$_POST['MedRec'] = $row1[1];
$MDRold = $_GLOBALS['mdr'];
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }

}
   }

?

SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

?php
$query2 = select * from Visit3 where  1 AND (Site = 'AA')  AND 
(MedRec = $_GLOBALS[mdr]);

$result2 = mysqli_query($cxn, $query2);
$num = mysqli_num_rows($result2);


global $finished;
$finished = 0;


while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
{
   global $finished;
   echo tr\n;
   echo td $row2[0] /td\n;
   echo td $row2[1] /td\n;
   echo td $row2[2] /td\n;
   echo td $row2[3] /td\n;
   echo td $row2[4] /td\n;
   echo td $row2[5] /td\n;
   echo td $row2[6] /td\n;
   echo /tr\n;

}

echo /table;

ENTER MORE DATA:

function More_Data()
{
   $decision = 5;
?

Do you Wish to Enter More Data?
form method=post action=
centerinput type=radio name=decision value=1 /Yes 
input type=radio name=decision value=0 /No/centerbr /

centerinput type=submit value=Enter more Data //center
input type=hidden name=next_step value=step10 /
 /form

?php
} //end function More_Data



switch ( @$_POST[next_step] )
{

   case step10:
   {
if (!isset($_POST['decision']))
{
   $_POST['decision'] = 5;
}

if ($_POST['decision'] == 0)
{
   exit();
}
if ($_POST['decision'] == 1)
{
 ;
   echo form method=\post\ action=\\;
echo input type=\hidden\ name=\next_step\ 
value=\step4\ /;

echo enterbr /;
echo Medical Record: nbspinput type=\text\ 
name=\MedRec\ value=\ $_GLOBALS[mdr]\ /;
echo nbspnbsp Weight: input type=\decimal\ 

Re: [PHP] PHP Database Problems -- Code Snippets

2012-05-02 Thread Matijn Woudt
On Wed, May 2, 2012 at 11:43 PM, Ethan Rosenberg eth...@earthlink.net wrote:
 Dear list -

 Sorry for the attachment.  Here are code snippets ---

Ethan,

I don't want to sound rude, but it appears to me you don't have any
understanding of what you're doing. It might help if you understand
what the code is doing... Let me explain.


 GET THE DATA FROM INTAKE3:

    function handle_data()
    {
       global $cxn;
       $query = select * from Intake3 where  1;



       if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )

$_Request does not exists, you're looking for $_REQUEST. And why are
you mixing $_REQUEST and $_POST here?

       {
            if ($_REQUEST['Sex'] === 0)
            {
               $sex = 'Male';
            }
            else
            {
               $sex = 'Female';
            }
       }

    }

What is the point of the handle_data function above? It doesn't do anything.

    $allowed_fields = array
       (  'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 'Fname' =
 $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
             'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex']  , 'Height'
 = $_POST['Height']  );

    if(empty($allowed_fields))
    {
          echo ouch;
    }

    $query = select * from Intake3  where  1 ;

    foreach ( $allowed_fields as $key = $val )
    {
       if ( (($val != '')) )

    {
       $query .=  AND ($key  = '$val') ;
    }
       $result1 = mysqli_query($cxn, $query);
    }

First, this will allow SQL injections, because you insert the values
directly from the browser.
Second, you should move the last line ($result1=...), outside of the
foreach loop, now you're executing the query multiple times.
Third, you should check if $result1 === FALSE, in case the query fails


    $num = mysqli_num_rows($result1);
    if(($num = mysqli_num_rows($result1)) == 0)

Doing the same thing twice?

    {
 ?
    br /br /centerbp style=color: red; font-size:14pt; No Records
 Retrieved #1/center/b/style/p
 ?php
    exit();
    }

 DISPLAY THE INPUT3 DATA:

 THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 

    centerbSearch Results/b/centerbr /

    centertable border=4 cellpadding=5 cellspacing=55  rules=all
  frame=box
    tr class=\heading\
    thSite/th
    thMedical Record/th
    thFirst Name/th
    thLast Name/th
    thPhone/td
    thHeight/td
    thSex/td
    thHistory/td
    /tr

 ?php

       while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
       {
            print_r($_POST);

Doesn't really make sense to print $_POST here..

               global $MDRcheck;
               $n1++;
               echo br /n1 br /;echo $n1;
            {
               if (($n1  2)  ($MDRcheck == $row1[1]))
               {
                    echo 2==  ;
                    echo $MDRcheck;
                    echo td $row1[0] /td\n;
                    echo td $row1[1] /td\n;
                    echo td $row1[2] /td\n;
                    echo td $row1[3] /td\n;
                    echo td $row1[4] /td\n;
                    echo td $row1[5] /td\n;
                    echo td $row1[6] /td\n;
                    echo td $row1[7] /td\n;
                    echo /tr\n;
               }
               elseif (($n1  2)  ($MDRcheck != $row1[1]))
               {
                    echo 2!=  ;

                    echo $MDRcheck;


                    continue;

continue doesn't do anything here.


               }
               elseif ($n1 == 2)
               {

                    define( MDR ,  $row1[1]);
                    echo br /row1 br;echo $row1[1];
                    echo tr\n;

                    $_GLOBALS['mdr']= $row1[1];
                    $_POST['MedRec'] = $row1[1];

You're not supposed to set variables in $_POST...

                    $MDRold = $_GLOBALS['mdr'];

It appears you want the old value of mdr, if so, then you should do
this before you set it again 2 lines above..

                    echo td $row1[0] /td\n;
                    echo td $row1[1] /td\n;
                    echo td $row1[2] /td\n;
                    echo td $row1[3] /td\n;
                    echo td $row1[4] /td\n;
                    echo td $row1[5] /td\n;
                    echo td $row1[6] /td\n;
                    echo td $row1[7] /td\n;
                    echo /tr\n;
               }

            }
       }

 ?

You say this routine is probably the one that is failing.. but what is
going wrong? And how the heck are we supposed to know what this
function should do?

 SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

 ?php
    $query2 = select * from Visit3 where  1 AND (Site = 'AA')  AND (MedRec =
 $_GLOBALS[mdr]);

You're using mdr as a constant here, this will generate a warning, but
sadly enough it works.

    $result2 = mysqli_query($cxn, $query2);

You should check if $result2 === FALSE, in case the query fails.

    $num = mysqli_num_rows($result2);

You're counting the rows here, but you don't do anything with the result?

 Snip the rest of this crappy 

Re: [PHP] PHP Database Problems -- Code Snippets

2012-05-02 Thread Duken Marga
It is a good habbit to write the core code just for inserting/retrieving
data from database. It will reduce much of your code complexity. When you
see your code is working, you can continue to embed it with your visual
front-end or with your filter.

On Thu, May 3, 2012 at 4:43 AM, Ethan Rosenberg eth...@earthlink.netwrote:

 Dear list -

 Sorry for the attachment.  Here are code snippets ---

 GET THE DATA FROM INTAKE3:

function handle_data()
{
   global $cxn;
   $query = select * from Intake3 where  1;



   if(isset($_Request['Sex']) trim($_POST['Sex']) != '' )
   {
if ($_REQUEST['Sex'] === 0)
{
   $sex = 'Male';
}
else
{
   $sex = 'Female';
}
   }

}

$allowed_fields = array
   (  'Site' =$_POST['Site'], 'MedRec' = $_POST['MedRec'], 'Fname' =
 $_POST['Fname'], 'Lname' = $_POST['Lname'] ,
 'Phone' = $_POST['Phone'] , 'Sex' = $_POST['Sex']  ,
 'Height' = $_POST['Height']  );

if(empty($allowed_fields))
{
  echo ouch;
}

$query = select * from Intake3  where  1 ;

foreach ( $allowed_fields as $key = $val )
{
   if ( (($val != '')) )

{
   $query .=  AND ($key  = '$val') ;
}
   $result1 = mysqli_query($cxn, $query);
}

$num = mysqli_num_rows($result1);
if(($num = mysqli_num_rows($result1)) == 0)
{
 ?
br /br /centerbp style=color: red; font-size:14pt; No
 Records Retrieved #1/center/b/style/p
 ?php
exit();
}

 DISPLAY THE INPUT3 DATA:

  THIS SEEMS TO BE THE ROUTINE THAT IS FAILING 

centerbSearch Results/b/centerbr /

centertable border=4 cellpadding=5 cellspacing=55  rules=all
  frame=box
tr class=\heading\
thSite/th
thMedical Record/th
thFirst Name/th
thLast Name/th
thPhone/td
thHeight/td
thSex/td
thHistory/td
/tr

 ?php

   while ($row1 = mysqli_fetch_array($result1, MYSQLI_BOTH))
   {
print_r($_POST);
   global $MDRcheck;
   $n1++;
   echo br /n1 br /;echo $n1;
{
   if (($n1  2)  ($MDRcheck == $row1[1]))
   {
echo 2==  ;
echo $MDRcheck;
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }
   elseif (($n1  2)  ($MDRcheck != $row1[1]))
   {
echo 2!=  ;

echo $MDRcheck;


continue;
   }
   elseif ($n1 == 2)
   {

define( MDR ,  $row1[1]);
echo br /row1 br;echo $row1[1];
echo tr\n;

$_GLOBALS['mdr']= $row1[1];
$_POST['MedRec'] = $row1[1];
$MDRold = $_GLOBALS['mdr'];
echo td $row1[0] /td\n;
echo td $row1[1] /td\n;
echo td $row1[2] /td\n;
echo td $row1[3] /td\n;
echo td $row1[4] /td\n;
echo td $row1[5] /td\n;
echo td $row1[6] /td\n;
echo td $row1[7] /td\n;
echo /tr\n;
   }

}
   }

 ?

 SELECT AND DISPLAY DATA FROM VISIT3 DATABASE

 ?php
$query2 = select * from Visit3 where  1 AND (Site = 'AA')  AND (MedRec
 = $_GLOBALS[mdr]);
$result2 = mysqli_query($cxn, $query2);
$num = mysqli_num_rows($result2);


global $finished;
$finished = 0;


while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH))
{
   global $finished;
   echo tr\n;
   echo td $row2[0] /td\n;
   echo td $row2[1] /td\n;
   echo td $row2[2] /td\n;
   echo td $row2[3] /td\n;
   echo td $row2[4] /td\n;
   echo td $row2[5] /td\n;
   echo td $row2[6] /td\n;
   echo /tr\n;

}

 echo /table;

 ENTER MORE DATA:

function More_Data()
{
   $decision = 5;
 ?

Do you Wish to Enter More Data?
form method=post action=
centerinput type=radio name=decision value=1 /Yes input
 type=radio name=decision value=0 /No/centerbr /
centerinput type=submit value=Enter more Data //center
input type=hidden name=next_step value=step10 /
 /form

 ?php
} //end function More_Data



switch ( @$_POST[next_step] )
{

   case step10:
   {
if (!isset($_POST['decision']))
{
   $_POST['decision'] = 5;
}

if ($_POST['decision'] == 0)
{
   exit();
}
if ($_POST['decision']