[PHP] Re: Simple Problem about forms and sending info to db

2004-09-14 Thread Logan Moore
Ok I think I figured out my own problem. The speechmarks in the Form break
up the speech marks in the echo statement so I originally changed the echo
statements speechmark to a ' which worked but was informed that this was
considered bad syntax and that maybe I should add a \ in front of all
speechmarks which are not part of the echo statement.

I could still do with an example of how to put the information from the form
into the db though. As I have never done this before.


Logan Moore [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I am currently coding a cms. So far I have completed the security
 login/password system but have now moved on to a new area of php.
Uploading
 info to a database.

 This is the code as it stands now.

 ?php
   if($_GET[action] == ){echo
   form name=adduser method=post action=adduser.php?action=adduser
   table width=400 border=0 cellspacing=0 cellpadding=5
 tr valign=top
   td width=50% align=rightFull Name:/td
   td width=50%input name=fullname type=text
id=fullname/td
 /tr
 tr valign=top
   td height=50 align=rightEmail:/td
   tdinput name=email type=text id=email/td
 /tr
 tr valign=top
   td align=rightUserName:/td
   tdinput name=username type=text id=username/td
 /tr
 tr valign=top
   td align=rightPassword:/td
   tdinput name=password type=password id=password/td
 /tr
 tr align=center
   td colspan=2input type=submit name=Submit
 value=Submit/td
   /tr
   /table
   /form
   ;}

   if($_GET[action] == adduser){echo Add User Function is still Under
 Construction br as a result what you just did has had no effect}
   ?


 I know there is something wrong as i get an error when I goto the page.
 I want it to display the form, then when you click submit, goto the same
 page except run the command to add the information from the form to the
 database.

 Also how do I put the information in the database.

 Regards
 Logan

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



[PHP] Re: Simple Problem about forms and sending info to db

2004-09-14 Thread Niklas Lampén
First of all, I'd use something like this:
-- CODE --
?
if (!isset($_GET['action']) || trim($_GET['action']) == )
{
?
form./form
?
}
else if ($_GET['action'] == 'adduser')
{
?
Foo
?
}
?
-- END --
But the actual error is in the echo. You're having quotation marks 
inside it. You need to do it my way, or write the form like
?
echo form name=\myForm\.../form;
?


Niklas

Logan Moore wrote:
I am currently coding a cms. So far I have completed the security
login/password system but have now moved on to a new area of php. Uploading
info to a database.
This is the code as it stands now.
?php
  if($_GET[action] == ){echo
  form name=adduser method=post action=adduser.php?action=adduser
  table width=400 border=0 cellspacing=0 cellpadding=5
tr valign=top
  td width=50% align=rightFull Name:/td
  td width=50%input name=fullname type=text id=fullname/td
/tr
tr valign=top
  td height=50 align=rightEmail:/td
  tdinput name=email type=text id=email/td
/tr
tr valign=top
  td align=rightUserName:/td
  tdinput name=username type=text id=username/td
/tr
tr valign=top
  td align=rightPassword:/td
  tdinput name=password type=password id=password/td
/tr
tr align=center
  td colspan=2input type=submit name=Submit
value=Submit/td
  /tr
  /table
  /form
  ;}
  if($_GET[action] == adduser){echo Add User Function is still Under
Construction br as a result what you just did has had no effect}
  ?
I know there is something wrong as i get an error when I goto the page.
I want it to display the form, then when you click submit, goto the same
page except run the command to add the information from the form to the
database.
Also how do I put the information in the database.
Regards
Logan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Simple Problem about forms and sending info to db

2004-09-14 Thread Jason Wong
On Tuesday 14 September 2004 18:06, Logan Moore wrote:
 Ok I think I figured out my own problem. The speechmarks in the Form break
 up the speech marks in the echo statement so I originally changed the echo
 statements speechmark to a ' which worked but was informed that this was
 considered bad syntax and that maybe I should add a \ in front of all
 speechmarks which are not part of the echo statement.

It's up to you. IMO, using single quote strings and breaking out when handling 
variables is more readable than using double quote strings and escaping the 
double quote (\).

 I could still do with an example of how to put the information from the
 form into the db though. As I have never done this before.

Plenty of tutorials out there.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
There are no working trigger cables, unless they are too short 
-- Ralf's Laws of Observational Astronomy n2
*/

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



Re: [PHP] Re: Simple Problem about forms and sending info to db

2004-09-14 Thread Wouter van Vliet
On Tue, 14 Sep 2004 18:32:50 +0800, Jason Wong [EMAIL PROTECTED] wrote:
 On Tuesday 14 September 2004 18:06, Logan Moore wrote:
  Ok I think I figured out my own problem. The speechmarks in the Form break
  up the speech marks in the echo statement so I originally changed the echo
  statements speechmark to a ' which worked but was informed that this was
  considered bad syntax and that maybe I should add a \ in front of all
  speechmarks which are not part of the echo statement.
 
 It's up to you. IMO, using single quote strings and breaking out when handling
 variables is more readable than using double quote strings and escaping the
 double quote (\).
 
  I could still do with an example of how to put the information from the
  form into the db though. As I have never done this before.
 
 Plenty of tutorials out there.
 

First of all, you're making some pretty harsh coding style errors. For
the sake of compatibility, always make sure you're quoting
non-numerical elements in an array, thus: write $_GET['action']
instead of $_GET[action]. Imagine, for example, what would happen if
you've got some field named public and you're upgrading to php5? Or
when, in php 5.4 (just saying smth), action suddenly becomes a
keyword. You're stuck then with dead code.

Good practice is also to check whether your expected array entry is
actually set. I usually do smth like:

isset($_GET['action']) or $_GET['action'] = 'thedefaultvalue';

or

if (!isset($_GET['action'])) {
  $_GET['action'] = 'thedefalutvalue'];
};

(both do the same, first one is just a lot shorter).

As adviced before, whenever you have to check if a certain variable
has a certain value, and if one of them is true, none of the others
will be true (which is the case with $_GET['action'] checks, usually)
- use the

if ( /* conditions */ ) {
} elseif ( /* other conditions */ ) {
}

method, rather than all seperate if's. I once changed this in somebody
else's code and found the script running about 5 (!!) times faster,
with about 15 conditions.

For inserting into the databas, mysql_connect() and mysql_execute()
are very good options. Or, if you're able to use the PEAR::DB package
I'd advice you to use that. It's more fun to do it that way, and will
help a lot if ever you'd want to change your database server from
mysql to something else (postgres, for example). Ow, and it also helps
a lot with any quoting problem you'd come up with.

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