Re: [PHP] Re: Everything works...Unless they hit the back button...

2005-08-05 Thread Jack Jackson

Kristen G. Thorson wrote:
You said If the user makes changes, those changes get error checked but 
do not become part of the sql query.  Where in your code is it failing 
to become part of the query?  Put a check at each level and see where 
*exactly* it fails to get deep enough to become one with the query.  
Also, I'm confused.  I asked if the query was what you're expecting, and 
you answered yes, which implies the data becomes part of the query.


Thanks for this; yes I was confused before and thank you for the 
clarification.


Now I am confused by how to check the logic: I echo out the sql as it is 
built, and if I'm going forward in the questionnaire it shows clearly but



$qidlist_sql=DELETE FROM teresa WHERE q_id IN ( . 
(implode(,,$qidlist)) . );;

echo br /br /;
echo br /\$ cqidlist_sql: . $qidlist_sql . br /;

   $q_a_sql=INSERT INTO teresa (u_id, q_id, a_id )
VALUES  . (implode(,,$qanda)) . ;;

 mysql_query($qidlist_sql);

echo br /br /;
echo br /\$ q_a_sql: . $q_a_sql . br /;

  if($q_a_result = mysql_query($q_a_sql))
{
  unset($_SESSION['required_fields']);
  $cat = $_POST['cat']+1;
  include_once(QUESTIONS . 'q.inc');
}


 shows NOTHING if I hit the BACK button. I'm still not seeing where the 
logic error is which makes it so that when I hit the BACK button it 
loses the plot.


Sorry for my misunderstanding
JJ







kgt






Jack Jackson wrote:

I've tried playing with the $_SERVER['HTTP_REFERER'] and that's no 
good because it's all coming from the same page - index.php!!


What am I missing. . . ?


Jack Jackson wrote:


Hi Kristen, there's a misunderstanding:

Kristen G. Thorson wrote:

The code below isn't much help to debug.  Do some checking to figure 
out how far into your IF statement you're getting.  Is the query 
running?  





Yes it runs successfully

Is it the query you expect?  





Yes it is perfect, and provided this is a new session and we're going 
forward page by page, it properly deletes from and inserts to the db 
as expected


(Step #1 when inserting or creating dynamic

queries that aren't working: print them out to make sure they are 
what you think they are.)  Is the category being incremented?





Yes, absolutely

You say you can go back, but you can't go forward.  





Actually no. In a new session, I can start and go forward page by 
page to the end of the questionnaire, advancing each stage perfectly, 
storing all values exactly as I'd expect.


The trouble starts if, during the process, the user hits the BACK 
button. At that point, user can reload the last page of questions, 
displaying the answers they gave. If the user makes changes, those 
changes get error checked but do not become part of the sql query. 
Also, user can not move forwards any more. So it's as the subject 
says - everything works...until they hit the back button, from which 
point the whole thing goes gablooey.


Look at the page source, is the


form action what it should be?





Yes

  Look at the form hidden variables (if


any) are they what you expect?




No. $cat remains what it was BEFORE the user hit the BACK button. 
However the questions dispayed are from the $cat which is in fact $cat-1


??!!









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



[PHP] Everything works...Unless they hit the back button...

2005-08-03 Thread Jack Jackson

Hi all. This has been an interesting week.

Now the form works, and I am able to error check, if no errors look into 
user answer table and delete from that all q_ids matching the ones just 
picked, insert this page of question/answer info (q_id/a_id) into the 
user answer db, and if successful advance the category by 1 and get more 
questions. It works.


I must have a logic error though because for some reason even though I 
say to delete matching  q_ids and reinsert, then move on, if the user 
hits the back button, changes answers and hits submit again, the table 
does not update . .  . and the category does not increment. We get stuck 
on this page of questions/answers forever.


What DOES happen after BACK is that the answers they select get passed 
back to error check (eg if they select a select box to nothing, error 
checking reenters its value into $message) and those values get passed 
back to the display page (eg $_POST[$qname] == $aid) because the 
selected answers change. It's just the db call and category advance 
which get stuck.


Any help will be greatly appreciated - Here's the code:

?php
//Start the session
session_start();
//Error announcements
echo POST:BR /;
print_r($_POST);
echo br /br /;
echo required session:BR /;
var_dump($_SESSION['required_fields']);

echo br /\$ cat: . $cat . br /;
echo \$message: ;
var_dump($message);

//error_reporting(E_ALL);


/* A script to retrieve from database questions and answers,
 * create a multi-page HTML form, error check answers and
 * submit them to the database on a per-user basis.
 * August 2005
 */

//Some basic vars
 if (!isset($cat)) { $cat = 1; }
$error=0;
$SUCCESS=0;


if (!isset($message))
{
$message = array();
}

if (!isset($_SESSION['required_fields']))
{
$_SESSION['required_fields'] = array();
}

if(!sizeof($_POST))
{
include_once(QUESTIONS . 'q.inc');
}

 //error checking

 reset($_SESSION['required_fields']);
  foreach ($_SESSION['required_fields'] as $fieldname)
{
   if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
   {
$message[$fieldname]=1;
   }

 }//error check
  if (!empty($message))
  {   $cat=$_POST['cat'];
  include_once(QUESTIONS . 'q.inc');
  }

//No errors? Store what's been done so far

  if ( ($_POST['action'] == 'process')  (!sizeof($message) ) )
  {
  foreach($_POST as $key=$val)
   {
   //find key/val sets within posts which are both numeric
   if(is_numeric($key)  is_numeric($val))
   {
  $nkey=$key;
  //add keys to the qidlist
  $qidlist[] .= $key;
  //add these values ( q_id, a_id ) to sql statement
  $qanda[] .= ('1' , ' . $nkey . ' , ' . $val . 
');

   }
   //find key/val sets within sub-arrays of $_POST 
which are numeric

   if(is_array($val))
   {
   foreach ($val as $akey=$aval)
   {
   //add these values ( q_id, a_id ) to sql 
statement
   $qanda[] .= ('1' , ' . $key . ' , ' . 
$aval . ');

   var_dump($qanda);
   }
   }
   }


   $qidlist_sql=DELETE FROM $userAnswers WHERE q_id IN ( 
. (implode(,,$qidlist)) . );;


   $q_a_sql=INSERT INTO $userAnswers (u_id, q_id, a_id )
VALUES  . (implode(,,$qanda)) . ;;

 mysql_query($qidlist_sql);


  if($q_a_result = mysql_query($q_a_sql))
{
  unset($_SESSION['required_fields']);
  $cat = $_POST['cat']+1;
  include_once(QUESTIONS . 'q.inc');
}

else
{
echo bA fatal MySQL error occured/b.\n
br /Query:  . $q_a_sql . br /\nError: ( . 
mysql_error();

die;
}

  }
?

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



Re: [PHP] Re: Everything works...Unless they hit the back button...

2005-08-03 Thread Jack Jackson

Hi, mark,

snip
Mark Rees wrote:
 Do you want to allow people to go back and change things ?
 If so, write a suitable UPDATE statement
/snip

Thanks, but I think the update function should be built in  -- the sql 
checks whether the userAnswer table contains the q_id the user has just 
entered; if so, it deletes the row containing it and then the second 
query inserts the new values.


   $qidlist_sql=DELETE FROM teresa WHERE q_id IN ( . 
(implode(,,$qidlist)) . );


   $q_a_sql=INSERT INTO teresa (u_id, q_id, a_id )
VALUES  . (implode(,,$qanda)) . ;;


I think there's something wrong with the logic of how I'm handling 
$_POST info and passing it back and forth: here's why: if I close the 
browser and reopen it and  refill the same questions, the answer table 
shows the updated answers. there's something in the logic I am using 
about how I am advancing the $cat and managing the $_POST information. I 
think . But I cannot find it.


Anyone?


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



Re: [PHP] Re: Everything works...Unless they hit the back button...

2005-08-03 Thread Jack Jackson

Hi Kristen, there's a misunderstanding:

Kristen G. Thorson wrote:
The code below isn't much help to debug.  Do some checking to figure out 
how far into your IF statement you're getting.  Is the query running?  


Yes it runs successfully

Is it the query you expect?  


Yes it is perfect, and provided this is a new session and we're going 
forward page by page, it properly deletes from and inserts to the db as 
expected


(Step #1 when inserting or creating dynamic
queries that aren't working: print them out to make sure they are what 
you think they are.)  Is the category being incremented?


Yes, absolutely

You say you 
can go back, but you can't go forward.  


Actually no. In a new session, I can start and go forward page by page 
to the end of the questionnaire, advancing each stage perfectly, storing 
all values exactly as I'd expect.


The trouble starts if, during the process, the user hits the BACK 
button. At that point, user can reload the last page of questions, 
displaying the answers they gave. If the user makes changes, those 
changes get error checked but do not become part of the sql query. Also, 
user can not move forwards any more. So it's as the subject says - 
everything works...until they hit the back button, from which point the 
whole thing goes gablooey.


Look at the page source, is the

form action what it should be?


Yes

  Look at the form hidden variables (if

any) are they what you expect?
No. $cat remains what it was BEFORE the user hit the BACK button. 
However the questions dispayed are from the $cat which is in fact $cat-1


??!!

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



Re: [PHP] Re: Everything works...Unless they hit the back button...

2005-08-03 Thread Jack Jackson
I've tried playing with the $_SERVER['HTTP_REFERER'] and that's no good 
because it's all coming from the same page - index.php!!


What am I missing. . . ?


Jack Jackson wrote:

Hi Kristen, there's a misunderstanding:

Kristen G. Thorson wrote:

The code below isn't much help to debug.  Do some checking to figure 
out how far into your IF statement you're getting.  Is the query 
running?  



Yes it runs successfully

Is it the query you expect?  



Yes it is perfect, and provided this is a new session and we're going 
forward page by page, it properly deletes from and inserts to the db as 
expected


(Step #1 when inserting or creating dynamic

queries that aren't working: print them out to make sure they are what 
you think they are.)  Is the category being incremented?



Yes, absolutely

You say you can go back, but you can't go forward.  



Actually no. In a new session, I can start and go forward page by page 
to the end of the questionnaire, advancing each stage perfectly, storing 
all values exactly as I'd expect.


The trouble starts if, during the process, the user hits the BACK 
button. At that point, user can reload the last page of questions, 
displaying the answers they gave. If the user makes changes, those 
changes get error checked but do not become part of the sql query. Also, 
user can not move forwards any more. So it's as the subject says - 
everything works...until they hit the back button, from which point the 
whole thing goes gablooey.


Look at the page source, is the


form action what it should be?



Yes

  Look at the form hidden variables (if


any) are they what you expect?


No. $cat remains what it was BEFORE the user hit the BACK button. 
However the questions dispayed are from the $cat which is in fact $cat-1


??!!



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



[PHP] Forming an SQL query

2005-08-02 Thread Jack Jackson

Hi,
Thanks to everyone's help, that multipage monster of a form is now 
working properly (yay!).


One problem I have though is that I stick the answers as each page is 
completed into a table. If the user hits the back button, rather than 
adding a new row to the table I'd rather update it if it's there. That's 
fairly straightforward when it's 1:1 questions to answers:


  $q_a_sql='INSERT INTO $userAnswerTable
  ( q_id, a_id )
  VALUES ' . (implode(,,$qanda))
  . ' on duplicate key UPDATE a_id = VALUES(a_id);';

But when it's 1:n, such as with checkboxes, this neat little plan of 
mine is thwarted.


So if I change the userAnswerTable to three columns, u_id, q_id and 
a_id, is there a way I can do all the 1:1 and 1:n in the manner I wish?


TIA,
JJ

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



Re: [PHP] Forming an SQL query

2005-08-02 Thread Jack Jackson

Ah, I had left out the third column the first time! Thanks.

Now I can insert and not create dupes but for some reason it is not 
updating.



Here's the code:


  if ( ($_POST['action'] == 'process')  (!sizeof($message) ) )
  {
  foreach($_POST as $key=$val)
   {
   //find key/val sets within posts which are both numeric
   if(is_numeric($key)  is_numeric($val))
   {
  $nkey=$key;
  //add these values ( q_id, a_id ) to sql statement
  $qanda[] .= ('1' , ' . $nkey . ' , ' . $val . 
');

   }
   //find key/val sets within sub-arrays of $_POST 
which are numeric

   if(is_array($val))
   {
   foreach ($val as $akey=$aval)
   {
   //add these values ( q_id, a_id ) to sql 
statement
   $qanda[] .= ('1' , ' . $key . ' , ' . 
$aval . ');

   }
   }
   }

$q_a_sql=INSERT INTO . $userTable . (u_id, q_id, a_id )
  VALUES  . (implode(,,$qanda)) . on duplicate key 
UPDATE a_id = VALUES(a_id);;


  if($q_a_result = mysql_query($q_a_sql))
{
  unset($_SESSION['required_fields']);
  $cat = $_POST['cat']+1;
  include_once(QUESTIONS . 'q.inc');
}


?


Kristen G. Thorson wrote:
How is it your plan thwarted?  It looks fine to me, but maybe I'm 
missing something.  The only thing I can think is that you're not 
defining your table keys correctly to correctly use ON DUPLICATE KEY.  
Do you have a key defined for all three columns *together*?


mysql create table user_answers (u_id int(11) not null, q_id int(11) 
not null, a_id int(11) not null, unique( u_id, q_id, a_id ) );

Query OK 0 rows affected (0.22 sec)

mysql insert into user_answers (u_id,q_id,a_id) values 
(1,1,1),(1,1,2),(1,2,1),(1,1,1) on duplicate key update a_id=values(a_id);

Query OK, 5 rows affected (0.01 sec)
Records: 4  Duplicates: 1  Warnings: 0

mysqlselect * from user_answers;
+--+--+--+
| u_id | q_id | a_id |
+--+--+--+
|1 |1 |1 |
|1 |1 |2 |
|1 |1 |3 |
+--+--+--+
3 rows in set (0.00 sec)



So, three different answers for the same user  same question.  The one 
duplicate did not cause an error because of the ON DUPLICATE KEY.  This 
looks like it's what you're trying to do, so then what's your error?




kgt




Jack Jackson wrote:


Hi,
Thanks to everyone's help, that multipage monster of a form is now 
working properly (yay!).


One problem I have though is that I stick the answers as each page is 
completed into a table. If the user hits the back button, rather than 
adding a new row to the table I'd rather update it if it's there. 
That's fairly straightforward when it's 1:1 questions to answers:


  $q_a_sql='INSERT INTO $userAnswerTable
  ( q_id, a_id )
  VALUES ' . (implode(,,$qanda))
  . ' on duplicate key UPDATE a_id = VALUES(a_id);';

But when it's 1:n, such as with checkboxes, this neat little plan of 
mine is thwarted.


So if I change the userAnswerTable to three columns, u_id, q_id and 
a_id, is there a way I can do all the 1:1 and 1:n in the manner I wish?


TIA,
JJ







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



Re: [PHP] Re: error checking a null array

2005-08-01 Thread Jack Jackson


g.gill wrote:
From what I understand the simplest solution here would be to check to see 
if you have $_POST['cb'] in the first place.  That would indicate if 
checkbox was selected or not.  After, you have posted the form just do the 
following test.


$check_box_exits = ((isset($_POST['cb']))? true:false);



That helped, sonu, thank you. The problem now is that, how can I pass 
through $_POST the names of each specific checkbox, whether filled in or 
not, and then parse each to see if they have any answer? I need to do 
that or else I can only tell the ones which *have* been filled in but 
not those which have not.


Thanks

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



Re: [PHP] Re: error checking a null array

2005-08-01 Thread Jack Jackson


Jochem Maas wrote:
snip


wtf are you smoking Jack? every checkbox that was checked will exist in the
$_POST array set with the value you gave it (I alway set a chekcboxes 
value to 1
because the values mere existance in the submitted data indicates it's 
chevckbox
 was checked), if a checkbox does not exist in the $_POST array it 
wasn't checked!!!


Oh, how I wish I were smoking something :) !

imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value 
of '1',
upon submitting the form they are in, your script sees the following in 
the $_POST

array...

$_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1');

which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10'
now how hard is it to determine which we're not checked?



Well, for me, it is - because I don't know the names of the other check 
boxes which were not checked because they were dynamically created, and 
I don't have the knowledge sufficient to pass the NAMES of all 
checkboxes through to $_POST so that I can search through and see which 
have been answered and which ones not.





maybe I'm not seeing the problem but I get the impression that you are
over complicating things regarding checkbox.


As always this is hugely possible.


JJ

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



Re: [PHP] error checking woes

2005-08-01 Thread Jack Jackson



Kristen G. Thorson wrote:

Thanks for the  ==  !

But I had set $message global within the buld-checkbox function, so that 
part of it does work. . . .







Jack,

Read below:



Jack Jackson wrote:


Hi,
Now that the drop down is working properly (thanks!!), I am trying to 
validate, and having LOTS of trouble. After being ceaselessly derided 
last night on an irc channel for my dimwitedness, I am still not any 
closer.


The code which works is this:

function GetQuestionsDropdown($cat){
//first get all the questions

$sql = SELECT * FROM questions WHERE questions.q_cat=$cat AND 
questions.q_style=1;


$result = mysql_query($sql);
//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {
   //if the form has been submitted, and the question 
unanswered

//highlight this whole question and answer block in red.
if ($message[$row['q_name']] == 1){






How does this funtion have access to $message?  You need to a) make it 
global or b) pass it in.




echo div class='error';
}
   //Make a question set div wrapper
echo div class='q_set'\n;
//State the question
echo div class='question';
echo $row['q_text'] . /div;
echo \n\n;
echo  div class='answer';
echo \n;
   //Create the dropdown for the answers
echo '  select name=' . $row['q_name'] . '';
echo \n;
   //get all of the answers for THIS question
$ans_sql = select * from answers where answers.q_id= . 
$row['q_id'];

$ans_result = mysql_query($ans_sql);

echo option value=\\Select from this list/option\n;
while($ans_row = mysql_fetch_assoc($ans_result)) {
   //list the answers for THIS question
echo option ;
echo value=\ . $ans_row['a_id'] . \;

if  ($row['q_name'] == $ans_row['a_id']) {
echo  selected;
}

echo  . $ans_row['a_answer'] . /option;
echo \n;
}
echo '  /select' . \n . ' /div' . \n;
echo /div!--q_set--\n\n;
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo /div!--/error--;
}
}
}//function GetQuestionsDropdown


NOW I have to validate after it's submitted. I am trying to look and 
see, if $_POST[$row['q_name']] is empty then make message of the same 
name = 1, so if


   if(empty($_POST['partners'])) {
   $message['partners'] = '1'
}

Then when I restate the dropdown function, and it shows the questions 
again,  those error checking things I built in will

a) show a div class=error around questions with a message
b) pre-select the previously selected answers (because I have put 
in the thing in the dropdown which says


 if ($row['q_name'] == $ans_row['a_id']) { echo  selected;}


The validate code I was trying, the subject of such howling on IRC 
(and I know it doesn't work, but not why) was:


function ValidatePost($cat){
//first get the q_names
$sql = SELECT * FROM questions WHERE q_cat=$cat;
$result = mysql_query($sql);

//go through the question set
while($row = mysql_fetch_assoc($result)) {
  if(empty($_POST[$row['q_name']])){
  $message[$row['q_name']] == 1;






You want $message = 1 here.  = = is for comparison.

You're setting $message inside a function.  This means it doesn't exist 
outside this scope!




  }
}
}//function ValidatePost

Can anyone tell me what I am doing wrong?

Thanks!
JJ





Hope this helps you get somewhere,

kgt




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



Re: [PHP] returning info. from a form selection

2005-08-01 Thread Jack Jackson
It'd have to be in the form of a form and you'd need to add values to 
the options, wrap it inside form tags, specify a method like $_POST or 
$_GET, error check and then send.





Bruce Gilbert wrote:

can anyone give me an idea on how to return info. from a forl pulldown menu

eg:

select class=textbox 
name=loan_process
  option value= 
  selected=selectedPurchase/option
  option 
  value=Construct Home/option

  option
/select

and return that to an email address.


thanks





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



Re: [PHP] Re: error checking a null array

2005-08-01 Thread Jack Jackson

AAarg.


Okay, thanks to all of you I've decided that any field name I need to 
see will be sent to $_SESSION['required_fields'] and basta.


Then after the submit button is pressed, I am doing this:



reset($_SESSION['required_fields']);
  foreach ($_SESSION['required_fields'] as $fieldname)
{
   if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
{
$message[$fieldname]=1;
include_once(QUESTIONS . 'q.inc');
}
}//error check



And this is *almost* working: it seems to crap out after the first loop 
through the $_SESSION['required_field'] array.


The array says:

Array ( [required_fields] = Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 
[4] = 1 [5] = 2 [6] = 3 [7] = 4 [8] = 1 [9] = 2 [10] = 3 [11] = 
4 ) )


$_POST says:

Array ( [action] = [process]process [1] = [2] = 68 [3] = [4] = )

So you see, there's an answer specified for the value of question [2].

But $messages says only:

$message: array(1) { [1]=  int(1) }


Why is it dying after the first loop through?

Thanks in advance

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



Re: [PHP] Re: error checking a null array

2005-08-01 Thread Jack Jackson

I can only swear this to the entire list:

Before I come here for help, each time, I echo and var_dump and print_r 
until, yes, I need a doctor.


So by the time I come here, it's not laziness or lack of looking in the 
manual, it's head-swirling confusion infused with incompetence and a 
complete lack of programming experience at any time before April of this 
year which leads me to come back again and again with relatively foolish 
questions.



My problem before, for example: In my error check function, I placed the 
include file (to return to the form) *within* the foreach loop, and then 
I wondered why it only ran through once.


D'oh.



Jochem Maas wrote:

Jack Jackson wrote:


AAarg.


Okay, thanks to all of you I've decided that any field name I need to 
see will be sent to $_SESSION['required_fields'] and basta.


Then after the submit button is pressed, I am doing this:



reset($_SESSION['required_fields']);



reset is not required when using foreach. and given that you have probably
not looped that item


  foreach ($_SESSION['required_fields'] as $fieldname)
{
   if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
{
$message[$fieldname]=1;
include_once(QUESTIONS . 'q.inc');
}
}//error check




you may be getting into trouble because of php's typecasting - try using
fielnames that are strings that do not auto cast to integers (which can be
used as array keys for indexed arrays) e.g. cb1 instead of 1



And this is *almost* working: it seems to crap out after the first 
loop through the $_SESSION['required_field'] array.


The array says:

Array ( [required_fields] = Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 
4 [4] = 1 [5] = 2 [6] = 3 [7] = 4 [8] = 1 [9] = 2 [10] = 3 [11] 
= 4 ) )


$_POST says:

Array ( [action] = [process]process [1] = [2] = 68 [3] = [4] = )



that does not look like valid output from var_dump() neither does the 
output you

show for $_SESSION['required_field'].



So you see, there's an answer specified for the value of question [2].

But $messages says only:

$message: array(1) { [1]=  int(1) }


Why is it dying after the first loop through?



is it? (use print_r() or var_dump() inside the loop to see what is 
happening)


NOT SO SUBTLE HINT: USE echo, print_r() and var_dump() until either you 
fingers or
your eyes start to bleed ;-) if you still haven't figured it out by then 
it's

time to see a doctor -












Thanks in advance







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



Re: [PHP] error checking woes- SOLVED

2005-07-31 Thread Jack Jackson
I did the smart thing last night: nothing. I read some PHP books and 
then realized that the answer to my error checking was a lot less 
complex, once again, than I had initially suspected. I finally ended up 
with:



 //error checking
foreach($_POST as $qname=$value) {
if(empty($value)){
$message[$qname]=1;
}
}


I cannot believe what I started with and what I ended up with.

Thanks as usual for the help!!

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



[PHP] error checking a null array

2005-07-31 Thread Jack Jackson

hi,
I have checkboxes beging dynamically generated. to seperate tasks in 
error checking I have added he arrays not just to $_POST but to 
$_POST[cb]  so names (derived from question numbers) are for example:


$_POST[cb][7]

A dump of $_POST would therefore include something like

[cb]=  array(1) { [7]=  array(1) { [0]=  string(3) 124 } }

 So I did this:

//error checking for checkboxes 
foreach ($cb as $cbkey = $cbvalue)
   {
  foreach($cbvalue as $cbkey2=$cb_answers)
  {
 if( !array_key_exists($_POST[$cbkey], $cb));
 {
 $message[$cbkey]=1;
 }
   }
   }

This almost works. The problem is that if someone doesn't check a 
checkbox, NOTHING related to the checkbox gets sent to $_POST; if I 
insert a hidden value of something, then that hidden value gets passed 
whether the user inputs something or not, since I need an entirely 
server-side solution. Is there a way to send something to tell the error 
checker whether for example $_POST[cb][7] is empty or null, so I can set 
the error message to one if it's empty?


Dump of $_POST with no checkboxes checked
$_POST:
array(4) { [action]= string(7) process [cat]= string(1) 2 
[rs]= array(3) { [5]= string(0)  [6]= string(0)  [9]= 
string(0)  } [b]= string(8) Continue }


Dump of $_POST with checkboxes checked

array(5) { [action]=  string(7) process [cat]=  string(1) 2 
[cb]=  array(2) { [7]=  array(5) { [0]=  string(1) 3 [1]= 
string(3) 124 [2]=  string(3) 125 [3]=  string(3) 127 [4]= 
string(3) 131 } [8]=  array(3) { [0]=  string(3) 141 [1]= 
string(3) 145 [2]=  string(1) 4 } } [rs]=  array(3) { [5]= 
string(0)  [6]=  string(0)  [9]=  string(0)  } [b]= 
string(8) Continue }



Thanks so much In advance

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



Re: [PHP] Re: error checking a null array

2005-07-31 Thread Jack Jackson



David Robley wrote:

Jack Jackson wrote:



hi,
I have checkboxes beging dynamically generated. to seperate tasks in
error checking I have added he arrays not just to $_POST but to
$_POST[cb]  so names (derived from question numbers) are for example:

$_POST[cb][7]

A dump of $_POST would therefore include something like

[cb]=  array(1) { [7]=  array(1) { [0]=  string(3) 124 } }

 So I did this:

//error checking for checkboxes
foreach ($cb as $cbkey = $cbvalue)
   {
  foreach($cbvalue as $cbkey2=$cb_answers)
  {
 if( !array_key_exists($_POST[$cbkey], $cb));
 {
 $message[$cbkey]=1;
 }
   }
   }

This almost works. The problem is that if someone doesn't check a
checkbox, NOTHING related to the checkbox gets sent to $_POST; if I
insert a hidden value of something, then that hidden value gets passed
whether the user inputs something or not, since I need an entirely
server-side solution. Is there a way to send something to tell the error
checker whether for example $_POST[cb][7] is empty or null, so I can set
the error message to one if it's empty?



I think you might find empty() and isset() fairly useful here.



Cheers


I would have thought so too, but empty doesn't seem to work if it's not 
there at all, (I guess it figures, how can it be empty if it isn't 
there) and isset doesn't work if the array is there but null. or 
something like that. IN any case I've yet to get them working using 
either. I probably should have said that!


Thanks in advance

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



[PHP] error checking woes

2005-07-30 Thread Jack Jackson

Hi,
Now that the drop down is working properly (thanks!!), I am trying to 
validate, and having LOTS of trouble. After being ceaselessly derided 
last night on an irc channel for my dimwitedness, I am still not any closer.


The code which works is this:

function GetQuestionsDropdown($cat){
//first get all the questions

$sql = SELECT * FROM questions WHERE questions.q_cat=$cat AND 
questions.q_style=1;


$result = mysql_query($sql);
//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {

//if the form has been submitted, and the question unanswered
//highlight this whole question and answer block in red.
if ($message[$row['q_name']] == 1){
echo div class='error';
}

//Make a question set div wrapper
echo div class='q_set'\n;
//State the question
echo div class='question';
echo $row['q_text'] . /div;
echo \n\n;
echo  div class='answer';
echo \n;

//Create the dropdown for the answers
echo '  select name=' . $row['q_name'] . '';
echo \n;

//get all of the answers for THIS question
$ans_sql = select * from answers where answers.q_id= . $row['q_id'];
$ans_result = mysql_query($ans_sql);

echo option value=\\Select from this list/option\n;
while($ans_row = mysql_fetch_assoc($ans_result)) {

//list the answers for THIS question
echo option ;
echo value=\ . $ans_row['a_id'] . \;

if  ($row['q_name'] == $ans_row['a_id']) {
echo  selected;
}

echo  . $ans_row['a_answer'] . /option;
echo \n;
}
echo '  /select' . \n . ' /div' . \n;
echo /div!--q_set--\n\n;
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo /div!--/error--;
}
}
}//function GetQuestionsDropdown


NOW I have to validate after it's submitted. I am trying to look and 
see, if $_POST[$row['q_name']] is empty then make message of the same 
name = 1, so if


   if(empty($_POST['partners'])) {
   $message['partners'] = '1'
}

Then when I restate the dropdown function, and it shows the questions 
again,  those error checking things I built in will

a) show a div class=error around questions with a message
	b) pre-select the previously selected answers (because I have put in 
the thing in the dropdown which says


 if ($row['q_name'] == $ans_row['a_id']) { echo  selected;}


The validate code I was trying, the subject of such howling on IRC (and 
I know it doesn't work, but not why) was:


function ValidatePost($cat){
//first get the q_names
$sql = SELECT * FROM questions WHERE q_cat=$cat;
$result = mysql_query($sql);

//go through the question set
while($row = mysql_fetch_assoc($result)) {

  if(empty($_POST[$row['q_name']])){

  $message[$row['q_name']] == 1;
  }
}
}//function ValidatePost

Can anyone tell me what I am doing wrong?

Thanks!
JJ

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



Re: [PHP] error checking woes

2005-07-30 Thread Jack Jackson


Okay, last attempt before I hit my head against wall. I thought perhaps 
to add the error check to the dropdown function itself:




function GetQuestionsDropdown($cat){
//first get all the questions

$sql = SELECT * FROM questions WHERE questions.q_cat=$cat AND 
questions.q_style=1;


$result = mysql_query($sql);
//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {

//if the form has been submitted, and the question unanswered
//highlight this whole question and answer block in red.
if ($message[$row['q_name']] == 1){
echo div class='error';
}

//Make a question set div wrapper
echo div class='q_set'\n;
//State the question
echo div class='question';
echo $row['q_text'] . /div;
echo \n\n;
echo  div class='answer';
echo \n;

//Create the dropdown for the answers
echo '  select name=' . $row['q_name'] . '';
echo \n;

//get all of the answers for THIS question
$ans_sql = select * from answers where answers.q_id= . $row['q_id'];
$ans_result = mysql_query($ans_sql);

echo option value=\\Select from this list/option\n;
while($ans_row = mysql_fetch_assoc($ans_result)) {

//list the answers for THIS question
echo option ;
echo value=\ . $ans_row['a_id'] . \;

if  ($row['q_name'] == $ans_row['a_id']) {
echo  selected;
}

echo  . $ans_row['a_answer'] . /option;
echo \n;
}
echo '  /select' . \n . ' /div' . \n;
echo /div!--q_set--\n\n;
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo /div!--/error--;
}
//error checking
if ( !strcmp($action,'process') ) {
  if(empty($_POST[$row['q_name']])){
  $message[$row['q_name']] == 1;
  }
}


}
}//function GetQuestionsDropdown




it didn't work either.










Jack Jackson wrote:

Hi,
Now that the drop down is working properly (thanks!!), I am trying to 
validate, and having LOTS of trouble. After being ceaselessly derided 
last night on an irc channel for my dimwitedness, I am still not any 
closer.


The code which works is this:

function GetQuestionsDropdown($cat){
//first get all the questions

$sql = SELECT * FROM questions WHERE questions.q_cat=$cat AND 
questions.q_style=1;


$result = mysql_query($sql);
//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {
   
//if the form has been submitted, and the question unanswered

//highlight this whole question and answer block in red.
if ($message[$row['q_name']] == 1){
echo div class='error';
}
   
//Make a question set div wrapper

echo div class='q_set'\n;
//State the question
echo div class='question';
echo $row['q_text'] . /div;
echo \n\n;
echo  div class='answer';
echo \n;
   
//Create the dropdown for the answers

echo '  select name=' . $row['q_name'] . '';
echo \n;
   
//get all of the answers for THIS question

$ans_sql = select * from answers where answers.q_id= . $row['q_id'];
$ans_result = mysql_query($ans_sql);

echo option value=\\Select from this list/option\n;
while($ans_row = mysql_fetch_assoc($ans_result)) {
   
//list the answers for THIS question

echo option ;
echo value=\ . $ans_row['a_id'] . \;

if  ($row['q_name'] == $ans_row['a_id']) {
echo  selected;
}

echo  . $ans_row['a_answer'] . /option;
echo \n;
}
echo '  /select' . \n . ' /div' . \n;
echo /div!--q_set--\n\n;
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo /div!--/error--;
}
}
}//function GetQuestionsDropdown


NOW I have to validate after it's submitted. I am trying to look and 
see, if $_POST[$row['q_name']] is empty then make message of the same 
name = 1, so if


   if(empty($_POST['partners'])) {
   $message['partners'] = '1'
}

Then when I restate the dropdown function, and it shows the questions 
again,  those error checking things I built in will

a) show a div class=error around questions with a message
b) pre-select the previously selected answers (because I have put

Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson
Hi, can anyone even point me in a *direction*? I suppose this is the 
most complex thing I've ever tried to do and I have been at it for tens 
of hours and am still completely baffled.



Jack Jackson wrote:

Hi,
because that last topic on multipage forms was so exciting, I decided to 
database the questions as well. I wonder if anyone can help me with a 
function to pull rows into dropdown boxes.


It's a 1:n relationship between questions and answers, and I have a 
table of questions


q_id
q_name
q_text
q_style //dropdown, radio, checkboxes
q_cat //question category

and a table full of answers

a_id
q_id
a_answer


When I do

$fields = 'SELECT *';
$from = 'FROM questions,answers';
$sort = ORDER BY questions.q_cat;
$where = WHERE answers.q_id=questions.q_id;

// construct the sql query:
$sql = $fields $from $where $sort;

// Run SQL query 1
if (!($result = mysql_query($sql))) {
echo Could not connect to the database ($sql) . mysql_error();
}

while ($row = mysql_fetch_assoc($result)) {


I need to loop through the results and make a dropdown list from them, 
taking the question name as the select name, and then making each answer 
id and answer text the makings of an option ros.


Based on a problem a while ago which was similar but different, someone 
here actually made me a function *similar* to what I need to do now, 
This one acts different and I just cannot adapt the old one, because I 
still get confused at this level.


I think it wants to be something like (and note that part of the return 
is the code to react to error checking results):


$dropdown[] = 'option ?php if (' . $q_name . ' == ' . $a_id . ') 
echo selected ; ? value=\'' . $a_id . '\'' . $a_answer . '/option';


etc for all $a_answer(s)...
and then

return '?php if (sizeof($message[\'' . $q_name . '\'])){ echo div 
class='error'; } ?

div class=\'row\'
select class=\'answer\' name=\'' . $q_name . '\'
option value=\'\'Select from this list/option'
 join('',$dropdown)
 . '/select/div'
 . '?php if (sizeof($message[\''. $q_name '\'])){ echo 
/div!--/error--; } ?';



Can anyone point me at the right direction?

Thanks!!

JJ



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



Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson

Hi, Jay,
I see perhaps I *was* thinking too complex. However this is *just* a bit 
  off:


Jay Blanchard wrote:

[snip]
Hi, can anyone even point me in a *direction*? I suppose this is the 
most complex thing I've ever tried to do and I have been at it for tens 
of hours and am still completely baffled.



Jack Jackson wrote:


Hi,
because that last topic on multipage forms was so exciting, I decided


to 

database the questions as well. I wonder if anyone can help me with a 
function to pull rows into dropdown boxes.


It's a 1:n relationship between questions and answers, and I have a 
table of questions


q_id
q_name
q_text
q_style //dropdown, radio, checkboxes
q_cat //question category

and a table full of answers

a_id
q_id
a_answer


When I do

   $fields = 'SELECT *';
   $from = 'FROM questions,answers';
   $sort = ORDER BY questions.q_cat;
   $where = WHERE answers.q_id=questions.q_id;

// construct the sql query:
$sql = $fields $from $where $sort;

// Run SQL query 1
if (!($result = mysql_query($sql))) {
echo Could not connect to the database ($sql) . mysql_error();
}

while ($row = mysql_fetch_assoc($result)) {
   


I need to loop through the results and make a dropdown list from them,




taking the question name as the select name, and then making each


answer 


id and answer text the makings of an option ros.

Based on a problem a while ago which was similar but different,


someone 

here actually made me a function *similar* to what I need to do now, 
This one acts different and I just cannot adapt the old one, because I




still get confused at this level.

I think it wants to be something like (and note that part of the


return 


is the code to react to error checking results):

$dropdown[] = 'option ?php if (' . $q_name . ' == ' . $a_id . ') 
echo selected ; ? value=\'' . $a_id . '\'' . $a_answer .


'/option';


   etc for all $a_answer(s)...
   and then
   
return '?php if (sizeof($message[\'' . $q_name . '\'])){ echo div 
class='error'; } ?

   div class=\'row\'
   select class=\'answer\' name=\'' . $q_name . '\'
   option value=\'\'Select from this list/option'
join('',$dropdown)
. '/select/div'
. '?php if (sizeof($message[\''. $q_name '\'])){ echo 
/div!--/error--; } ?';
   


Can anyone point me at the right direction?

Thanks!!

JJ



[/snip]


It seems that you have over-complicated the issue, let me boil it down a
little;

$sql = select answer from table ;
if(!($result = mysql_query($sql, $connection))){
   echo mysql_error() . \n;
   exit();
}

echo select name=\answers\\n;
while($row = mysql_fetch_array($result)){
echo option name=\. $row['answer'] . \;
echo $row['answer'];
echo /option\n;

}
echo /select\n;

Your out put will look like this;

select name=answers
option name=answer1answer1/option
option name=answer2answer2/option
option name=answer3answer3/option
/select

Is this what you're after?




Very close to it, thank you! However this completes the gap: I am still 
not sure if my syntax is right:



$sql = 'SELECT *
FROM questions,answers
WHERE answers.q_id=questions.q_id
ORDER BY questions.q_cat,questions.q_id,answers.q_id';

if(!($result = mysql_query($sql, $connection))){
echo mysql_error() . \n;
exit();
 }

 /*each question has at least one answer, usually three to six
  *I need to give the select the name of $q_name
  *and dynamically loop through until all the question/answer
  *sets have their own dropdown
  */


 echo select name=\' . $q_name . \'\n;
 while($row = mysql_fetch_array($result)){
echo option name=\. $row['a_id'] . \;
echo ?php if . \$$q_name .  ==  . $a_id . echo \selected \ 
?\n;
echo $row['$a_answer'];
echo /option\n;

 }
 echo /select\n;

Then hopefully my output would look like
 select name=question_name
 option ?php if $question_name == 1 echo selected  ? 
value=1Answer One/option


 select name=question_name
 option ?php if $question_name == 2 echo selected  ? 
value=2Answer Two/option


 select name=question_name
 option ?php if $question_name == 1 echo selected  ? 
value=3Answer Two/option

 /select





TIA!!

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



Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson


Kristen,

Thank you so much this is precisely what I was trying to accomplish. 
However I was also trying to learn how to do it with those arrays you 
mentioned which I figure will help me emerge from total newbieness.


To date, I hope the list has seen I've progressed from absolutely *no* 
programming experience whatever to the point where I feel comfortable 
saying I am a newbie programmer (as opposed to a clueless one).


But Multidimensional arrays still baffle me and I believe that certain 
aspects of them work by magic!


I hope that people here will help me figure out both approaches. And 
thank you so much for the code here and the fix, which even I can follow!


JJ



Kristen G. Thorson wrote:
I'm not 100% sure where you're saying you're stuck, but I think you're 
trying to do with one query what you will probably find is best to do 
with several.  Hopefully the following will help some:



//first get all the questions
$sql = select * from questions;
$result = mysql_query( $sql );

//now one-by-one go through the questions
while( $row = mysql_fetch_row( $result ) {

   //create the drop down box for THIS question
   echo 'select name='.$row['question_text'].'';

   //get all of the answers for THIS question
   $ans_sql = select * from answers where 
question_id=.$row['question_id'];

   $ans_result = mysql_query( $ans_sql );
   while( $ans_row = mysql_fetch_row( $ans_result ) ) {

  //list the answers for THIS question
  echo 'option 
value='.$ans_row['answer_id'].''.$ans_row['answer_text'].'/option';

   }
   echo '/select';
}

outputs:
select name=question1
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option

select name=question2
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option
option value=4answer 4/option
option value=5answer 5/option



It requires numerous DB calls, but I believe in most cases, it's still 
better than what you'd have to do otherwise (create some arrays and do 
some sorting, etc.).  That is, if I've understood what you need ;)





kgt




Jack Jackson wrote:

Hi, can anyone even point me in a *direction*? I suppose this is the 
most complex thing I've ever tried to do and I have been at it for 
tens of hours and am still completely baffled.



Jack Jackson wrote:


Hi,
because that last topic on multipage forms was so exciting, I decided 
to database the questions as well. I wonder if anyone can help me 
with a function to pull rows into dropdown boxes.


It's a 1:n relationship between questions and answers, and I have a 
table of questions


q_id
q_name
q_text
q_style //dropdown, radio, checkboxes
q_cat //question category

and a table full of answers

a_id
q_id
a_answer


When I do

$fields = 'SELECT *';
$from = 'FROM questions,answers';
$sort = ORDER BY questions.q_cat;
$where = WHERE answers.q_id=questions.q_id;

// construct the sql query:
$sql = $fields $from $where $sort;

// Run SQL query 1
if (!($result = mysql_query($sql))) {
echo Could not connect to the database ($sql) . mysql_error();
}

while ($row = mysql_fetch_assoc($result)) {
   I need to loop through the results and make a dropdown list from 
them, taking the question name as the select name, and then making 
each answer id and answer text the makings of an option ros.


Based on a problem a while ago which was similar but different, 
someone here actually made me a function *similar* to what I need to 
do now, This one acts different and I just cannot adapt the old one, 
because I still get confused at this level.


I think it wants to be something like (and note that part of the 
return is the code to react to error checking results):


$dropdown[] = 'option ?php if (' . $q_name . ' == ' . $a_id . ') 
echo selected ; ? value=\'' . $a_id . '\'' . $a_answer . 
'/option';


etc for all $a_answer(s)...
and then
return '?php if (sizeof($message[\'' . $q_name . '\'])){ echo 
div class='error'; } ?

div class=\'row\'
select class=\'answer\' name=\'' . $q_name . '\'
option value=\'\'Select from this list/option'
 join('',$dropdown)
 . '/select/div'
 . '?php if (sizeof($message[\''. $q_name '\'])){ echo 
/div!--/error--; } ?';

   Can anyone point me at the right direction?

Thanks!!

JJ









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



Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson

And of course, I am finding that this way of yours is the easiest!!

Thanks, again, Kristen


JJ
Kristen G. Thorson wrote:
I'm not 100% sure where you're saying you're stuck, but I think you're 
trying to do with one query what you will probably find is best to do 
with several.  Hopefully the following will help some:



//first get all the questions
$sql = select * from questions;
$result = mysql_query( $sql );

//now one-by-one go through the questions
while( $row = mysql_fetch_row( $result ) {

   //create the drop down box for THIS question
   echo 'select name='.$row['question_text'].'';

   //get all of the answers for THIS question
   $ans_sql = select * from answers where 
question_id=.$row['question_id'];

   $ans_result = mysql_query( $ans_sql );
   while( $ans_row = mysql_fetch_row( $ans_result ) ) {

  //list the answers for THIS question
  echo 'option 
value='.$ans_row['answer_id'].''.$ans_row['answer_text'].'/option';

   }
   echo '/select';
}

outputs:
select name=question1
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option

select name=question2
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option
option value=4answer 4/option
option value=5answer 5/option



It requires numerous DB calls, but I believe in most cases, it's still 
better than what you'd have to do otherwise (create some arrays and do 
some sorting, etc.).  That is, if I've understood what you need ;)





kgt




Jack Jackson wrote:

Hi, can anyone even point me in a *direction*? I suppose this is the 
most complex thing I've ever tried to do and I have been at it for 
tens of hours and am still completely baffled.



Jack Jackson wrote:


Hi,
because that last topic on multipage forms was so exciting, I decided 
to database the questions as well. I wonder if anyone can help me 
with a function to pull rows into dropdown boxes.


It's a 1:n relationship between questions and answers, and I have a 
table of questions


q_id
q_name
q_text
q_style //dropdown, radio, checkboxes
q_cat //question category

and a table full of answers

a_id
q_id
a_answer


When I do

$fields = 'SELECT *';
$from = 'FROM questions,answers';
$sort = ORDER BY questions.q_cat;
$where = WHERE answers.q_id=questions.q_id;

// construct the sql query:
$sql = $fields $from $where $sort;

// Run SQL query 1
if (!($result = mysql_query($sql))) {
echo Could not connect to the database ($sql) . mysql_error();
}

while ($row = mysql_fetch_assoc($result)) {
   I need to loop through the results and make a dropdown list from 
them, taking the question name as the select name, and then making 
each answer id and answer text the makings of an option ros.


Based on a problem a while ago which was similar but different, 
someone here actually made me a function *similar* to what I need to 
do now, This one acts different and I just cannot adapt the old one, 
because I still get confused at this level.


I think it wants to be something like (and note that part of the 
return is the code to react to error checking results):


$dropdown[] = 'option ?php if (' . $q_name . ' == ' . $a_id . ') 
echo selected ; ? value=\'' . $a_id . '\'' . $a_answer . 
'/option';


etc for all $a_answer(s)...
and then
return '?php if (sizeof($message[\'' . $q_name . '\'])){ echo 
div class='error'; } ?

div class=\'row\'
select class=\'answer\' name=\'' . $q_name . '\'
option value=\'\'Select from this list/option'
 join('',$dropdown)
 . '/select/div'
 . '?php if (sizeof($message[\''. $q_name '\'])){ echo 
/div!--/error--; } ?';

   Can anyone point me at the right direction?

Thanks!!

JJ









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



Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson

Aaron,
Thanks for showing me this it is very cool indeed.

However maybe I am being dumb and obdurate but what I am really trying 
to do is build some of these things myself (with, thankfully, help) so 
that I understand enough that when I see a great tool like yours I'll 
actually appreciate what it's doing for me. I can see that your tool is 
doing everything in one line, and I think its really great. I just am 
such a beginner that I think tools like that would encourage me to 
*never* get above this level I'm at now.


I got the questions and answers thing working, starting with Kristen's 
two-query code and moving from there. I would like to come back to see 
how it can be done with one query and one function, but at this point my 
eyes are so bleary I'm grateful for the fact that I can now focus on 
getting the form to process!


Thanks again

JJ

Aaron Greenspan wrote:

Jay,

This is why I think frameworks are helpful Here's how I'd do it with 
Lampshade in one line of code with my own hypothetical field names:


dropdownBox('answerid', SELECT answerid, CONCAT(questions.description,' 
- ',answers.description) AS display FROM questions LEFT JOIN answers ON 
questions.questionid=answers.questionid ORDER BY questions.description, 
answers.description, $myrow['answerid'], 'Question and Answer', 'Choose 
an Answer');


For more information on this function:

http://www.thinkcomputer.com/software/lampshade/documentation.html?function=dropdownBox 



I'd be happy to help you get it set up if you have any questions.

Aaron

Aaron Greenspan
President  CEO
Think Computer Corporation

http://www.thinkcomputer.com



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



Re: [PHP] Dropdown Building Function

2005-07-29 Thread Jack Jackson



Kristen G. Thorson wrote:
I'm not 100% sure where you're saying you're stuck, but I think you're 
trying to do with one query what you will probably find is best to do 
with several.  Hopefully the following will help some:



//first get all the questions
$sql = select * from questions;
$result = mysql_query( $sql );

//now one-by-one go through the questions
while( $row = mysql_fetch_row( $result ) {

   //create the drop down box for THIS question
   echo 'select name='.$row['question_text'].'';

   //get all of the answers for THIS question
   $ans_sql = select * from answers where 
question_id=.$row['question_id'];

   $ans_result = mysql_query( $ans_sql );
   while( $ans_row = mysql_fetch_row( $ans_result ) ) {

  //list the answers for THIS question
  echo 'option 
value='.$ans_row['answer_id'].''.$ans_row['answer_text'].'/option';

   }
   echo '/select';
}

outputs:
select name=question1
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option

select name=question2
option value=1answer 1/option
option value=2answer 2/option
option value=3answer 3/option
option value=4answer 4/option
option value=5answer 5/option



It requires numerous DB calls, but I believe in most cases, it's still 
better than what you'd have to do otherwise (create some arrays and do 
some sorting, etc.).  That is, if I've understood what you need ;)




 And it did!!
//first get all the questions
$sql = select * from questions ORDER BY q_cat;
$result = mysql_query($sql);

//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {

//if the form has been submitted, and the question unanswered
//highlight this whole question and answer block in red.
if (sizeof($message[$row['q_name']])){
echo div class='error';
}

//State the question
echo div class='question';
echo $row['q_text'] . /div;
echo \n\n;
echo  div class='answer';
echo \n;

//Create the dropdown for the answers
echo '  select name=' . $row['q_name'] . '';
echo \n;

//get all of the answers for THIS question
$ans_sql = select * from answers where answers.q_id= . $row['q_id'];
$ans_result = mysql_query($ans_sql);

echo option value=\\Select from this list/option\n;
while($ans_row = mysql_fetch_assoc($ans_result)) {

//list the answers for THIS question
echo option ;
echo value=\ . $ans_row['a_id'] . \;

if  ($row['q_name'] == $ans_row['a_id']) {
echo  selected;
}

echo  . $ans_row['a_answer'] . /option;
echo \n;
}
echo '  /select' . \n . ' /div' . \n\n;
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo /div!--/error--;
}
}



Thanks so much!

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



Re: [PHP] Multipage form redux

2005-07-28 Thread Jack Jackson

Somehow my intent has been turned around here and I apologise.

I do not want to use *any* client side validation. I only want to do 
server side validation and server side storage.


My intent was to remove the client from as much as possible of this - if 
I didn't need their information I wouldn't even allow clients!! :)


What I wanted to do was this:


p. 1 : I send client page one, they send answers. SUBMIT sends to page 2 
script.


p 2. Before displaying anything to the client, Page 2 script validates 
input from page 1. If there are problems, page 2 script redisplays page 
one questions with highlights around problems. Clicking submit then 
resubmits page one data to page 2 script.


Once page 2 script validates all page 1 answers, page 2 script stores 
all those answers to a SESSION, then sends PAGE 2 QUESTIONS ONLY (no 
$_POST information) to client. Client answers page 2 questions and 
clicking submit submits PAGE 2 QUESTIONS to page 3 script.


p 3. Before displaying anything to the client, Page 3 script validates 
input from page 2 questions. If there are problems, page 3 script 
redisplays page 2 questions with highlights around problems. Clicking 
submit resubmits page 2 data to page 3 script.


Once page 3 script validates all page 2 answers, the script stores all 
those answers to a SESSION, then sends PAGE 3 QUESTIONS ONLY (no $_POST 
information) to client. Client answers page 3 questions and clicking 
submit submits PAGE 3 QUESTIONS to page 4 script.


At this point, if the client goes off for a bite, or two weeks 
backpacking in the Anapurna region, I'm fine, because the information is 
stored in the session (I have a very small group taking this 
questionnaire, all have a vested interested in filling it in, so I am 
not too worried abou their going aaway from it for more than a couple 
days max).


Once they complete the last set of questions, I say thanks much, get all 
the information out of their SESSION, insert it into the db, send 
confirmation emails all around and we're done.


Is this possible? How?

Thanks!



Marcus Bointon wrote:

On 27 Jul 2005, at 21:22, Jack Jackson wrote:


Right. Except I would rather have it working in a session because I  
specifically do not want to have the form sending $_POST data back  
and forth to the browser six times for several reasons. SO I'd like to


Page1 // User enters first batch of data, presses SUBMIT at bottom.  
Data is cleaned and written to SESSION, user passed to Page2


repeat as necessary to last page. At last page, process and error  
check newest input, then commit it, plus all previously stored  
session info to db.




As has also been said, Javascript can do this really nicely. The best  
example I've seen of this is in Mambo's (a popular PHP CMS) admin  
interface. It uses a tabbed multi-page form with client-side  
validation. It's really just one big page, so if the user has JS  turned 
off, they will get one big form with no client-side  validation, but it 
will still work. It's a really elegant way of  working. It doesn't 
require any server interaction between pages -  nothing is submitted 
until the form is complete.


See here for a howto: http://www.devx.com/webdev/Article/10483/1763/ page/1

Admittedly this approach doesn't easily allow to you abandon and  resume 
later (unless you get clever with JS and cookies).


For keeping data in a session, you could combine this approach with  
Ajax: http://particletree.com/features/smart-validation-with-ajax


Marcus


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



Re: [PHP] Multipage form redux

2005-07-28 Thread Jack Jackson

The light dawns.

Thank you everyone for this explanation, and the help




JJ

Mark Rees wrote:

Jack Jackson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


Somehow my intent has been turned around here and I apologise.

I do not want to use *any* client side validation. I only want to do
server side validation and server side storage.

My intent was to remove the client from as much as possible of this - if
I didn't need their information I wouldn't even allow clients!! :)

What I wanted to do was this:


p. 1 : I send client page one, they send answers. SUBMIT sends to page 2
script.

p 2. Before displaying anything to the client, Page 2 script validates
input from page 1. If there are problems, page 2 script redisplays page
one questions with highlights around problems. Clicking submit then
resubmits page one data to page 2 script.

Once page 2 script validates all page 1 answers, page 2 script stores
all those answers to a SESSION, then sends PAGE 2 QUESTIONS ONLY (no
$_POST information) to client. Client answers page 2 questions and
clicking submit submits PAGE 2 QUESTIONS to page 3 script.

p 3. Before displaying anything to the client, Page 3 script validates
input from page 2 questions. If there are problems, page 3 script
redisplays page 2 questions with highlights around problems. Clicking
submit resubmits page 2 data to page 3 script.

Once page 3 script validates all page 2 answers, the script stores all
those answers to a SESSION, then sends PAGE 3 QUESTIONS ONLY (no $_POST
information) to client. Client answers page 3 questions and clicking
submit submits PAGE 3 QUESTIONS to page 4 script.

At this point, if the client goes off for a bite, or two weeks
backpacking in the Anapurna region, I'm fine, because the information is
stored in the session (I have a very small group taking this
questionnaire, all have a vested interested in filling it in, so I am
not too worried abou their going aaway from it for more than a couple
days max).

Once they complete the last set of questions, I say thanks much, get all
the information out of their SESSION, insert it into the db, send
confirmation emails all around and we're done.



Sessions are used to identify users on a single visit to a website. They are
not intended to track users who turn off their machines, then turn them on
again and visit the website again. There are various ways of doing this, and
for all I know it may be possible with sessions, but I don't recommend you
try.

Do as suggested previously by various posters, it is the simplest and most
robust solution to your problem:

1. have the user register their details first up. Store this in a db, and
use it to identify the user on any subsequent visit.
2. when each page is submitted, write the information into the db. This way
it will definitely be associated with the right user
3. Whenever a user revisits the questionnaire, make them log in, then take
them to wherever they were up to - you will be able to work this out from
the amount of data you have recorded against them.

e.g. database table

userid
question
question
question
question
question
question









Is this possible? How?

Thanks!



Marcus Bointon wrote:


On 27 Jul 2005, at 21:22, Jack Jackson wrote:




Right. Except I would rather have it working in a session because I
specifically do not want to have the form sending $_POST data back
and forth to the browser six times for several reasons. SO I'd like to

Page1 // User enters first batch of data, presses SUBMIT at bottom.
Data is cleaned and written to SESSION, user passed to Page2

repeat as necessary to last page. At last page, process and error
check newest input, then commit it, plus all previously stored
session info to db.



As has also been said, Javascript can do this really nicely. The best
example I've seen of this is in Mambo's (a popular PHP CMS) admin
interface. It uses a tabbed multi-page form with client-side
validation. It's really just one big page, so if the user has JS  turned
off, they will get one big form with no client-side  validation, but it
will still work. It's a really elegant way of  working. It doesn't
require any server interaction between pages -  nothing is submitted
until the form is complete.

See here for a howto: http://www.devx.com/webdev/Article/10483/1763/


page/1


Admittedly this approach doesn't easily allow to you abandon and  resume
later (unless you get clever with JS and cookies).

For keeping data in a session, you could combine this approach with
Ajax: http://particletree.com/features/smart-validation-with-ajax

Marcus





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



Re: [PHP] Multipage form redux

2005-07-28 Thread Jack Jackson



Mark Rees wrote:

André Medeiros [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]


The point of sessions is that when you close your browser, you loose it.
I'm affraid that if you want sessions that last two weeks, you'll have
to make your own session handler :) but yeah, it's possible, and it
beats the crap out of the fill form, store in db, fill form, store in
db method.



Unless your user wishes to complete the form from a different machine, of
course.

I really don't understand the dogmatic antipathy to storing information in
the database. Sometimes it is a better solution - horses for courses.
Rolling your own session management tool, whilst undoubtedly fun and
satisfying, is hardly an appropriate solution to this type of enquiry, which
is apparently from someone taking their first steps in web development.

I should probably explain that I come from an ASP background and so have an
inherent mistrust of sessions, although I am coming to understand that PHP
sessions are much more reliable.

Sorry about the three posts before, my mistake.






No, I think I wasn't clear because of a fundamental misunderstanding on 
my part of the problem of SESSIONS not lasting between ... uh... 
sessions. In fact I think my very first post on the subject did in fact 
say I wanted to store the answers on the db throughout the process, but 
I got so excited at the prospect of having sessions store things that I 
got distracted.


Anyway, thanks again to all who replied and for all the help I generally 
receive here on the list!!


JJ

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



[PHP] Dropdown Building Function

2005-07-28 Thread Jack Jackson

Hi,
because that last topic on multipage forms was so exciting, I decided to 
database the questions as well. I wonder if anyone can help me with a 
function to pull rows into dropdown boxes.


It's a 1:n relationship between questions and answers, and I have a 
table of questions


q_id
q_name
q_text
q_style //dropdown, radio, checkboxes
q_cat //question category

and a table full of answers

a_id
q_id
a_answer


When I do

$fields = 'SELECT *';
$from = 'FROM questions,answers';
$sort = ORDER BY questions.q_cat;
$where = WHERE answers.q_id=questions.q_id;

// construct the sql query:
$sql = $fields $from $where $sort;

// Run SQL query 1
if (!($result = mysql_query($sql))) {
echo Could not connect to the database ($sql) . mysql_error();
}

while ($row = mysql_fetch_assoc($result)) {


I need to loop through the results and make a dropdown list from them, 
taking the question name as the select name, and then making each answer 
id and answer text the makings of an option ros.


Based on a problem a while ago which was similar but different, someone 
here actually made me a function *similar* to what I need to do now, 
This one acts different and I just cannot adapt the old one, because I 
still get confused at this level.


I think it wants to be something like (and note that part of the return 
is the code to react to error checking results):


$dropdown[] = 'option ?php if (' . $q_name . ' == ' . $a_id . ') 
echo selected ; ? value=\'' . $a_id . '\'' . $a_answer . '/option';


etc for all $a_answer(s)...
and then

return '?php if (sizeof($message[\'' . $q_name . '\'])){ echo div 
class='error'; } ?

div class=\'row\'
select class=\'answer\' name=\'' . $q_name . '\'
option value=\'\'Select from this list/option'
 join('',$dropdown)
 . '/select/div'
 . '?php if (sizeof($message[\''. $q_name '\'])){ echo 
/div!--/error--; } ?';



Can anyone point me at the right direction?

Thanks!!

JJ

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



[PHP] Multipage form redux

2005-07-27 Thread Jack Jackson

Hi,
I have searched the archives and seen links to tutorials at phpclasses 
(which seem to be down) and not found an answer to my question:
I have a long form I want to break into seven pages. Rather than pass 
values from page to page as hidden, I'd rather write the results to the 
db after each page then move on.


Anyone know of any tutorials on this?

Thanks in advance,
JJ

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



Re: [PHP] Multipage form redux

2005-07-27 Thread Jack Jackson
Thanks everyone. I take the point of Andre, but believe that the depth 
and sensitivity of the data require it be stored server side. I think 
that Richard and Mark have put their fingers on it - it's gotta be 
cookie based. Someone on the IRC suggested sessions and I think that it 
the way it goes. As for the idea that new users would be sent packing by 
such a ridiculously long form, right on! This is a form to be filled in 
by a client of the company after they've hired to company to provide an 
assessment of ther practices, so they'd expect a long form. But point taken


Thanks everyone for replying so quickly!

I'll come back when I botch the sessions and need help fixing!!

JJ


Richard Davey wrote:

Hello André,

Wednesday, July 27, 2005, 2:22:30 PM, you wrote:

AM That's not a very good idea. Imagine the user gets to the fourth
AM form and gets a cup of coffee, or goes out to lunch. By the time
AM he gets to the computer he might have lost the session, thus
AM having data on your DB that is wasting space.

AM And what if the user closes the browser window? :)

All of those things are unavoidable no matter what technique you use
:)

I've seen multi-page forms with a Finish this later option that
issues a cookie to your browser, allowing you to visit the site at any
(realistic) point in the future and carry on. In which cases the
part-filled contents must already be in a database somewhere. This
isn't a bad thing imho, it's a nice touch.

Of course it's prone to the usual browser doesn't accept cookies /
browser deletes cookies syndrome though.

If you don't want to pass the form values across in a hidden manner
(and I don't blame you) then it's either dump it all in a session and
hope it doesn't time-out, or dump it into a database, issue the
visitor some link to that entry (cookie, session var) and again hope
they don't time out.

The only real difference being the DB option will need purging to get
rid of incomplete forms  X days old. But that in itself could prove a
useful statistic for reports. Unless you're dealing with thousands of
sign-ups an hour, I don't see any issue with this option.

Another technique might be the following - rethink how your forms
work. Exactly what is it you're collecting data about? If it's part of
a long sign-up process then you could consider changing the process
around a bit - so that the VERY first thing the user does is create a
temporary account on your site (call them incomplete users). So you
grab some method of login + authentication details from them. Then the
form pages following this can all be saved to a DB and linked to that
user.

So, as long as they complete this first step, they can always come
back and finish the job off - whenever they want, avoiding cookie and
session time-out issues.

This won't work for all forms of course, it depends what the nature of
the process is, but it's certainly an option.

Best regards,

Richard Davey


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



Re: [PHP] Multipage form redux

2005-07-27 Thread Jack Jackson

hi, my first attempt at a sessions-based form is starting at

http://pastebin.com/322696

and I have a question. What I want to do is, after the user answers the 
questions in section one and they are error checked, I want to write the 
answers to $_SESSION() and then continue down the script to the next 
page of questions. I do *not* want to re-send the answers from page one 
as $_POST vars back to the user and have the user submit the answers to 
page 2 plus the $_POST answers from page 1.




What I am doing now is clearly wrong, basically :

if (empty($error)) {
include_once($page2);
}

because that's keeping it all in one script. But how should I be getting 
to the next page, sending headers to a new script, and at the end of the 
chain the script which pulls it all together?


Thanks in advance,

JJ






Jack Jackson wrote:





Thanks everyone. I take the point of Andre, but believe that the depth 
and sensitivity of the data require it be stored server side. I think 
that Richard and Mark have put their fingers on it - it's gotta be 
cookie based. Someone on the IRC suggested sessions and I think that it 
the way it goes. As for the idea that new users would be sent packing by 
such a ridiculously long form, right on! This is a form to be filled in 
by a client of the company after they've hired to company to provide an 
assessment of ther practices, so they'd expect a long form. But point taken


Thanks everyone for replying so quickly!

I'll come back when I botch the sessions and need help fixing!!

JJ


Richard Davey wrote:


Hello André,

Wednesday, July 27, 2005, 2:22:30 PM, you wrote:

AM That's not a very good idea. Imagine the user gets to the fourth
AM form and gets a cup of coffee, or goes out to lunch. By the time
AM he gets to the computer he might have lost the session, thus
AM having data on your DB that is wasting space.

AM And what if the user closes the browser window? :)

All of those things are unavoidable no matter what technique you use
:)

I've seen multi-page forms with a Finish this later option that
issues a cookie to your browser, allowing you to visit the site at any
(realistic) point in the future and carry on. In which cases the
part-filled contents must already be in a database somewhere. This
isn't a bad thing imho, it's a nice touch.

Of course it's prone to the usual browser doesn't accept cookies /
browser deletes cookies syndrome though.

If you don't want to pass the form values across in a hidden manner
(and I don't blame you) then it's either dump it all in a session and
hope it doesn't time-out, or dump it into a database, issue the
visitor some link to that entry (cookie, session var) and again hope
they don't time out.

The only real difference being the DB option will need purging to get
rid of incomplete forms  X days old. But that in itself could prove a
useful statistic for reports. Unless you're dealing with thousands of
sign-ups an hour, I don't see any issue with this option.

Another technique might be the following - rethink how your forms
work. Exactly what is it you're collecting data about? If it's part of
a long sign-up process then you could consider changing the process
around a bit - so that the VERY first thing the user does is create a
temporary account on your site (call them incomplete users). So you
grab some method of login + authentication details from them. Then the
form pages following this can all be saved to a DB and linked to that
user.

So, as long as they complete this first step, they can always come
back and finish the job off - whenever they want, avoiding cookie and
session time-out issues.

This won't work for all forms of course, it depends what the nature of
the process is, but it's certainly an option.

Best regards,

Richard Davey





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



Re: [PHP] Multipage form redux

2005-07-27 Thread Jack Jackson

Jim Moseby wrote:

-Original Message-
From: Jack Jackson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 27, 2005 3:47 PM
To: php  [php] PHP General List
Subject: Re: [PHP] Multipage form redux


hi, my first attempt at a sessions-based form is starting at

http://pastebin.com/322696

and I have a question. What I want to do is, after the user 
answers the 
questions in section one and they are error checked, I want 
to write the 
answers to $_SESSION() and then continue down the script to the next 
page of questions. I do *not* want to re-send the answers 
from page one 
as $_POST vars back to the user and have the user submit the 
answers to 
page 2 plus the $_POST answers from page 1.




What I am doing now is clearly wrong, basically :

if (empty($error)) {
include_once($page2);
}

because that's keeping it all in one script. But how should I 
be getting 
to the next page, sending headers to a new script, and at the 
end of the 
chain the script which pulls it all together?


Thanks in advance,

JJ




This seems so simple to me.  As I understand it, you want to split a data
entry session into several pages.  You don't want to collect the data and
submit it all at the end, but instead commit it to session variables along
the way.  Am I missing something? 


Here's how I would do it in a nutshell:

Page1 // User enters first batch of data, presses SUBMIT at bottom.  Data is
POSTed to Page2

Page2 // Commit data from page 1 to session variables, then displays form
for next batch of data.  User presses SUBMIT, posts data to Page 3.

Page3 // Commit data from page 2 to session variables, then displays form
for next batch of data.  User presses SUBMIT, posts data to Page 4.

... etc etc etc  (Each page begins by assigning data from the previous page
to session variables)

Page515 // Displays all session variables set in previous pages, asks user
to confirm.  User confirms by pressing SUBMIT, confirmation POSTed to page
516, who writes it all to the database, and sends confirmation email.

Personally, I would take the advice of a previous poster and start off
assigning a username and password to the user.  Then store each page in the
database as the user progresses.  That way, if he is interrupted in the
middle of the process, he won't lose all his data and have to start over.
He can just enter his username and pick up where he left off. You will just
have to  write a script that purges old incomplete records. (A great job for
cron!)

JM




Right. Except I would rather have it working in a session because I 
specifically do not want to have the form sending $_POST data back and 
forth to the browser six times for several reasons. SO I'd like to


Page1 // User enters first batch of data, presses SUBMIT at bottom. 
Data is cleaned and written to SESSION, user passed to Page2


repeat as necessary to last page. At last page, process and error check 
newest input, then commit it, plus all previously stored session info to 
db.


Does this make sense?

Thanks in advance

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



[PHP] Prepopulating form fields afer an error

2005-07-25 Thread Jack Jackson

Hi,
I have a form and it does basic error checking after submission; when 
the user omits required fields it kicks back the form with highlighted 
errors telling them the error of their ways.


I've sussed out that by populating the value of the field with 
$fieldvalue I can have that form field populated with the data the 
user *did* enter for that field:


something like

input type=text name=email_address value=?php echo $email_address?

That works great. But how can I do the same thing for drop down boxes, 
when they select an option?


I tried the unwieldy,

select name='blah'
 ?php if (!empty(blah)) {
echo option value=';
echo $blah;
echo '
echo $blah;
echo /option\n;
}
   ?


And that, lo and behold, didn't work. Can anyone offer a suggestion?

Thanks in advance
JJ

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



Re: [PHP] Prepopulating form fields afer an error

2005-07-25 Thread Jack Jackson

Thanks so much, Mark, Matt and John! I'll play with all those.

Much appreciated,

JJ

Mark Cain wrote:

Here's the way I do it:

The following is an HTML code snippet with embedded PHP code for the
intelligence.

select name=shipper
 option value=DHL ? if ($shipped_via == DHL) echo selected;
?DHL
 option value=FedEx ? if ($shipped_via == FedEx) echo selected;
?FedEx
 option value=UPS ? if ($shipped_via == UPS) echo selected;
?UPS
/select




Mark Cain


- Original Message -
From: Jack Jackson [EMAIL PROTECTED]
To: [php] PHP General List php-general@lists.php.net
Sent: Monday, July 25, 2005 2:37 PM
Subject: [PHP] Prepopulating form fields afer an error




Hi,
I have a form and it does basic error checking after submission; when
the user omits required fields it kicks back the form with highlighted
errors telling them the error of their ways.

I've sussed out that by populating the value of the field with
$fieldvalue I can have that form field populated with the data the
user *did* enter for that field:

something like

input type=text name=email_address value=?php echo $email_address?

That works great. But how can I do the same thing for drop down boxes,
when they select an option?

I tried the unwieldy,

select name='blah'
 ?php if (!empty(blah)) {
echo option value=';
echo $blah;
echo '
echo $blah;
echo /option\n;
}
   ?


And that, lo and behold, didn't work. Can anyone offer a suggestion?

Thanks in advance
JJ

--
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



[PHP] Zipping on the fly

2005-06-29 Thread Jack Jackson

hi,
I'm providing a download script which lets trusted users view a 
directory and select a file to download; I don't want to store the files 
zipped on the server. Is there a fast, built-in way to zip the selected 
file on the fly and let the user download the zipped copy? I looked at 
php.net/zip and didn't see any...


Thanks in advance

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



Re: [PHP] Zipping on the fly

2005-06-29 Thread Jack Jackson

Thanks for this Philip and Andre!

Philip Hallstrom wrote:

hi,
I'm providing a download script which lets trusted users view a 
directory and select a file to download; I don't want to store the 
files zipped on the server. Is there a fast, built-in way to zip the 
selected file on the fly and let the user download the zipped copy? I 
looked at php.net/zip and didn't see any...



http://marc.theaimsgroup.com/?r=1w=2q=bl=php-generals=zip

Read the PHP ZIP Class messages...





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



Re: [PHP] Verifying images with getimagesize()

2005-06-25 Thread Jack Jackson



Edward Vermillion wrote:

Sorry to reply to this message but I wanted the OP to find it too...

On Jun 23, 2005, at 9:42 AM, Jack Jackson wrote:
[snip]

Through your help I was able to validate image files using 
getimagesize() and have made a nice script to upload and rename images.



[\snip]

I've been meaning to post a reply to a problem I ran into a while back 
that included validating images with getimagesize(). I've seen a few 
posts from folks saying this is the way to go and just want to share my 
experiences.


My original problem was that a script I had for batch generating 
thumbnails from uploaded images was running out of memory. With Richard 
Lynch's help I was able to track the problem to createimagefromjpeg() 
using an unholy amount of memory on one particular file, a file that had 
passed through getimagesize() with no problems.
What I found was that if an image ( in this case a jpeg ) is corrupted, 
but just barely, getimagesize() will let it through. Just for the record 
I could open it up in Photoshop and that's how I discovered that it was 
corrupted, the last ten or fifteen rows on the image were gone. 
Photoshop showed an uncompressed file size of 11M for this image. But 
what I had to end up doing is setting my memory limit to 48M before 
createimagefromjpeg() could get enough memory to work with that it 
finally failed.


Just a heads up to anyone that's using getimagesize() to verify an image 
before running it through createimagefromjpeg(), just because it passes 
getimagesize() doesn't necessarily mean it's a good image.


Edward Vermillion
[EMAIL PROTECTED]

Thanks for telling me about that, Edward. I apprecate it. Actually in 
this case I was using it only to verify that it was something like an 
image to validate the file type before allowing it on the server. But 
you raise a very good point and I appreciate it.


JJ

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



Re: [PHP] Uploading and verifying word and excel files

2005-06-24 Thread Jack Jackson

Thank you for ALL this great information, Richard! I really appreciate
all the help.

JJ
Richard Lynch wrote:

On Thu, June 23, 2005 7:42 am, Jack Jackson said:


I cannot see a way to validate or examine Word or Excel files for
validity (and assume that older word files would validate differently
from newer ones).



If your PHP does not have the mime_type functions, you could probably use
http://php.net/exec with the file utility which does much the same thing
under Un*x-like systems.

man file on the command line for more info.



The PEAR http upload script mentioned twice in the user notes at that
manual page does not *seem* to validate other than denying certain
extensions like php, php3, etc. I could be wrong of course.



Does it catch .asp, .cgi, .pl, .htm, .html, .jpg, .png, .gif, .jpeg, .pdf,
and .swf?

Cuz at certain directories on *my* server, those are all PHP scripts!

Well, okay, .pl and .cgi aren't.  Actually, I think I still have a .cgi
somewhere that *is* a PHP script...  It's equally dangerous either way.

Maybe someday they will be on your server, too, once you run into the
zillion IE bugs where the URL counts for more than the Content-type:
header.

It's really Bad Practice to rely on the last N characters of a filename as
some kind of Security Measure to stop a serious attack...



Also, it seems that directories must be blown wide open (777) to allow
the script to copy the file over from /tmp. My ISP won't allow
directories to be set to 777 under public_html/ -- but we need to access
the files via web browser which is the whole point.



Well, requring 777 just plain sucks...

You *should* have a directory writable by the PHP user/group as the
minimum requirement.

If PEAR really and truly requires 777, then that feature of PEAR sucks,
and you shouldn't use it.  Sorry, PEAR guys.  Gotta call 'em as I see 'em.

And if the best it can do is outlaw .php .php3 ..., then that ain't much
either.  I'd rather code it myself than have that weak of a safety.



So my questions:
1. How do you validate Word and Excel files before upload?



You don't.

Any validation done before upload is done on the client, and is therefore
something that can be easily bypassed by the savvy user.

It might be useful as a User-Interface feature to catch obvious stupid
mistakes by honest folk...

But it's USELESS as a Security Measure to stop Bad Guys.

Oh yeah:

You may need to use move_uploaded_file to move the files to a staging area
before you use exec/file on them...

At least, under *MY* webhost's setup, I can't directly read PHP uploaded
files from /tmp, even though PHP can move_uploaded_file() them... That may
have been changed/fixed, but it's a possible configuration issue.

So, use move_uploaded_file to let PHP do its checks, but put stuff in a
staging area that the PHP user can read/write, and is *NOT* in the
web-tree.

Then, do all of YOUR checks.  getimagesize, exec(/usr/bin/file $file...)
etc.

If that all passes, move the file (again) to its final destination, which
should *still* be out-side the web tree on most shared servers.

Write a PHP script that only allows files already listed in your database
to be served up, and which readfile's the data from outside the webtree to
spew it out.

*IF* you are on a dedicated server, or *IF* your webhost has a unique
UID/GID for you to have directories that no *OTHER* user on that webhost
can write to your PHP-writable directories/files, *then* it is
probably/maybe just as safe to put stuff in your webtree as to readfile it
from outside the web tree...

Even then, I'd only do the direct to webtree if performance was a major
issue.  It just doesn't make sense to me to let untrusted users put stuff
in the webtree where they might manage to trick the server into executing
it as Perl, PHP, JSP, ASP, or [deity] knows what code to do Evil things.

It's gonna be a lot tougher for them to fool PHP's readfile into executing
code.  Hell, if they can do that, they already own your server.



2. How can I make a passthrough from a file above public_html to one
below it so that people can surf in with a browser and download files
which have been uploaded by the script?



There's an easy one. :-)

Put the files *OUTSIDE* your webtree.

Then write a PHP script that takes an ID of a valid uploaded file that
your previously stored in your database, looks up the path to that file,
and use http://php.net/readfile on it.

You were real close with passthrough which is http://php.net/passthru
which is kind of the same, only not.

You'd only put files in the webtree if PHP readfile proved too slow, *AND*
you were sure no user on the box could ever manage to infiltrate a
damaging file into the webtree...

That second one is a pretty Tall Order...

I can see somebody justifying it, but, honestly, if the overhead of
readfile is that big of a deal, then maybe you're living too close to the
edge on performance in the first place, and it's time to buy more/better
hardware anyway

[PHP] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson

Hi,
I checked at http://www.php.net/manual/en/features.file-upload.php and 
all the user notes, and also the PEAR solution for uploading files and I 
still have a couple of questions.


I need to create a form to allow users to upload (and later to delete) 
MS word, excel and jpg files. Through your help I was able to validate 
image files using getimagesize() and have made a nice script to upload 
and rename images.


I cannot see a way to validate or examine Word or Excel files for 
validity (and assume that older word files would validate differently 
from newer ones).


The PEAR http upload script mentioned twice in the user notes at that 
manual page does not *seem* to validate other than denying certain 
extensions like php, php3, etc. I could be wrong of course.


Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to access 
the files via web browser which is the whole point.



So my questions:
1. How do you validate Word and Excel files before upload?

2. How can I make a passthrough from a file above public_html to one 
below it so that people can surf in with a browser and download files 
which have been uploaded by the script?


Thanks in advance,
JJ

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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson


John Nichel wrote:

Jack Jackson wrote:
snip

Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to 
access the files via web browser which is the whole point.



It shouldn't have to be this way.  The webserver should be configured to 
run as your virtual user, or belong to a group which has write 
permission to that directory, or.I'm getting a bit off track with 
that.  This is something you'll have to take up with your ISP.


Will do.




So my questions:
1. How do you validate Word and Excel files before upload?



Before?  JavaScript...if JavaScript can even do it (I haven't touched 
the stuff in ages).  After upload, you can check the mime type, but 
that's not foolproof.




Okay, sorry I miswrote: after upload to the temp directory, BEFORE using 
move_uploaded_file(). Checking the mime type is the problem - if I can't 
trust the browsers am I really reliant on the file extension? Can't I 
peek in some manner into it as we do with getimagesize()?


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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson



Tom Rogers wrote:

Hi,

Friday, June 24, 2005, 12:42:33 AM, you wrote:
JJ Hi,
JJ I checked at
JJ http://www.php.net/manual/en/features.file-upload.php and 
JJ all the user notes, and also the PEAR solution for uploading files and I

JJ still have a couple of questions.

JJ I need to create a form to allow users to upload (and later to delete)
JJ MS word, excel and jpg files. Through your help I was able to validate
JJ image files using getimagesize() and have made a nice script to upload
JJ and rename images.

JJ I cannot see a way to validate or examine Word or Excel files for 
JJ validity (and assume that older word files would validate differently

JJ from newer ones).

JJ The PEAR http upload script mentioned twice in the user notes at that
JJ manual page does not *seem* to validate other than denying certain
JJ extensions like php, php3, etc. I could be wrong of course.

JJ Also, it seems that directories must be blown wide open (777) to allow
JJ the script to copy the file over from /tmp. My ISP won't allow 
JJ directories to be set to 777 under public_html/ -- but we need to access

JJ the files via web browser which is the whole point.


JJ So my questions:
JJ 1. How do you validate Word and Excel files before upload?

JJ 2. How can I make a passthrough from a file above public_html to one
JJ below it so that people can surf in with a browser and download files
JJ which have been uploaded by the script?

JJ Thanks in advance,
JJ JJ

The first 8 bytes of an ole2 file (exel and word are ole2 files I
think) should have the following hex sequence:

\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1

So do an fopen and read in the first 8 bytes and compare it to that
string should give some indication.

Cl. Thank you Tom and all those who replied. I always learn so much 
here!


JJ

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



[PHP] Amy's Site question

2005-06-22 Thread Jack Jackson

Hello,

On a site I'm listing measurements in both inches and cm; in the db 
they're stored as inches. To convert them to cm I'm doing:


?php echo ($cartoon['art_width'] * 2.54); ? x ?php echo 
($cartoon['art_height'] * 2.54); ? cm



How can I limit the result of that math to one decimal place, ie, 9.5 
cm, not 9.523 cm?


Thanks in advance,
JJ

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



Re: [PHP] Amy's Site question

2005-06-22 Thread Jack Jackson
Thanks everyone! I did look in the manual under operators and must have 
missed the link to round. Thanks to all who replied!




Simon Allison wrote:

http://au3.php.net/round


-Original Message-
From: Jack Jackson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 22 June 2005 9:18 PM

To: [php] PHP General List
Subject: [PHP] Amy's Site question

Hello,

On a site I'm listing measurements in both inches and cm; in the db 
they're stored as inches. To convert them to cm I'm doing:


?php echo ($cartoon['art_width'] * 2.54); ? x ?php echo 
($cartoon['art_height'] * 2.54); ? cm



How can I limit the result of that math to one decimal place, ie, 9.5 
cm, not 9.523 cm?


Thanks in advance,
JJ



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



[PHP] Those checkboxes again

2005-06-16 Thread Jack Jackson

hi,
I'm severely frustrated and perhaps you can help with what I have done 
wrong. The checkboxes I use to populate an intersection table work to 
add the records, and now I am trying to update them. It's almost there 
but producing some unexpected results when the form is submitted: the 
idea is that it displays the checkboxes as pre-selected if they're 
associated with the art_id in the intersection table. They're now 
appearing as all unselected. Any help is appreciated.


?php

$query = '';
$result = 0;
$art_id = $_POST['art_id'];

print_r($_POST);

if (isset($_POST['editrecordMedia'])){

if (!empty($_POST['media_types'])) {

foreach($_POST['media_types'] as $type)
 {
 $query = UPDATE media_art SET
 media_id='$type',
 art_id='$art_id';
var_dump($query);
 mysql_query($query) or die(mysql_error());

 }
}

else {echo mediatypes is empty;}
//Closes if (!empty($media_types))
}//closes if (isset($_POST['editrecordMedia'])

//If editrecord hasn't been set, but selectcartoon has, get the 
cartoon's recordset


//This is just to get the title for display purposes
$query = SELECT art_title
FROM art
WHERE art_id='$art_id';
//end

$media_query = SELECT media.media_id,
media.media_name,
media_art.art_id
FROM media
LEFT JOIN media_art
ON media_art.media_id=media.media_id
AND media_art.art_id='$art_id';

//These $art results are just to get the title for display purposes
$art_result = mysql_query($query);  
$art_rows = mysql_fetch_assoc($art_result);
//end

$media_result = mysql_query($media_query);
$checkbox_media = array ();


while ($media_rows = mysql_fetch_assoc($media_result)){

	$checkbox_media[] = input type='checkbox' name='media_types[]' 
value='{$media_rows['media_id']}' ;


if ($media_rows['art_id'] === $art_id) {
$checkbox_media[] .= checked ;
}

$checkbox_media[] .= /{$media_rows['media_name']}  ;


}

?

table align=center
trth colspan=4Main Menu/th/tr
tr
tda href=addrecord.phpAdd A Record/a/td
tda href=chooserecord.phpEdit A Record/a/td
tda href=deleterecord.phpDelete A Record/a/td
/tr
/table

form action=?php echo $_SERVER['PHP_SELF']; ? method=post 
name=editrecordMedia

input type=hidden name=art_id value=?php echo $art_id ;?
 Choose media related to strong?php echo 
$art_rows['art_title'];?/strongbr /br /


 Media: ?php echo join($checkbox_media); ?

input type=submit name=editrecordMedia value=Update
/form

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



Re: [PHP] Re: Image upload form

2005-06-16 Thread Jack Jackson



Nadim Attari wrote:

http://www.php-help.net/sources-php/image.upload.function.353.html


Thanks, Nadim,
I'm sure that is a great script. I am really trying to learn how it's 
working, so I'm trying to stay away from pre-rolled stuff as much as I 
can and beg for the mercy of the list in building these simple scripts. 
Believe it or not I'm actually improving pretty fast (despite 
scriptorial evidence to the contrary on this list)!


Thanks again,
JJ




Regards,
Nadim Attari
Alienworkers.com




Hi, After a disastrous first attempt (which uploaded images but only by
chance) it was suggested I rework the entire thing. This one seems to
check the file against getimagesize and if that doesn't prove false,
check the type and make the extension then rename the file. But the
moving part is not working, and it does not kick back any error, it just
fails.

Can anyone tell me what I am doing wrong, and also if this is sufficient
to a) upload images safely and b) protect against tampering?

Thanks in advance,
JJ


?php

error_reporting(E_ALL);

  $uploaddir = images/jpg/test/;

//  print_r($_FILES);

  $local_file = $_FILES['userfile']['tmp_name'];

if (sizeof($local_file))
  {

//try to get image size; this returns false if this is not an actual
image file.
  $image_test = getimagesize($local_file);

if ($image_test !== false) {
  $mime_type = $_FILES['userfile']['type'];
  switch($mime_type) {
  case image/jpeg:
  $pext = 'jpg';
  break;
  case image/tiff:
  $pext = 'tif';
  break;
  default:
  echo The file you are trying to upload is an image, but it is not
a tif or jpeg and therefore unacceptable.;
  }
} else {
   echo The file you are trying to upload is not a valid image file;
}

 $main_image = md5(date(l-F-j-Y i:s)).'.'.$pext;


  move_uploaded_file($main_image,$uploaddir);

  }

  ?

  form enctype=multipart/form-data action=?php echo
$_SERVER['PHP_SELF']; ? method=POST
input type=hidden name=MAX_FILE_SIZE value=30 /
!-- Name of input element determines name in $_FILES array --
Cartoon: input name=userfile type=file /
input type=submit value=Upload File /
/form





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



[PHP] A more sane problem description

2005-06-16 Thread Jack Jackson

Sorry,
The last post I made was fairly incomprehensible.

I'm trying to

a) edit information which is already in an intersection table, while
b) allowing the user to add new information to the intersection table

The information in it is pulled from the table media_art and I grab the 
media_art_id, media_id and art_id.


If a media_id is associated with an art_id in the table, I grab all 
three and make the checkbox for that media_id checked.


I need to understand how I can make it so that

a) if the user UNchecks the box, then the row containing that media_id 
will be deleted.


AND

b) if the user checks a new box, a new row will be inserted into the 
media_art table containing the media_id and the art_id.


This is so far beyond my comprehension it's not even funny.

This is what I have so far - thank you in advance for the help.:


?php

$query = '';
$result = 0;
$art_id = $_POST['art_id'];
$media_art_id = $_POST['media_art_id'];
//print_r($_POST);

if (isset($_POST['editrecordMedia'])){

if (!empty($_POST['media_types'])) {

foreach($_POST['media_types'] as $type)
 {  
 $query = UPDATE media_art SET
 media_id='$type',
 art_id='$art_id'
 WHERE media_art_id='$media_art_id'
 LIMIT 1;
print_r($query);
 mysql_query($query) or die(mysql_error());

 }
}

else {echo mediatypes is empty;}
//Closes if (!empty($media_types))
}//closes if (isset($_POST['editrecordMedia'])

//If editrecord hasn't been set, but selectcartoon has, get the 
cartoon's recordset


//This is just to get the title for display purposes
$query = SELECT art_title
FROM art
WHERE art_id='$art_id';
//end

$media_query = SELECT media.media_id,
media.media_name,
media_art.art_id,
media_art.media_art_id
FROM media
LEFT JOIN media_art
ON media_art.media_id=media.media_id
AND media_art.art_id='$art_id';

//These $art results are just to get the title for display purposes
$art_result = mysql_query($query);  
$art_rows = mysql_fetch_assoc($art_result);
//end

$media_result = mysql_query($media_query);
$checkbox_media = array ();


while ($media_rows = mysql_fetch_assoc($media_result)){

	$checkbox_media[] = input type='checkbox' name='media_types[]' 
value='{$media_rows['media_id']}' ;


if ($media_rows['art_id'] === $art_id) {
		$checkbox_media[] .= checked 
media_art_id='{$media_rows['media_art_id']}';

}

$checkbox_media[] .= /{$media_rows['media_name']}  ;


}

?

table align=center
trth colspan=4Main Menu/th/tr
tr
tda href=addrecord.phpAdd A Record/a/td
tda href=chooserecord.phpEdit A Record/a/td
tda href=deleterecord.phpDelete A Record/a/td
/tr
/table

form action=?php echo $_SERVER['PHP_SELF']; ? method=post 
name=editrecordMedia

input type=hidden name=art_id value=?php echo $art_id ;?
 Choose media related to strong?php echo 
$art_rows['art_title'];?/strongbr /br /


 Media: ?php echo join($checkbox_media); ?

input type=submit name=editrecordMedia value=Update
/form

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



Re: [PHP] Those checkboxes again

2005-06-16 Thread Jack Jackson

Thanks, Joe!

I see what you weer going after. I had several problems including the 
fact that I really didn't understand what I was trying to do until after 
I did it. And I had some log errors a friend helped with.


What I needed to do was delete the media types from the intersection 
table and then insert them anew; that way I don't have to do all sorts 
of looping through finding the status of checked and unchecked boxes etc.


Eventually I came to:



 if (isset($_POST['editrecordMedia'])){

   if (!empty($_POST['media_types'])) {

   //TO make sure art_id isn't empty
   if (!empty($art_id)) { //delete media_art entries for this art_id
   $query=DELETE FROM media_art WHERE art_id='$art_id';
   mysql_query($query);

   $query = INSERT INTO `media_art`
   (`media_id`,`art_id`) VALUES ;
  $sep = ;
   foreach($_POST['media_types'] as $type)
   {
   $query .= $sep ('$type','$art_id');
   $sep = , ;



Anyway, thanks so much for your help!!

JJ
Joe Harman wrote:

 if ($media_rows['art_id'] === $art_id) {
   $checkbox_media[] .= checked ;
   }

   $checkbox_media[] .= /{$media_rows['media_name']}  ;


if think you only need 2 '=' signs... i do this alot with arrays of
check boxes .. now don't quote me on this... but i do something like 
this.. using arrays for the check box values


if($permissions_data  NULL)
{
if(in_array($row_rsPermissions['permission_short_name'], $permissions_data)) 
{ $checked_per =  checked; } else { $checked_per = ; }

}

hope that helps you out
Joe

On 6/16/05, Jack Jackson [EMAIL PROTECTED] wrote:


hi,
I'm severely frustrated and perhaps you can help with what I have done
wrong. The checkboxes I use to populate an intersection table work to
add the records, and now I am trying to update them. It's almost there
but producing some unexpected results when the form is submitted: the
idea is that it displays the checkboxes as pre-selected if they're
associated with the art_id in the intersection table. They're now
appearing as all unselected. Any help is appreciated.

?php

$query = '';
$result = 0;
$art_id = $_POST['art_id'];

print_r($_POST);

if (isset($_POST['editrecordMedia'])){

  if (!empty($_POST['media_types'])) {

  foreach($_POST['media_types'] as $type)
   {
   $query = UPDATE media_art SET
   media_id='$type',
   art_id='$art_id';
var_dump($query);
   mysql_query($query) or die(mysql_error());

   }
  }

  else {echo mediatypes is empty;}
  //Closes if (!empty($media_types))
   }//closes if (isset($_POST['editrecordMedia'])

//If editrecord hasn't been set, but selectcartoon has, get the
cartoon's recordset

//This is just to get the title for display purposes
$query = SELECT art_title
  FROM art
  WHERE art_id='$art_id';
//end

  $media_query = SELECT media.media_id,
  media.media_name,
  media_art.art_id
  FROM media
  LEFT JOIN media_art
  ON media_art.media_id=media.media_id
  AND media_art.art_id='$art_id';

//These $art results are just to get the title for display purposes
$art_result = mysql_query($query);
$art_rows = mysql_fetch_assoc($art_result);
//end

$media_result = mysql_query($media_query);
$checkbox_media = array ();


while ($media_rows = mysql_fetch_assoc($media_result)){

  $checkbox_media[] = input type='checkbox' name='media_types[]'
value='{$media_rows['media_id']}' ;

  if ($media_rows['art_id'] === $art_id) {
  $checkbox_media[] .= checked ;
  }

  $checkbox_media[] .= /{$media_rows['media_name']}  ;


}

?

table align=center
   trth colspan=4Main Menu/th/tr
   tr
   tda href=addrecord.phpAdd A Record/a/td
   tda href=chooserecord.phpEdit A Record/a/td
   tda href=deleterecord.phpDelete A Record/a/td
   /tr
/table

form action=?php echo $_SERVER['PHP_SELF']; ? method=post
name=editrecordMedia
input type=hidden name=art_id value=?php echo $art_id ;?
Choose media related to strong?php echo
$art_rows['art_title'];?/strongbr /br /

Media: ?php echo join($checkbox_media); ?

input type=submit name=editrecordMedia value=Update
   /form

--
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



[PHP] Image upload form

2005-06-15 Thread Jack Jackson
Hi, After a disastrous first attempt (which uploaded images but only by 
chance) it was suggested I rework the entire thing. This one seems to 
check the file against getimagesize and if that doesn't prove false, 
check the type and make the extension then rename the file. But the 
moving part is not working, and it does not kick back any error, it just 
fails.


Can anyone tell me what I am doing wrong, and also if this is sufficient 
to a) upload images safely and b) protect against tampering?


Thanks in advance,
JJ


?php

error_reporting(E_ALL);

  $uploaddir = images/jpg/test/;

//  print_r($_FILES);

  $local_file = $_FILES['userfile']['tmp_name'];

if (sizeof($local_file))
  {

//try to get image size; this returns false if this is not an actual 
image file.

  $image_test = getimagesize($local_file);

if ($image_test !== false) {
   $mime_type = $_FILES['userfile']['type'];
   switch($mime_type) {
   case image/jpeg:
   $pext = 'jpg';
   break;
   case image/tiff:
   $pext = 'tif';
   break;
   default:
		   echo The file you are trying to upload is an image, but it is not 
a tif or jpeg and therefore unacceptable.;	

   }
} else {
   echo The file you are trying to upload is not a valid image file;
}

 $main_image = md5(date(l-F-j-Y i:s)).'.'.$pext;


   move_uploaded_file($main_image,$uploaddir);

  }

  ?

  form enctype=multipart/form-data action=?php echo 
$_SERVER['PHP_SELF']; ? method=POST

input type=hidden name=MAX_FILE_SIZE value=30 /
!-- Name of input element determines name in $_FILES array --
Cartoon: input name=userfile type=file /
input type=submit value=Upload File /
/form

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



Re: [PHP] Image upload form

2005-06-15 Thread Jack Jackson

Okay, I started seeing some of my mistakes.

I am still having a great deal of trouble:


newfile returns: 0fdae2e9e6aa43f067a9dd780a5a36a6.jpg
image_file returns: images/jpg/test/0fdae2e9e6aa43f067a9dd780a5a36a6.jpg

images/jpg/test is set to 777 but I still get (Could not move file to 
destination).  What am I missing? Thanks!



?php

error_reporting(E_ALL);

  $uploaddir = images/jpg/test/;


  print_r($_FILES);

  $local_file = $_FILES['userfile']['tmp_name'];



if (sizeof($local_file))
  {

//try to get image size; this returns false if this is not an actual 
image file.

  $image_test = getimagesize($local_file);

if ($image_test !== false) {
   $mime_type = $_FILES['userfile']['type'];
   switch($mime_type) {
   case image/jpeg:
   $pext = 'jpg';
   break;
   case image/tiff:
   $pext = 'tif';
   break;
   default:
		   echo The file you are trying to upload is an image, but it is not 
a tif or jpeg and therefore unacceptable.;	

   }
} else {
   echo The file you are trying to upload is not a valid image file;
}

 $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext;

 $image_file = $uploaddir . $newfile;

// print_r($newfile);
// print_r($image_file);

 if(!move_uploaded_file($newfile,$image_file)) {

 echo 'Could not move file to destination';
 exit;
 }

 else {
 echo 'image file ?php echo $newfile ? uploaded.';



 }



  }

  ?

  form enctype=multipart/form-data action=?php echo 
$_SERVER['PHP_SELF']; ? method=POST

input type=hidden name=MAX_FILE_SIZE value=30 /
!-- Name of input element determines name in $_FILES array --
Cartoon: input name=userfile type=file /
input type=submit value=Upload File /
/form

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



Re: [PHP] Image upload form

2005-06-15 Thread Jack Jackson



Richard Davey wrote:

Hello Jack,

Wednesday, June 15, 2005, 5:38:11 PM, you wrote:

JJ newfile returns: 0fdae2e9e6aa43f067a9dd780a5a36a6.jpg
JJ image_file returns:
JJ images/jpg/test/0fdae2e9e6aa43f067a9dd780a5a36a6.jpg

JJ images/jpg/test is set to 777 but I still get (Could not move file to
JJ destination).  What am I missing? Thanks!

This directory needs to be absolute - i.e. the COMPLETE path:

/usr/home/jack/images/jpg/test




Thanks, Richard,

Still no soap: I changed

  $uploaddir = /home/jack/public_html/amyportnoy/images/jpg/test;

and
  $image_file = $uploaddir . '/' . $newfile;

Now $image_file returns the valid path of:

/home/jack/public_html/amyportnoy/images/jpg/test/09992d5379dd0a0cf376aab82241a66d.jpg

but it still  does not copy the file to that location. However the error 
has changed:


 if (is_uploaded_file($newfile)) {

 if(!move_uploaded_file($newfile,$image_file)) {

 echo 'Could not move file to destination';
 exit;
 }

 else {
 echo 'image file ?php echo $newfile ? uploaded.';
  }

 }

 else {
echo 'Problem with ' . $newfile;
  }

  }
And I'm getting an error message of Problem with 
6a26590fb45fd86e58954ba91d5580a4.jpg


So i guess it's not uploading for some reason?

Here's the whole thing I have so far once again, with several mods:



?php

error_reporting(E_ALL);

  $uploaddir = /home/jack/public_html/amyportnoy/images/jpg/test;

  print_r($_FILES);


  if ($_FILES['userfile']['error']  0) {

echo 'Problem: ';

switch ($_FILES['userfile']['error']) {
  case 1:
	 echo 'File exceeds maximum upload size limit 
(upload_max_filesize).';

 break;
  case 2:
 echo 'File exceeds maximum size limit (max_file_size).';
 break;
  case 3:
 echo 'File was only partially uploaded.';
 break;
  case 4:
 echo 'No file was uploaded.';
 break;

  }//end switch

  }//end if error 0

  $local_file = $_FILES['userfile']['tmp_name'];

if (sizeof($local_file))
  {

//try to get image size; this returns false if this is not an actual 
image file.

  $image_test = getimagesize($local_file);

if ($image_test !== false) {
   $mime_type = $_FILES['userfile']['type'];
   switch($mime_type) {
   case image/jpeg:
   $pext = 'jpg';
   break;
   case image/tiff:
   $pext = 'tif';
   break;
   default:
		   echo The file you are trying to upload is an image, but it is not 
a tif or jpeg and therefore unacceptable.;	

   }
} else {
   echo The file you are trying to upload is not a valid image file;
}

 $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext;

 $image_file = $uploaddir . '/' . $newfile;

// print_r($newfile);
 print_r($image_file);


 if (is_uploaded_file($newfile)) {

 if(!move_uploaded_file($newfile,$image_file)) {

 echo 'Could not move file to destination';
 exit;
 }

 else {
 echo 'image file ' . $newfile . 'uploaded.';
  }

 }

 else {
echo 'Problem with ' . $newfile;
  }

  }

  ?

  form enctype=multipart/form-data action=?php echo 
$_SERVER['PHP_SELF']; ? method=POST

input type=hidden name=MAX_FILE_SIZE value=30 /
!-- Name of input element determines name in $_FILES array --
Cartoon: input name=userfile type=file /
input type=submit value=Upload File /
/form



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



Re: [PHP] Image upload form

2005-06-15 Thread Jack Jackson

Yes, Jason,
Those did it!

Thanks so much for the help!



Jason Wong wrote:

On Thursday 16 June 2005 00:38, Jack Jackson wrote:



//try to get image size; this returns false if this is not an actual
image file.
  $image_test = getimagesize($local_file);
if ($image_test !== false) {
   $mime_type = $_FILES['userfile']['type'];



$_FILES['userfile']['type'] contains the mime-type that is provided by the 
browser and will vary depending on browser and hence extremely 
unreliable.


In fact the returned value from getimagesize() already has mime-type info, 
use that instead.




 $newfile = md5(date(l-F-j-Y i:s)).'.'.$pext;

 $image_file = $uploaddir . $newfile;

// print_r($newfile);
// print_r($image_file);

 if(!move_uploaded_file($newfile,$image_file)) {

 echo 'Could not move file to destination';
 exit;
 }



The file pointed to by $newfile doesn't exist. You need to move ...



  $local_file = $_FILES['userfile']['tmp_name'];



... $localfile




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



Re: [PHP] Checkboxes From Intersection Redux

2005-06-15 Thread Jack Jackson

That did it exactly, Kristen
Thanks so much for the help! (and sorry for sending this to you and not 
the list the first time!)




JJ

Kristen G. Thorson wrote:

Hopefully I understand your question correctly.

You have this SQL:

$media_query = 'SELECT media_id,media_name FROM media GROUP BY media_name';

And

For every media_id which is associated with $cartoon in the table 
media_art, check the box; for all others leave them unchecked.


The problem is, the SQL you have is not returning every media_id 
(because you're grouping on media_name).  I wonder if you truly need to 
group on media_name.  I would assume that media_name is unique in the 
media table.   If it is not, then you need to rethink your table 
structure.  If you group on media_name and there are duplicate 
media_names, you can have data like this:


media_id media_name
4Name1
16   Name1

Grouping by media_name as in your query above will produce a line like:

media_idmedia_name
4   Name1

You then output this to check boxes and use those to set the relation to 
art and media.  But what's the difference between media_id 4 and 
media_id 16?  In this case, if the database always returns the group by 
this way, you would never set the media_id 16.  If there is a distinct 
difference between media_names with different ids, then I think you 
probably need to make some changes.


That being said, if you do not need to group by media_name, then you can 
simply do something like this:


select media.media_id, media.media_name, media_art.art_id, from media 
left join media_art on media_art.media_id=media.media_id and 
media_art.art_id=$cartoon['art_id']


Which would return a table like this if $cartoon['art_id']=15:

media_idmedia_name art_id
4   Name1  NULL
8   Name2  15
12  Name3  NULL
16  Name4  15
17  Name5  NULL
18  Name6  NULL

You could then test the output of art_id:

$checkbox_media[] = input type='checkbox' name='media_types[]' 
value='{$media_rows['media_id']}' 
.(rows['art_id']==$cartoon['art_id']? 
checked:)./{$media_rows['media_name']}  ;



HTH
kgt





Jack Jackson wrote:


Hi,
With your help I got some checkboxes generated the other day for a 
form. I would like some help getting a similar problem solved.


I am now making a form to edit db entries made in the previous form. I 
have three tables involved: art, media and media_art. I need to show 
checkboxes for all available media. For the chosen record ($cartoon, 
which equals an art_id selected by the user) I must also go into the 
media_art table, and where the selected art ID has a corresponding 
media_id, display that media_id's media_name as a checked box.


TABLE media:
media_id   media_name
   1   ink
   2   pencil
   3   watercolor
   4   gauche
   5   watercolor pencil


To find out the art_id of the chosen record, the user is selecting 
from a dropdown box in the form. I'm doing queries like this to make a 
publisher dropdown in a similar vein:


$query = SELECT * FROM art WHERE art.art_id = '$cartoon';
$publisher_query = 'SELECT * FROM publisher';
$result = mysql_query($query);
$publisher_result = mysql_query($publisher_query);

while ($rows = mysql_fetch_assoc($result)){

 $publisher_dropdown = 'select name=publisher_id';
while ($pub = mysql_fetch_assoc($publisher_result)){
$publisher_dropdown .= 'option value=' . $pub['publisher_id'];
if ($pub['publisher_id'] == $rows['publisher_id']){
$publisher_dropdown .= '  selected ';
}
  $publisher_dropdown .= '' . htmlentities($pub['publisher_name']);
 }
  $publisher_dropdown .= '/select';
}



I now need to formulate how to make the checkboxes similarly. The 
original setup to make the checkboxes was :


$media_query = 'SELECT media_id,media_name FROM media GROUP BY 
media_name';

$media_result = mysql_query($media_query);

$checkbox_media = array ();
$media_types = array();
while ($media_rows = mysql_fetch_assoc($media_result)){
$checkbox_media[] = input type='checkbox' 
name='media_types[]' value='{$media_rows['media_id']}' 
/{$media_rows['media_name']}  ;

}

Those which were checked were inserted into media_art thusly:


media_id art_id
  31
  41
  51

What I want to do is say For every media_id which is associated with 
$cartoon in the table media_art, check the box; for all others leave 
them unchecked.


How can I do this?
Thanks very much in advance,

Jack








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



[PHP] Checkboxes From Intersection Redux

2005-06-14 Thread Jack Jackson

Hi,
With your help I got some checkboxes generated the other day for a form. 
I would like some help getting a similar problem solved.


I am now making a form to edit db entries made in the previous form. I 
have three tables involved: art, media and media_art. I need to show 
checkboxes for all available media. For the chosen record ($cartoon, 
which equals an art_id selected by the user) I must also go into the 
media_art table, and where the selected art ID has a corresponding 
media_id, display that media_id's media_name as a checked box.


TABLE media:
media_id   media_name
   1   ink
   2   pencil
   3   watercolor
   4   gauche
   5   watercolor pencil


To find out the art_id of the chosen record, the user is selecting from 
a dropdown box in the form. I'm doing queries like this to make a 
publisher dropdown in a similar vein:


$query = SELECT * FROM art WHERE art.art_id = '$cartoon';
$publisher_query = 'SELECT * FROM publisher';

$result = mysql_query($query);
$publisher_result = mysql_query($publisher_query);

while ($rows = mysql_fetch_assoc($result)){

 $publisher_dropdown = 'select name=publisher_id';
while ($pub = mysql_fetch_assoc($publisher_result)){
$publisher_dropdown .= 'option value=' . $pub['publisher_id'];
if ($pub['publisher_id'] == $rows['publisher_id']){
$publisher_dropdown .= '  selected ';
}
  $publisher_dropdown .= '' . htmlentities($pub['publisher_name']);
 }
  $publisher_dropdown .= '/select';
}



I now need to formulate how to make the checkboxes similarly. The 
original setup to make the checkboxes was :


$media_query = 'SELECT media_id,media_name FROM media GROUP BY media_name';
$media_result = mysql_query($media_query);

$checkbox_media = array ();
$media_types = array();
while ($media_rows = mysql_fetch_assoc($media_result)){
		$checkbox_media[] = input type='checkbox' name='media_types[]' 
value='{$media_rows['media_id']}' /{$media_rows['media_name']}  ;

}

Those which were checked were inserted into media_art thusly:


media_id art_id
  31
  41
  51

What I want to do is say For every media_id which is associated with 
$cartoon in the table media_art, check the box; for all others leave 
them unchecked.


How can I do this?
Thanks very much in advance,

Jack

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



Re: [PHP] Optimizing Help

2005-06-14 Thread Jack Jackson

Jochem,
I cannot believe you spent this much time helping me with this. I really 
appreciate it. I will go through and make ALL those changes. I am 
grateful. Especially the changes which cleaned up jibberish and 
tightened from several lines to one - really! Thank you thank you thank you!


--JJ

Jochem Maas wrote:

jack jackson wrote:


Hello,
Recently with the help of several of you I got a script working. It's
complex, I'm still new, some parts of it came from other authors and I
adapted it, and generally despite the fact that it seems to work
perfectly at this point, I am certain that there is bloat, repetition
and simply useless crap.

I'd like to know if anyone can have a look and help me optimize what I
have. For example, there are several mysql queries - would it be
possible to combine them somehow? I use the image upload section twice
because I couldn't figure out how to make it work using different vars
within the same section. That kind of newbie stuff.

The code is here: http://hashphp.org/pastebin.php?pid=3701




# ?php
#
#  require_once('nscfg.php');
#
#  //Initialize vars
#  $query = '';
#  $dropdown = '';
#  $result = 0;
#  $errors = array();
#  $msgArray  = array();
#  $msgText = '';

be neat, it helps:

$query  = '';
$dropdown= '';
$result  = 0;

#
#   $query = 'SELECT art.*,publisher.*
# FROM art,subject,publisher,series
# GROUP BY publisher_name';

make good (ab)use of alignment (your style may differ ;-)

$query = 'SELECT art.*,
 publisher.*
  FROM art,
   subject,
   publisher,
   series
  GROUP BY publisher_name';

// ps - why is 'series'  'subject' in there?

#
#   $subject_query = 'SELECT art.*,subject.*
# FROM art,subject
# GROUP BY subject_name';
#
#   $series_query = 'SELECT art.*,series.*
# FROM art,series
# GROUP BY series_name';
#
#   $media_query = 'SELECT media_id,media_name
# FROM media
#   GROUP BY media_name';
#
#  $result = mysql_query($query);
#  $media_result = mysql_query($media_query);
#  $subject_result = mysql_query($subject_query);
#  $series_result = mysql_query($series_query);
#

instead of creating 4 result identifiers, run and loop thru 1 at a time,
its allows you to reuse a single $result var (as well as being better in 
other ways)


#  $dropdown_publishers = 'select name=publisher';
#  while ($rows = mysql_fetch_assoc($result)){
#  $dropdown_publishers .= 'option value=' . $rows['publisher_id'] 
. '' . htmlentities($rows['publisher_name']);

#  }
#  $dropdown_publishers .= '/select';


here is a candidate for a function:

buildOptionList($name, $result, $valKey, $nameKey)
{
while ($row = mysql_fetch_assoc($result)) {
$dropdown[] = 'option value='
. htmlentities($row[$valKey], ENT_QUOTES)
 . ''
. htmlentities($row[$nameKey], ENT_QUOTES)
. '/option'; // options have closing tags
}

return 'select name=' . $name . '' .
   join('',$dropdown) . '/select';
}

#
#
#  $dropdown_subject = 'select name=subject';
#  while ($rows = mysql_fetch_assoc($subject_result)){

 ^- white space?

#  $dropdown_subject .= 'option value=' . $rows['subject_id'] . 
'' . htmlentities($rows['subject_name']);

#  }
#  $dropdown_subject .= '/select';
#
#  $dropdown_series = 'select name=seriesoption value=Select A 
Series/option';

#  while ($rows = mysql_fetch_assoc($series_result)){
#  $dropdown_series .= 'option value=' . $rows['series_id'] . '' 
. htmlentities($rows['series_name']);

#  }
#  $dropdown_series .= '/select';
#
#  $checkbox_media = array ();
#  $media_types = array();
#   while ($media_rows = mysql_fetch_assoc($media_result)){
#   $checkbox_media[] = input type='checkbox' name='media_types[]' 
value='{$media_rows['media_id']}' /{$media_rows['media_name']}  ;

#   }
#
#  ///IMAGE SECTION - MAIN IMAGE (IMAGE UPLOAD SCRIPT COPYRIGHT INFO IN 
CFG FILE)

#  ///THIS SECTION Copyright (c) 2000 Marcus Kazmierczak, [EMAIL PROTECTED]
#  if ($REQUEST_METHOD == POST)
#  {
#  $uploaddir = images/jpg;
#
#  /*== checks the extension for .jpg or .tiff ==*/
#  $pext = getFileExtension($imgfile_name);

TURN OFF register_globals, and access the $_FILES array instead.

#
#  $pext = strtolower($pext);
#
#
#  //If main image don't match extentions
#   if (empty($POST['imgfile'])) {
#   $errors[] = 'Please select an image. This is sort of the whole 
point, yes?';


your error checking for whether the image was actually uploaded is 
non-existent,
check the manual (+usernotes) for guidelines on how to check whether 
anything

made it thru.

#   }
#
#   if (($pext != jpg)   ($pext != jpeg)  ($pext != tif)  
($pext != tiff))

#  {

or maybe:

$validExtensions = array(jpg,jpeg,tif,tiff);

if (!in_array($pext, $validExtensions)) { /* bad */ }

/*

having said that the file extension doesn't say anything - better to use

[PHP] Optimizing Help

2005-06-13 Thread jack jackson
Hello,
Recently with the help of several of you I got a script working. It's
complex, I'm still new, some parts of it came from other authors and I
adapted it, and generally despite the fact that it seems to work
perfectly at this point, I am certain that there is bloat, repetition
and simply useless crap.

I'd like to know if anyone can have a look and help me optimize what I
have. For example, there are several mysql queries - would it be
possible to combine them somehow? I use the image upload section twice
because I couldn't figure out how to make it work using different vars
within the same section. That kind of newbie stuff.

The code is here: http://hashphp.org/pastebin.php?pid=3701

Thanks in advance!

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



Re: [PHP] Optimizing Help

2005-06-13 Thread jack jackson
Thanks, Chris,  I see what you're getting at. I'm not sure I
understand what you mean about looping through the array in the area
you specified- isn't that just the definitions of the vars? Or is that
what you meant and I'm missing the point!!?



On 6/13/05, Chris Ramsay [EMAIL PROTECTED] wrote:
 Hey there Jackson,
 
 The first thing I would consider would be to see if you can classify
 the code into chunks that do a certain job, and then rewrite them as
 functions. I would also consider looping through arrays for repetitive
 jobs (lines 258 - 270 for example).
 
 Down the line you could consider the use of classes, your own or ready
 made -  such as the ever useful PEAR (http://pear.php.net). I
 personally found that the greatest saver of time to be the re-use of
 code that I know works well for given situations.
 
 HTH
 
 Chris


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



[PHP] Three queries. One Form.

2005-06-09 Thread jack jackson
Hi, 
I am trying to make one form on a single page insert info into three
tables; query 1 creates an art_id (auto-increment) for the newly
created row in table art;

query2 creates a media_id in table media. 

Then I need to get the art_id and media_id created by the first two
queries to insert into an intersection table as query three.

Must I run an intermediate query to get the ids, and assign it to
vars? What would it even look like?

Thanks in advance,

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



Re: [PHP] Three queries. One Form.

2005-06-09 Thread jack jackson
On 6/9/05, Matt Babineau [EMAIL PROTECTED] wrote:
 Well after the first query you could do this:
 
 $art_id = mysql_insert_id();
 
 There is your new unique art_id you just created.
 
 Do this for the next table, the do the insert on your 3rd table.

Thanks, Matt!


 
 
 Matt Babineau
 Criticalcode
 w: http://www.criticalcode.com
 p: 858.733.0160
 e: [EMAIL PROTECTED]
 
 -Original Message-
 From: jack jackson [mailto:[EMAIL PROTECTED]
 Sent: Thursday, June 09, 2005 4:06 PM
 To: php-general@lists.php.net
 Subject: [PHP] Three queries. One Form.
 
 Hi,
 I am trying to make one form on a single page insert info into three tables;
 query 1 creates an art_id (auto-increment) for the newly created row in
 table art;
 
 query2 creates a media_id in table media.
 
 Then I need to get the art_id and media_id created by the first two queries
 to insert into an intersection table as query three.
 
 Must I run an intermediate query to get the ids, and assign it to vars? What
 would it even look like?
 
 Thanks in advance,
 
 --
 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
 


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



Re: [PHP] Three queries. One Form.

2005-06-09 Thread jack jackson
Thanks for this Richard!


On 6/9/05, Richard Davey [EMAIL PROTECTED] wrote:
 Hello jack,
 
 Friday, June 10, 2005, 12:05:35 AM, you wrote:
 
 jj I am trying to make one form on a single page insert info into three
 jj tables; query 1 creates an art_id (auto-increment) for the newly
 jj created row in table art;
 
 jj query2 creates a media_id in table media.
 
 jj Then I need to get the art_id and media_id created by the first two
 jj queries to insert into an intersection table as query three.
 
 Assuming MySQL - just use 2 insert statements and after each one get
 the last_insert_id. Once you've got both of those you can perform your
 third and final insert using both of those values.
 
 Best regards,
 
 Richard Davey
 --
  http://www.launchcode.co.uk - PHP Development Services
  I do not fear computers. I fear the lack of them. - Isaac Asimov
 
 --
 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



[PHP] Getting checkboxes as array

2005-06-09 Thread jack jackson
HI I have a form which pulls values from the db, and thanks to help
from the irc chat, hopefully makes any checkboxes which are selected
part of an array to be gotten in post:

while ($media_rows = mysql_fetch_assoc($media_result)){
  
$checkbox_media[] = input type='checkbox' name='media_types[]'
value='{$media_rows['media_id']}' /{$media_rows['media_name']}  ;
}

I'd like to now add the value of any checked box to an intersection
table based on my last question to the list:

$art_id = mysql_insert_id();

What I'd like to end up with is  something which for each value in
media_types[] create a New row in the intersection table (media_art)

However how can I make this:

$query = INSERT INTO media_art (media_art_id,art_id, media_id) 
VALUES ('',' . $art_id . ',' . $media_types[2]. ');  

repeat as many or few times as possible to account for the number of
checked boxes, such as

$art_id $media_types[5]
$art_id $media_types[9]

etc

I suspect it's something to do with the foreach but I'm stuck in
figuring it out.

Thanks in advance!


$media_types[] = ($_POST['media_types[]']);

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



Re: [PHP] Getting checkboxes as array

2005-06-09 Thread jack jackson
Thank you Sebastian! Saved me some hell there!!

On 6/9/05, Sebastian [EMAIL PROTECTED] wrote:
 Don't forget to mention that even if you don't select a checkbox it will
 still add a empty record to the db.. i know for sure the foreach loop
 will add a record even if a box is not check, so you have to check its
 actually set before you start inserting.
 
 Richard Davey wrote:
 
 Hello jack,
 
 Friday, June 10, 2005, 2:16:06 AM, you wrote:
 
 jj $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 jj VALUES ('',' . $art_id . ',' . $media_types[2]. ');
 
 jj repeat as many or few times as possible to account for the number of
 jj checked boxes, such as
 
 One way:
 
 for ($i = 0; $i  count($media_types); $++)
 {
 $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 VALUES ('','$art_id','{$media_types[$i]}');
 // perform query here
 }
 
 Another:
 
 foreach ($media_types as $type)
 {
 $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 VALUES ('','$art_id','$type');
 // perform query here
 }
 
 Best regards,
 
 Richard Davey
 
 
 
 --
 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] Getting checkboxes as array

2005-06-09 Thread jack jackson
Whoops. I must be botching this syntax because this is printing 


,,0,, as the query:

All the first part of the query works and inserts records into the
database, and it's when I try to get mysql_insert_id () that I seem to
run into trouble. Ah. ave I not yet run the first query? The part of
the code that actually runs it was given to me in a class and I don't
quite understand how it's suppose to be working ...
Thanks in advance:

$trimblog = (trim($_POST['blog']));
$blog = (nl2br($trimblog));
$image = mysql_real_escape_string($final_imgname); 
$image_thb = mysql_real_escape_string($final_thb_filename);
$pubwidth = mysql_real_escape_string(trim($_POST['art_width']));
$pubheight = mysql_real_escape_string(trim($_POST['art_height']));
$origwidth = mysql_real_escape_string(trim($_POST['orig_width']));
$origheight = mysql_real_escape_string(trim($_POST['orig_height']));
$publisher = mysql_real_escape_string(trim($_POST['publisher']));
$series = mysql_real_escape_string(trim($_POST['series']));
$subject = mysql_real_escape_string(trim($_POST['subject']));
$title = mysql_real_escape_string(trim($_POST['title']));
$caption = mysql_real_escape_string(trim($_POST['art_caption']));
$blog = mysql_real_escape_string($blog);
$keywords = mysql_real_escape_string(trim($_POST['keywords']));


$query = INSERT INTO art (art_id,art_thumbnail, art_image,
art_width, art_height, orig_width, orig_height, art_pub_date,
publisher_id, art_creation_date, series_id, subject_id, art_title,
art_caption, art_keywords, art_blog)
VALUES ('',' . $image_thb . ',' . $image . ',' . $pubwidth .
',' . $pubheight . ',' . $origwidth . ',' . $origheight . ','
.  $pubdate . ',' . $publisher . ',' . $orig_date . ',' .
$series . ',' . $subject . ',' . $title . ',' . $caption . ','
. $keywords . ',' . $blog . ');

$art_id = mysql_insert_id();
foreach ($media_types[] as $type)
{
  $query .= INSERT INTO media_art (media_art_id,media_id, 
art_id)
   VALUES ('',' . $type . ',' . $art_id . ');
   // perform query here
}

if (!mysql_query($query) || mysql_error($query)!= ''){
$errMsg = mysql_error($query);
trigger_error(Problem with addrecord: $query\r\n$errMsg\r\n, 
E_USER_ERROR);
  } else {

  $msgText = 'trtdstrongYour record was 
saved!/strong/td/tr';
  }
On 6/9/05, Richard Davey [EMAIL PROTECTED] wrote:
 Hello jack,
 
 Friday, June 10, 2005, 2:16:06 AM, you wrote:
 
 jj $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 jj VALUES ('',' . $art_id . ',' . $media_types[2]. ');
 
 jj repeat as many or few times as possible to account for the number of
 jj checked boxes, such as
 
 One way:
 
 for ($i = 0; $i  count($media_types); $++)
 {
 $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 VALUES ('','$art_id','{$media_types[$i]}');
 // perform query here
 }
 
 Another:
 
 foreach ($media_types as $type)
 {
 $query = INSERT INTO media_art (media_art_id,art_id, media_id)
 VALUES ('','$art_id','$type');
 // perform query here
 }
 
 Best regards,
 
 Richard Davey
 --
  http://www.launchcode.co.uk - PHP Development Services
  I do not fear computers. I fear the lack of them. - Isaac Asimov
 
 --
 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] Beautiful HTML Invoice - Prints like crap! I need some suggestions!

2005-06-07 Thread Jack Jackson
Matt Babineau wrote:

Hi all -

I've got a great html invoice that prints like crap because of my user of
background images and foreground images. Does anyone have any good
suggestions other than turn on images in IE to get this thing to print the
graphics? Is there a good way I could convert the HTML view to a JPG? I'm on
a linux box and have php 4.3.10.

Thanks for the help!

Matt Babineau
Criticalcode
w: http://www.criticalcode.com
p: 858.733.0160
e: [EMAIL PROTECTED]


  

Make it a pdf?

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



Re: [PHP] Beautiful HTML Invoice - Prints like crap! I need some suggestions!

2005-06-07 Thread Jack Jackson
Matt Babineau wrote:

Hi all -

I've got a great html invoice that prints like crap because of my user of
background images and foreground images. Does anyone have any good
suggestions other than turn on images in IE to get this thing to print the
graphics? Is there a good way I could convert the HTML view to a JPG? I'm on
a linux box and have php 4.3.10.

Thanks for the help!

Matt Babineau
Criticalcode
w: http://www.criticalcode.com
p: 858.733.0160
e: [EMAIL PROTECTED]


  

Sorry, more helpful:http://us4.php.net/pdf

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



Re: [PHP] linux php editor

2005-06-06 Thread Jack Jackson



Clive Zagno wrote:
what php GUI editors do you recommend. Ive used bluefish before, any 
other recommendations, thanks


clive


I love Jedit http://www.jedit.com

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



[PHP] Implode? Explode?

2005-06-06 Thread Jack Jackson

Hi all,
I'm trying to fetch similar things - in this case, rows which share a 
series ID no - and bring them into an array and display them grouped by 
 what makes them similar (in this case, series id). I looked at implode 
and explode which seem wrong for this - the only separator I can see is 
that they're each in a table cell.


The result of my query returns something like:

art_id   series_id art_titleseries_name
2   1  Weddings 2004Summer Special
4   1  Summer In The City   Summer Special
5   2  Bags of NY   Op-Art
7   2  Dogs of NY   Op-Art


I'd like to create a list of links to each art_id grouped together as 
series, href code obviously not complete but demonstrative:


pSummer Specialbr /
a href='2'Weddings 2004/a | a href='4'Summer In The City/p

pOp-Artbr /
a href='5'Bags of NY/a | a href='7'Dogs of NY/p


?

Thanks in advance,
Jack

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



Re: [PHP] Implode? Explode?

2005-06-06 Thread Jack Jackson



Brent Baisley wrote:
You're close, but you need to group your data on the series_id first. 
You can do that by looping through your array and creating another array 
using series_id as the array key. You'll end up with a list of arrays 
named after the series_id.


foreach( $result_set as $result_item ) {
//Add an array item to the series_id slot of the grouped_result array
$grouped_result[ $result_item['series_id'] ][]= 
array('id'=$result_items['art_id'], 'title'=$result_item['art_title']);

}


That did the trick, Brent. Thanks so much for this useful information.

Now you have your data grouped by series_id. Each item of the 
grouped_result array will contain one or more arrays which contain the 
art_id and art_title.


If you are not familiar with multidimensional arrays, this may be a 
little confusing.


A little is right! But tanks for the intro to multi-dimensional arrays!

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



Re: [PHP] ampersands in href's

2005-06-05 Thread Jack Jackson

Thanks!

Leon Poon wrote:
The simplest way to make sure everything work well regardless of what 
the values are:


?
$url = somepage.php?var1=.urlencode($var1).var2=.urlencode($var2);
echo a href=\.htmlspecialchars($url).\;
?

htmlspecialchars() changes characters '', '', ''', '', '' into the 
HTML equivilant. And yup, you should do this for all *ML pages as long 
as the thing being printed is not part of the mark-up syntax.




Jack Jackson wrote:


Rory Browne wrote:


On 6/4/05, Jack Jackson [EMAIL PROTECTED] wrote:


Hi, Rory

Rory Browne wrote:


I think you have the idea. The 's are used to seperate the various
variables. If you want to set $p to something like 'Tom  Jerry' then
personally I'd do something like:

?php

$p = Tom  Jerry;
$s = Cat  Mouse;
printf(a href='{$_SERVER['PHP_SELF']}?p=%ss=%s, urlencode($p),
urlencode($s));

?


That's nice. To get more specific (because my code varies a bit from
yours and I don't wanna mess up the ) and ' and  s:
$p and $c are actually row ID numbers so up to 3 digits. So for 
example if


$p=1
$c=32

I was wanting to see a URL of

http://foo.com?r=1c=32



In that case, you can simply echo them out, once you're sure that $r,
and $c are actually integers.



I forgot to mention that above I did $r = intval($_GET[r])

!



Thanks, everyone!


echo a href='http://foo.com?r=$rc=$c'whatever/a

if not(sure they're integers, you could always
printf(a href=\http://foo.com?r=%dc=%d\;whatever/a, $r, $c);

Alternatively you could $r = (int)$r;

or echo a href='http://foo.com?r=; . (int)$r . c= . (int)$c .
'whatever/a;

There's more than one way to do it...


so was this the way to go?


//Make a thumbnail table of contents to display in the left sidebar

while ($sidebar = mysql_fetch_assoc($sidebar_result)) {
   $sidebar_thumbnails[] = a class='img-link'
href='{$_SERVER['PHP_SELF']}?p=%pc={$sidebar['art_id']}, 
urlencode($p)'

title=\{$sidebar['art_title']}\img class='sidebar-img'
src='{$image_dir}{$sidebar['art_thumbnail']}' width='50' height='60'
border='0' alt=\{$sidebar['art_title']}\ //a;
  }

?

Thanks in advance!




On 6/4/05, Jack Jackson [EMAIL PROTECTED] wrote:



Hi,

If I want to make a link to a URL which includes some GETs can I 
just do:


a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc

or must I escape the ampersand somehow?

TIA,
--Jack

--
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








--
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



[PHP] looping through an array problem

2005-06-05 Thread Jack Jackson

This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul;

  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed here?

Thanks in advance!

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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
Thanks for all the replies. Jochem, thank you for this code, which will 
take me all night to understand (though I bet it works). I also note 
that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a fly 
in the ointment.


Thanks all!



Jochem Maas wrote:

Jack Jackson wrote:


This is something dumb I am doing but:

Trying to pull all names of publishers in db. This sql:



its a mysql question in disguise, maybe...:

SELECT DISTINCT art.art_id,art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_iduse, 


on the other hand if you want to pull every article
from the DB then that won't do it. maybe you
need to be extracting the name of the article instead/aswell?

on the other hand if you are trying to display a list of
publishers, why are you selecting from the arts table?

SELECT p.publisher_id,p.publisher_name
FROM publisher p ORDER BY p publisher_id DESC

(maybe you only want to show publishers with listed 'art's?)

what does this do for you?:

SELECT COUNT(a.art_id) as art_count,a.publisher_id,p.publisher_name
FROM art a, publisher p
WHERE p.publisher_id=a.publisher_id
AND art_count  0
GROUP BY a.publisher_id


SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

pulls (in phpmyadmin) four rows:
  artID  pubID Publisher_name
  17   The New York Times: Sunday Styles
  23   The New York Sun
  32   Metro NY
  43   The New York Sun


I'm trying to make a sidebar which will make links to each unique 
publisher name:




and/or something like.:

?php

// $result   = DB::doMagic();

$seenAlready = array();
$templet = 'ul class=sidebar-menua class=img-link href='
 . $_SERVER['PHP_SELF']
 . '?p=%1$s title=%2$s%2$s/a/ul';

while ($cartoon = mysql_fetch_assoc($result)) {
if (in_array($cartoon['publisher_id'], $seenAlready))
continue;

$seenAlready[] = $cartoon['publisher_id'];
$pub_sidebar[] = sprintf($templet,
 $cartoon['publisher_id'],
 $cartoon['publisher_name']);
}


while ($cartoon = mysql_fetch_assoc($result)) {
 $pub_sidebar[] = ul class='sidebar-menu'a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}' 
title=\{$cartoon['publisher_name']}\{$cartoon['publisher_name']}/a/ul; 


  }


This prints:
  The New York Times: Sunday Styles

  The New York Sun

  Metro NY

  The New York Sun


I'd like to stop the NY Sun from appearing twice! What have i missed 
here?


Thanks in advance!







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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson



M. Sokolewicz wrote:

Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.


by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...


Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.


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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
Forgive me if this comes twice: my ISP had a service blackout for three 
hours and I don't know what went:



If my last post read (and I see that it did) that I was defending myself
as opposed to falling ALL OVER my sword, I apologize: allow me to be clear:

No, you're all correct and M. Sokolewicz doubly so: I had
unintentionally selected fields from the wrong table for no reason other
than  lack of sleep coupled with lack of experience and a desperation to
try to understand

The problem was that I was pulling data in a manner both useless and
complex from a thoroughly unnecessary table (I could tell you all why
but you'll all just laugh at me more)

I am grateful for all the help everyone has offered up to now and hope I
did not offend  - I was trying in my last post to indicate that I  was
an idiot, and it appears I've come off as arrogant. I promise it was not
my intent!


[Then I wrote::]

Ah. I just remembered one reason I had done it involving the art_id field:

I have more publishers in the db than are currently associated with 
artworks. I don't want a publisher to appear unless there is at least 
one image associated with it. So I did this to avoid having people see a 
link to the Sneezy Acres Tribune only to arrive at the next page and 
see, There are no images associated with this publisher.




Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson

Ah. I just remembered one reason I had done it involving the art_id field:

I have more publishers in the db than are currently associated with 
artworks. I don't want a publisher to appear unless there is at least 
one image associated with it. So I did this to avoid having people see a 
link to the Sneezy Acres Tribune only to arrive at the next page and 
see, There are no images associated with this publisher.





Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



Re: [PHP] looping through an array problem

2005-06-05 Thread Jack Jackson
If my last post read (and I see that it did) that I was defending myself 
as opposed to falling ALL OVER my sword, I apologize: allow me to be clear:


No, you're all correct and M. Sokolewicz doubly so: I had 
unintentionally selected fields from the wrong table for no reason other 
than  lack of sleep coupled with lack of experience and a desperation to 
try to understand


The problem was that I was pulling data in a manner both useless and 
complex from a thoroughly unnecessary table (I could tell you all why 
but you'll all just laugh at me more)


I am grateful for all the help everyone has offered up to now and hope I 
did not offend  - I was trying in my last post to indicate that I  was 
an idiot, and it appears I've come off as arrogant. I promise it was not 
my intent!






Jochem Maas wrote:

Jack Jackson wrote:




M. Sokolewicz wrote:


Jack Jackson wrote:

Thanks for all the replies. Jochem, thank you for this code, which 
will take me all night to understand (though I bet it works). I also 
note that SELECT DISTINCT worked here, too


Also as many of you noticed before me, the art_id was in there as a 
fly in the ointment.




by that statement I ment the exact same thing Jochem ment in his 2nd 
part; I have NO idea why you're selecting *ANYTHING* from the arts 
table... it's *useless* if you don't need the data...




Er, yes, that was what I meant: I had unintentionally included that 
bit.Thank you for your help.




Er, Jack - your original query was:

SELECT art.art_id,art.publisher_id,publisher.publisher_name,
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

which is a selection on the art table... ( with a typo)
if you did:

SELECT art.publisher_id,publisher.publisher_name
FROM art
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id

nothing would change. and if you did:

SELECT publisher.publisher_id,publisher.publisher_name
publisher

i.e. not 'unintentionally' selecting from the arts table.
then you would not have had a problem in the first place?!

I think I'm missing something ;-)



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



[PHP] ampersands in href's

2005-06-04 Thread Jack Jackson

Hi,

If I want to make a link to a URL which includes some GETs can I just do:

a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc

or must I escape the ampersand somehow?

TIA,
--Jack

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



Re: [PHP] ampersands in href's

2005-06-04 Thread Jack Jackson

Hi, Rory

Rory Browne wrote:

I think you have the idea. The 's are used to seperate the various
variables. If you want to set $p to something like 'Tom  Jerry' then
personally I'd do something like:
 
?php 


$p = Tom  Jerry;
$s = Cat  Mouse;
printf(a href='{$_SERVER['PHP_SELF']}?p=%ss=%s, urlencode($p),
urlencode($s));

?



That's nice. To get more specific (because my code varies a bit from 
yours and I don't wanna mess up the ) and ' and  s:

$p and $c are actually row ID numbers so up to 3 digits. So for example if

$p=1
$c=32

I was wanting to see a URL of

http://foo.com?r=1c=32

so was this the way to go?


//Make a thumbnail table of contents to display in the left sidebar

while ($sidebar = mysql_fetch_assoc($sidebar_result)) {
	$sidebar_thumbnails[] = a class='img-link' 
href='{$_SERVER['PHP_SELF']}?p=%pc={$sidebar['art_id']}, urlencode($p)' 
title=\{$sidebar['art_title']}\img class='sidebar-img' 
src='{$image_dir}{$sidebar['art_thumbnail']}' width='50' height='60' 
border='0' alt=\{$sidebar['art_title']}\ //a;

  }

?

Thanks in advance!



On 6/4/05, Jack Jackson [EMAIL PROTECTED] wrote:


Hi,

If I want to make a link to a URL which includes some GETs can I just do:

a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc

or must I escape the ampersand somehow?

TIA,
--Jack

--
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] ampersands in href's

2005-06-04 Thread Jack Jackson



Murray @ PlanetThoughtful wrote:

If I want to make a link to a URL which includes some GETs can I just do:

a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc

or must I escape the ampersand somehow?



Depends very much on the document type of your page. Valid XHTML
(transitional, at least), for example, doesn't like single ampersands in a
href= links. For XHTML, you need to replace s with amp;s.

So the following link:

a href='http://www.somewhere.com/index.php?id1=1id2=2'Something/a

...should be changed to:

a href='http://www.somewhere.com/index.php?id=1amp;id=2'Something/a


Thank you Murray. The page is in xhtml  1.0/transitional. That was 
precisely what I was worried about. The amp; will be converted as part 
of the URL right? I mean, the printed URL resulting from clicking on 
that link won't say amp; it'll just say  is this correct? Combined 
with Rory's post this is really, really useful stuff and I thank you !


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



Re: [PHP] ampersands in href's

2005-06-04 Thread Jack Jackson



Rory Browne wrote:

On 6/4/05, Jack Jackson [EMAIL PROTECTED] wrote:


Hi, Rory

Rory Browne wrote:


I think you have the idea. The 's are used to seperate the various
variables. If you want to set $p to something like 'Tom  Jerry' then
personally I'd do something like:

?php

$p = Tom  Jerry;
$s = Cat  Mouse;
printf(a href='{$_SERVER['PHP_SELF']}?p=%ss=%s, urlencode($p),
urlencode($s));

?


That's nice. To get more specific (because my code varies a bit from
yours and I don't wanna mess up the ) and ' and  s:
$p and $c are actually row ID numbers so up to 3 digits. So for example if

$p=1
$c=32

I was wanting to see a URL of

http://foo.com?r=1c=32



In that case, you can simply echo them out, once you're sure that $r,
and $c are actually integers.


I forgot to mention that above I did $r = intval($_GET[r])

!



Thanks, everyone!


echo a href='http://foo.com?r=$rc=$c'whatever/a

if not(sure they're integers, you could always
printf(a href=\http://foo.com?r=%dc=%d\;whatever/a, $r, $c);

Alternatively you could $r = (int)$r;

or 


echo a href='http://foo.com?r=; . (int)$r . c= . (int)$c .
'whatever/a;

There's more than one way to do it...


so was this the way to go?


//Make a thumbnail table of contents to display in the left sidebar

while ($sidebar = mysql_fetch_assoc($sidebar_result)) {
   $sidebar_thumbnails[] = a class='img-link'
href='{$_SERVER['PHP_SELF']}?p=%pc={$sidebar['art_id']}, urlencode($p)'
title=\{$sidebar['art_title']}\img class='sidebar-img'
src='{$image_dir}{$sidebar['art_thumbnail']}' width='50' height='60'
border='0' alt=\{$sidebar['art_title']}\ //a;
  }

?

Thanks in advance!




On 6/4/05, Jack Jackson [EMAIL PROTECTED] wrote:



Hi,

If I want to make a link to a URL which includes some GETs can I just do:

a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc

or must I escape the ampersand somehow?

TIA,
--Jack

--
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








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



Re: [PHP] Site Design Strategy

2005-06-03 Thread Jack Jackson



asinning wrote:

This is my first post to this group.  I've been trying to figure this
out on my own, but I keep running into complications, so I've decided
to get some help.  Much thanks for any help!

I've been writing php server application for a couple of years, but now
I'm turning my attention to re-building our company's aging website.
This is a big project and is going to require a solid foundation.

At the crux of this post is the following question:  How do you develop
a very robust, dynamic web-site, but also allow non-technical people to
contribute? There must be an easier way.

Here are my working assumptions and my strategy.  Please help me if I'm
thinking down the wrong path.

Assumptions:

1) Non-technical people in the company need to be able to build pages,
and they should be able to post their pages without bothering me.  We
have a tech-support person who will be able to help them, but she has
zero programming knowledge and only a superficial understanding of
HTML.

2) Every page needs to reside within he shell of the web site.  This
includes

  header(the top-level menu)
  left-side menu (a dynamic, context-specific menu)
  content (this is what the non-technical people will produce)
  footer (your standard fare text-based links)

3) I don't want to use frames, and I don't want to use Dreamweaver
templates.

Strategy:  Currently, I am working on the following model:

 There is a top-level index.php page.  This is the target of EVERY
page on the site.

 The page that gets loaded in depends on the parameters of
query-string.  It's very simple, if the query string reads
?target=products/gsp, then my php will look for a site-relative
document such as products/gsp.htm OR products/gsp/index.hml.  Then,
this document will get included as the content in my shell.

 Well, this works to a degree, but it requires that people use
site-relative paths for all of their graphics and links, which is
way, way to much to ask.  After all, people are using WYSIWIG editors
such as Dreamweaver and even Word to build their pages.  Typically,
site-relative paths don't work in these environments.  They shouldn't
need to upload their document to preview it.

 It also requires that they put their page within a 550 pixel wide
-td- tag.  I'd love to drop that requirement.

So, now I considering the following:  A parser that will convert any
content into includable form.  Relative paths will be translated to
the site-root, etc.  I'm a bit stuck here.



Maybe I've misunderstood but here's a thought:

I'm not sure what they're actually doing with these pages but it's 
usually in my experience something like a headline, a block of text in 
which you can allow certain HTML tags (you can use tidy within PHP) and 
 some images and some links. Is there more that these folks are doing? 
Is there a reason to give them so much flexibility in design? Are these 
home pages as in personal showcases or department-specific offerings?


You probably want to set up each user with their own directory or db 
area so they can upload all their images through your control panel, 
enter their text and have everything in one place for each user.


If you give users the opportunity to put in unlimited matched sets of 
Headline, text block, image float right left or center (cna cation  if 
required) plus strong, em and a limited href capability 99% of 
people  will probably be happy. Make sure you rename all images they 
upload to remove spaces, weird characters and duplicate names. You can 
use a naming convention like user.image.x. or even md5(imagename).


So this way, each user gets a user directory in which all image links 
are relative to that directory, all images are righ there and ties to 
the user.



  It also requires that they put their page within a 550 pixel wide
 -td- tag.  I'd love to drop that requirement.

AAARG. We use a wrapper in XHTML, putting everything in div tags so 
that later, when we change the format, they're not stuck in a td as 
you rightly worry about. Using div and CSS positioning increases 
exponentially your flexibility both now and later. And requires fairly 
modern browsers but according to our logs almost everyone has them. And 
if they come in using lynx it'll still *work* in that they get all the 
info in sensible order. Netscape 4 and IE 4 users are out of luck, but 
then, they often are anyway in terms of support on the web (please let's 
not devolve into a flame war over that statement).



HTH and makes sense.





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



[PHP] Using GET to build multiple sql queries

2005-06-02 Thread Jack Jackson
 I'd love some help with http://hashphp.org/pastebin?pid=3443 if anyone 
can...


Basically I want to make it so that, if the get in the url specifies no 
query or a query to a nonexistent row, send to vanilla index. If url 
specifies c= then set $c=c and use the number to build the mysql query; 
same for p= and s= - if they're valid build  the query, if not kick em out.


Can anyone offer any help?

Thanks in advance!

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



[PHP] Delay?

2005-06-02 Thread Jack Jackson

Has anyone else noticed significant delays in messages getting posted?

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



Re: [PHP] Using GET to build multiple sql queries

2005-06-02 Thread Jack Jackson

Thanks for the reply, Greg,

I see how that is useful. I am confused as to how I would implement it 
here. Please bear with me as I am a newbie and am now perhaps more 
confused than ever!:


I'm trying to use the number given in the $_GET URL to build one piece 
of the sql:


If there is anything set in the $_GET field other than ?c=[valid int] or 
?p=[valid int] or ?s=[valid int] then I want to bounce to a plain index. 
If it's a valid int (a positive int which corresponds to a valid row) 
then I want to set its value to the appropriate variable: either $c, $p 
or $s, and thus set the values of $fields, $from and $where.



?php  //IF there is a valid query by cartoon, use $c to build the SQL
$fields = 'SELECT art.*,publisher.*,subject.*';
$from = 'FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id';
$sort = ORDER BY art.art_pub_date;
$where = WHERE art.art_id = '$c' AND
 subject.subject_id=art.subject_id;
?

If that were instead a $p then I would do:

?php   //IF there is a valid query by publisher, use $p to build the SQL
$fields = SELECT art.*,publisher.*,subject.*;
$from = FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id;
   $where = WHERE publisher.publisher_id=art.publisher_id AND
 art.publisher_id = '$p' AND
 subject.subject_id=art.subject_id;

?
If that were instead an $s then I would do:

?php  //IF there is a valid query by subject, use $s to build the SQL
$fields = SELECT art.*,publisher.*,subject.*;
$from = FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id;
   $where = WHERE publisher.publisher_id=art.publisher_id AND
 art.subject_id = '1' AND
 art.subject_id=subject.subject_id;
?

I'm sure your method works ( ;) ). If I understand it, as my friend 
Darrell said about your suggestion:


'...We iterate through the array seeing if there's a submitted HTML form 
field name that matches the current database column name. If so, we add 
the column name and the value submitted in the form to a string that is 
being built into a database query.'


I'm trying to see how this code lets me do that. I know it's right in 
front of my face but I cannot see how to adapt it to the task. .



Thanks in advance!!






Greg Donald wrote:

On 6/2/05, Jack Jackson [EMAIL PROTECTED] wrote:


 I'd love some help with http://hashphp.org/pastebin?pid=3443 if anyone
can...

Basically I want to make it so that, if the get in the url specifies no
query or a query to a nonexistent row, send to vanilla index. If url
specifies c= then set $c=c and use the number to build the mysql query;
same for p= and s= - if they're valid build  the query, if not kick em out.

Can anyone offer any help?



I'd iterate over the $_GET array to build the query elements.  Then
implode those elements.

$array = array();

while( list( $k, $v ) = each( $_GET ) )
{
if( $k == 'somekeynotindb' )
{
continue;
}

$array[] = $k . =' . $v . ';
}

if( $array )
{
$and = implode( ', ', $array );
}

$sql = 
SELECT *
FROM table
WHERE 1
$and
;

$query = mysql_query( $sql );




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



Re: [PHP] Using GET to build multiple sql queries

2005-06-02 Thread Jack Jackson

SORRY - one small correction below:

SNIP

If that were instead an $s then I would do:

?php  //IF there is a valid query by subject, use $s to build the SQL
$fields = SELECT art.*,publisher.*,subject.*;
$from = FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id;
   $where = WHERE publisher.publisher_id=art.publisher_id AND
 art.subject_id = '$s' AND
 art.subject_id=subject.subject_id;
?

/SNIP
I had accidentally put a number 1 in place of the $s in the above 
example. Apologies for the extra mail and thanks in advance.





Greg Donald wrote:

On 6/2/05, Jack Jackson [EMAIL PROTECTED] wrote:


 I'd love some help with http://hashphp.org/pastebin?pid=3443 if anyone
can...

Basically I want to make it so that, if the get in the url specifies no
query or a query to a nonexistent row, send to vanilla index. If url
specifies c= then set $c=c and use the number to build the mysql query;
same for p= and s= - if they're valid build  the query, if not kick em out.

Can anyone offer any help?



I'd iterate over the $_GET array to build the query elements.  Then
implode those elements.

$array = array();

while( list( $k, $v ) = each( $_GET ) )
{
if( $k == 'somekeynotindb' )
{
continue;
}

$array[] = $k . =' . $v . ';
}

if( $array )
{
$and = implode( ', ', $array );
}

$sql = 
SELECT *
FROM table
WHERE 1
$and
;

$query = mysql_query( $sql );




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



Re: [PHP] Using GET to build multiple sql queries

2005-06-02 Thread Jack Jackson

Greg, thank you for all this... See below

Greg Donald wrote:

On 6/2/05, Jack Jackson [EMAIL PROTECTED] wrote:


Thanks for the reply, Greg,

I see how that is useful. I am confused as to how I would implement it
here. Please bear with me as I am a newbie and am now perhaps more
confused than ever!:



Bummer, sorry.

Twasn't you; were me.





I'm trying to use the number given in the $_GET URL to build one piece
of the sql:

If there is anything set in the $_GET field other than ?c=[valid int] or
?p=[valid int] or ?s=[valid int] then I want to bounce to a plain index.



if( !(  isset( $_GET[ 'c' ] )  is_int( $_GET[ 'c' ] )
|| isset( $_GET[ 'p' ] )  is_int( $_GET[ 'p' ] )
|| isset( $_GET[ 's' ] )  is_int( $_GET[ 's' ] ) ) )
{
header( 'Location: index.php' );
exit;
}


Of course, that almost did it. But I wanted to do it it *weren't* an 
int. I put a ! in front and that works like a charm!




If it's a valid int (a positive int which corresponds to a valid row)
then I want to set its value to the appropriate variable: either $c, $p
or $s,



If it's in the URL it's already set as $_GET[ 'c' ], $_GET[ 'p' ], or
$_GET[ 's' ].


I get it. Thanks for that. Including it in the sql didn't work as you 
suggested:




?php  //IF there is a valid query by cartoon, use $c to build the SQL
$fields = 'SELECT art.*,publisher.*,subject.*';
$from = 'FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id';
$sort = ORDER BY art.art_pub_date;
$where = WHERE art.art_id = '$c' AND



WHERE art.art_id = '$_GET[c]'


I guess it was missing a print command or something. I did this up top 
though:


$c = intval($_GET['c']);
$p = intval($_GET['p']);
$s = intval($_GET['s']);

and then did it as I had it in the sample above and it worked like a 
charm, too.






 subject.subject_id=art.subject_id;
?

If that were instead a $p then I would do:

?php   //IF there is a valid query by publisher, use $p to build the SQL
$fields = SELECT art.*,publisher.*,subject.*;
$from = FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id;
   $where = WHERE publisher.publisher_id=art.publisher_id AND
 art.publisher_id = '$p' AND



art.publisher_id = '$_GET[p]' AND



 subject.subject_id=art.subject_id;

?
If that were instead an $s then I would do:

?php  //IF there is a valid query by subject, use $s to build the SQL
$fields = SELECT art.*,publisher.*,subject.*;
$from = FROM art,subject
LEFT JOIN publisher
 ON publisher.publisher_id=art.publisher_id;
   $where = WHERE publisher.publisher_id=art.publisher_id AND
 art.subject_id = '1' AND
 art.subject_id=subject.subject_id;
?

I'm sure your method works ( ;) ). If I understand it, as my friend
Darrell said about your suggestion:

'...We iterate through the array seeing if there's a submitted HTML form
field name that matches the current database column name. If so, we add
the column name and the value submitted in the form to a string that is
being built into a database query.'



It's just a matter of checking for variables in the $_GET array and
doing what you need to do if they exist and are valid or not.  Do you
know about print_r() yet?

echo 'pre';
print_r( $_GET );
echo '/pre';


I did and thank you. This is close to working, though I still have to 
deal with what happens once I run those queries. But thanks for sorting 
out that mess for me,. I really appreciate it.









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



[PHP] foreach ($media as $key = $val) problem

2005-06-01 Thread Jack Jackson

Hi, all,
This might look like a mysql problem but I assure you it's my botching 
the PHP which is the problem!


I'm building a part of a page with info from three tables: art, media 
and media_art. Media_art is the intersection table. For every entry in 
art there can be one or more entries in media.

art.art_id 1 has two entries in media_art:

Media_id art_id
   32
   52

I do this SQL, which in phpmyadmin returns the two names of media as 
expected


SELECT media.media_name
FROM art, media_art, media
WHERE art.art_id = 1
AND art.art_id = media_art.art_id
AND media.media_id = media_art.media_id


Yet here's where I mess up. To see if I've got them in an array, I do:

  $media = mysql_fetch_assoc($media_result);

while ($media = mysql_fetch_assoc($media_result)) {

asort($media);

foreach($media as $key = $val) {
 echo key: $key value: $val br /;
}

} //end while $media = mysql_fetch_assoc($media_result)


and this returns only the name of the HIGHer number of the two (that is, 
5).
What have I done wrong to echo out each name of the media associated 
with this record?  I'm trying, eventually, to echo it out in the age so 
that it appears as


[art_id 1] comprises Ink, watercolor.

Thanks in advance,
Jack

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



[PHP] php not allowed in .htaccess

2005-05-27 Thread Jack Jackson

 Hi, dumb config issue.


I'm putting a php_value include_path statement in an .htaccess file

  php_value include_path .:/home/user/public_html/dis/admin/:/home/nick/
  php_value auto_prepend_file /home/user/public_html/dis/admin/wcsconf.php


and getting a 500 Server Error. Apache logs say, .htaccess: php_value 
not allowed here


Where can I change this behavior - is this an apache httpd.conf or 
php.ini setting? Something else?


Thanks in advance!

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



Re: [PHP] php not allowed in .htaccess

2005-05-25 Thread Jack Jackson
Sorry folks. Figured it out: in httpd.conf it wasn't in the first or 
second AllowOverride section (which I had set to All and that's why I 
was so gobsmacked) BUT it was in the Control access to UserDir 
directories section.


Thanks everyone!

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