[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 

[PHP] RE: [PHP-DB] PHP Database Problems

2012-05-02 Thread Gavin Chalkley
Ethan,

Some coding you are using would be helpful (as far as i am aware attachments
are not support on the mailing list's)

Gav

-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: 02 May 2012 19:54
To: php-db-lists.php.net; php-general@lists.php.net
Subject: [PHP-DB] PHP  Database Problems

  have a database

mysql describe Intake3;
++-+--+-+-+---+
| Field  | Type| Null | Key | Default | Extra |
++-+--+-+-+---+
| Site   | varchar(6)  | NO   | PRI | |   |
| MedRec | int(6)  | NO   | PRI | NULL|   |
| Fname  | varchar(15) | YES  | | NULL|   |
| Lname  | varchar(30) | YES  | | NULL|   |
| Phone  | varchar(30) | YES  | | NULL|   |
| Height | int(4)  | YES  | | NULL|   |
| Sex| char(7) | YES  | | NULL|   |
| Hx | text| YES  | | NULL|   |
++-+--+-+-+---+
8 rows in set (0.00 sec)

mysql describe Visit3;
++--+--+-+-++
| Field  | Type | Null | Key | Default | Extra  |
++--+--+-+-++
| Indx   | int(4)   | NO   | PRI | NULL| auto_increment |
| Site   | varchar(6)   | YES  | | NULL||
| MedRec | int(6)   | YES  | | NULL||
| Notes  | text | YES  | | NULL||
| Weight | int(4)   | YES  | | NULL||
| BMI| decimal(3,1) | YES  | | NULL||
| Date   | date | YES  | | NULL||
++--+--+-+-++

and a program to enter and extract data.

I can easily extract data from the database. However, if I try to enter
data, it goes into the incorrect record.  Following are some screenshots.
The program is attached.  [pardon the comical names.  This is a test, and
any resemblance to true names is not intentional]

Let us say that I wish to deal with Medical Record 1:


This it data from Intake3:
Site Medical Record First Name Last Name Phone Height Sex History AA 1
David Dummy 845 365-1456 66 Male c/o obesity. Various treatments w/o success

This is data from Visit3:
Index Site Medical Record Notes Weight BMI Date
2322 AA 1 Second Visit. 170 27.4 2010-01-20
2326 AA 1 Third visit. Small progress, but pt is very happy. 165
26.6 2010-02-01


I then request to enter additional data:

Site Medical Record First Name Last Name Phone Height Sex History
AA 10003 Stupid Fool 325 563-4178 65 Male Has been convinced by his 
friends that he is obese. Normal BMI = 23.
Index Site Medical Record Notes Weight BMI Date

Notice that it is entered into record 10003

The data is First Try

Index Site Medical Record Notes Weight BMI Date
2590 AA 10003 First Try 189 31.4 02 May 2012

Help and advice, please.

Thanks.

Ethan



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