Re: [PHP-DB] lamer noob with repeat question

2004-05-04 Thread Hans Lellelid
Dan Bowkley wrote:
}
else {echo "OOPS! Your programmer is an idiot!\n";}
}}
... and consider removing this for a couple reasons:

1) If a user should never see this, then design your application so that 
they never do.

2) If this code ever could be executed, then you probably want to handle 
it in a way that would stand less chance of scaring away future business. :)

Good luck!
Hans
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] lamer noob with repeat question

2004-05-04 Thread Hans Lellelid
Hi,

I think there are probably a few reasons why no one has answered:
  1) This isn't a database problem,
  2) You can apply some pretty standard debugging practices to narrow 
down the problem, and
  3) Your code is hard to follow -- and fact application logic is being 
lost in the all the escaped HTML that you are echo()ing.

 so, here's what I'd suggest:

--
Start by echoing your $_REQUEST array at the top of your script:
  print ""; print_r($_REQUEST); print "";
Make sure your 'action' var is being set correctly, etc.  This is 
standard debugging stuff.  Print values all over the place; add things like:
  print "Got this far: " . __LINE__ . "";

so that you know where your code is dying.

--
Remove any "@" error suprression ... until you know your script works 
you shouldn't be silencing errors (Especially as in some cases these 
errors could be fatal causing your script to terminate with that 
infamous white screen).

--
Use the switch() statement to make your logic easier.  DON'T USE 
ARBITRARY NUMBER VALUES FOR YOUR ACTION SWITCH!  And consider separating 
out your HTML markup from your application logic.  You don't have to do 
anything fancy like use a template engine; just include a PHP file that 
is essentially just HTML with embedded  tags to echo values. 
(no logic in that file, just flat HTML).

Consider having two switch statements -- $action and $view.  The first 
one handles things like 'save', 'load', etc.  Based on the result of 
actions (like inserting to db, etc.) of the first switch you can change 
the view that should be displayed.  This is fairly simple and will go a 
long, long way to making your code easier to debug -- and easier for 
other people to read.

Cheers,
Hans
Dan Bowkley wrote:

Anyone?
- Original Message - 
From: "Dan Bowkley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 02, 2004 1:21 AM
Subject: [PHP-DB] lamer noob with repeat question



Hello everyone,

I've been working on (read:tearing my hair out over) my mom's website for
some time now.  Specifically, I'm trying to get her work order database up
and running.
The basic idea is this: you start out adding a new record by going to
add.php.  It sees that you've not done anything yet and thus presents you
with a form to fill out.  That form gets submitted to add.php, which sees
that you're adding something.  It checks for a duplicate work order number
(and eventually other errors) and then either adds the stuff you submitted
into the DB, or pops an error and presents the form again.
Alas, it does nothing.

When you initially load the page, it works okay, sensing that you've not
yet

done anything and displaying the form.  But when you submit data, it spits
out naught more than a blank page, and doesn't add anything to the
database.

Damned lazy script.

What I've got so far is this:


The Board Lady - Work Order Database 0.1a

\n";
echo "";
echo "Work Order #: \n";
echo "Customer Name:  Phone: \n";
echo "Email Addy:  Date In: \n";
echo "Board Type and SN:  Last 3
of

SN: \n";
echo "Weight In:  Weight Out:


type=\"text\" name=\"weight_out\">\n";
echo "\n";
echo " \n";
}
if ($page_req == "1") {
$wo_num=$HTTP_GET_VARS['wo_num'];
$name=$HTTP_GET_VARS['name'];
$phone=$HTTP_GET_VARS['phone'];
$email=$HTTP_GET_VARS['email'];
$date=$HTTP_GET_VARS['date'];
$board_type=$HTTP_GET_VARS['board_type'];
$last_three=$HTTP_GET_VARS['last_three'];
$weight_in=$HTTP_GET_VARS['weight_in'];
$weight_out=$HTTP_GET_VARS['weight_out'];
$query_testingforadupe = "SELECT job_no FROM boards WHERE job_no ==
$job_no

ORDER BY job_no ASC";
$result_testingforadupe = @mysql_query ($query_testingforadupe);
if ($result_testingforadupe) {
echo "That's a duplicate work order number, you ditz. Try again, this time
without screwing it all up.\n";
echo "";
echo "Work Order #: \n";
echo "Customer Name:  Phone: \n";
echo "Email Addy:  Date In: \n";
echo "Board Type and SN:  Last 3
of

SN: \n";
echo "Weight In:  Weight Out:


type=\"text\" name=\"weight_out\">\n";
echo "\n";
echo " \n";
}
else {
$query_insert = "INSERT INTO boards (wo_num, name, phone, email, date,
board_type, last_three, weight_in, weight_out) VALUES (\'$wo_num\',
\'$name\', \'$phone\', \'$email\', \'$date\', \'$board_type\',
\'$last_three\', \'$weight_in\', \'$weight_out\')";
$result_insert = @mysql_query ($query_insert);
if ($result_insert == "") {
echo "\n";
}
else {echo "OOPS! Your programmer is an idiot!\n";}
}}
mysql_close();
?>






The database looks like this, in case you're curious:
CREATE TABLE boards (
 name varchar(40) default NULL,
 phone varchar(12) default NULL,
 email varchar(40) default NULL,
 purveyor varchar(40) default NULL,
 job_no int(5) unsigned NOT NULL default '0',
 date varchar(10) NOT NULL default '',
 board_type varchar(100) NOT NULL default '',
 weight_in decimal(4,2) default NULL,
 weight_out decimal(4,2) default NULL,
 last_three int(3) unsigned default NULL,
 PRIMARY KEY  (job_no),
 KEY last-three (last_three)
) TYPE=MyISAM;
Can an

RE: [PHP-DB] lamer noob with repeat question

2004-05-03 Thread Uzi Klein
Try 
$result_insert = @mysql_query ($query_insert) or die(mysql_error);

-Original Message-
From: Dan Bowkley [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 04, 2004 08:37
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] lamer noob with repeat question

Anyone?
- Original Message - 
From: "Dan Bowkley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 02, 2004 1:21 AM
Subject: [PHP-DB] lamer noob with repeat question


> Hello everyone,
>
> I've been working on (read:tearing my hair out over) my mom's website for
> some time now.  Specifically, I'm trying to get her work order database up
> and running.
>
> The basic idea is this: you start out adding a new record by going to
> add.php.  It sees that you've not done anything yet and thus presents you
> with a form to fill out.  That form gets submitted to add.php, which sees
> that you're adding something.  It checks for a duplicate work order number
> (and eventually other errors) and then either adds the stuff you submitted
> into the DB, or pops an error and presents the form again.
>
> Alas, it does nothing.
>
> When you initially load the page, it works okay, sensing that you've not
yet
> done anything and displaying the form.  But when you submit data, it spits
> out naught more than a blank page, and doesn't add anything to the
database.
>
> Damned lazy script.
>
>
> What I've got so far is this:
>
> 
> The Board Lady - Work Order Database 0.1a
> 
>  define ('DB_USER', 'user');
> define ('DB_PASSWORD', '');
> define ('DB_HOST', 'localhost');
> define ('DB_NAME', 'boardlady');
> $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not
> connect to database: ' . mysql_error());
> @mysql_select_db (DB_NAME) OR die ('Could not connect to database: ' .
> mysql_error());
> $page_req=$HTTP_GET_VARS['action'];
> if ($page_req == "") {$page_req="0";}
> if ($page_req == "0") {
> echo "SWORD data entry\n";
> echo "";
> echo "Work Order #: \n";
> echo "Customer Name:  Phone:  type=\"text\" name=\"phone\">\n";
> echo "Email Addy:  Date In:  type=\"text\" name=\"date\">\n";
> echo "Board Type and SN:  Last 3
of
> SN: \n";
> echo "Weight In:  Weight Out:
 type=\"text\" name=\"weight_out\">\n";
> echo "\n";
> echo "  type=\"reset\">\n";
> }
> if ($page_req == "1") {
> $wo_num=$HTTP_GET_VARS['wo_num'];
> $name=$HTTP_GET_VARS['name'];
> $phone=$HTTP_GET_VARS['phone'];
> $email=$HTTP_GET_VARS['email'];
> $date=$HTTP_GET_VARS['date'];
> $board_type=$HTTP_GET_VARS['board_type'];
> $last_three=$HTTP_GET_VARS['last_three'];
> $weight_in=$HTTP_GET_VARS['weight_in'];
> $weight_out=$HTTP_GET_VARS['weight_out'];
> $query_testingforadupe = "SELECT job_no FROM boards WHERE job_no ==
$job_no
> ORDER BY job_no ASC";
> $result_testingforadupe = @mysql_query ($query_testingforadupe);
> if ($result_testingforadupe) {
> echo "That's a duplicate work order number, you ditz. Try again, this time
> without screwing it all up.\n";
> echo "";
> echo "Work Order #: \n";
> echo "Customer Name:  Phone:  type=\"text\" name=\"phone\">\n";
> echo "Email Addy:  Date In:  type=\"text\" name=\"date\">\n";
> echo "Board Type and SN:  Last 3
of
> SN: \n";
> echo "Weight In:  Weight Out:
 type=\"text\" name=\"weight_out\">\n";
> echo "\n";
> echo "  type=\"reset\">\n";
> }
> else {
> $query_insert = "INSERT INTO boards (wo_num, name, phone, email, date,
> board_type, last_three, weight_in, weight_out) VALUES (\'$wo_num\',
> \'$name\', \'$phone\', \'$email\', \'$date\', \'$board_type\',
> \'$last_three\', \'$weight_in\', \'$weight_out\')";
> $result_insert = @mysql_query ($query_insert);
> if ($result_insert == "") {
> echo " echo "\n";
> }
> else {echo "OOPS! Your programmer is an idiot!\n";}
> }}
> mysql_close();
> ?>
> 
> 
>
>
>
>
>
> The database looks like this, in case you're curious:
> CREATE TABLE boards (
>   name varchar(40) default NULL,
>   phone varchar(12) default NULL,
>   email varchar(40) default NULL,
>   purveyor varchar(40) default NULL,
>   job_no int(5) unsigned NOT NULL default '0',
>   date varchar(10) NOT NULL default '',
>   board_type varchar(100) NOT NULL default '',
>   weight_in decimal(4,2) default NULL,
>   weight_out decimal(4,2) default NULL,
>   last_three int(3) unsigned default NULL,
>   PRIMARY KEY  (job_no),
>   KEY last-three (last_three)
> ) TYPE=MyISAM;
>
>
> Can anyone help me to get this thing working?
>
> TIA
> Dan
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

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

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



Re: [PHP-DB] lamer noob with repeat question

2004-05-03 Thread Dan Bowkley
Anyone?
- Original Message - 
From: "Dan Bowkley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 02, 2004 1:21 AM
Subject: [PHP-DB] lamer noob with repeat question


> Hello everyone,
>
> I've been working on (read:tearing my hair out over) my mom's website for
> some time now.  Specifically, I'm trying to get her work order database up
> and running.
>
> The basic idea is this: you start out adding a new record by going to
> add.php.  It sees that you've not done anything yet and thus presents you
> with a form to fill out.  That form gets submitted to add.php, which sees
> that you're adding something.  It checks for a duplicate work order number
> (and eventually other errors) and then either adds the stuff you submitted
> into the DB, or pops an error and presents the form again.
>
> Alas, it does nothing.
>
> When you initially load the page, it works okay, sensing that you've not
yet
> done anything and displaying the form.  But when you submit data, it spits
> out naught more than a blank page, and doesn't add anything to the
database.
>
> Damned lazy script.
>
>
> What I've got so far is this:
>
> 
> The Board Lady - Work Order Database 0.1a
> 
>  define ('DB_USER', 'user');
> define ('DB_PASSWORD', '');
> define ('DB_HOST', 'localhost');
> define ('DB_NAME', 'boardlady');
> $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not
> connect to database: ' . mysql_error());
> @mysql_select_db (DB_NAME) OR die ('Could not connect to database: ' .
> mysql_error());
> $page_req=$HTTP_GET_VARS['action'];
> if ($page_req == "") {$page_req="0";}
> if ($page_req == "0") {
> echo "SWORD data entry\n";
> echo "";
> echo "Work Order #: \n";
> echo "Customer Name:  Phone:  type=\"text\" name=\"phone\">\n";
> echo "Email Addy:  Date In:  type=\"text\" name=\"date\">\n";
> echo "Board Type and SN:  Last 3
of
> SN: \n";
> echo "Weight In:  Weight Out:
 type=\"text\" name=\"weight_out\">\n";
> echo "\n";
> echo "  type=\"reset\">\n";
> }
> if ($page_req == "1") {
> $wo_num=$HTTP_GET_VARS['wo_num'];
> $name=$HTTP_GET_VARS['name'];
> $phone=$HTTP_GET_VARS['phone'];
> $email=$HTTP_GET_VARS['email'];
> $date=$HTTP_GET_VARS['date'];
> $board_type=$HTTP_GET_VARS['board_type'];
> $last_three=$HTTP_GET_VARS['last_three'];
> $weight_in=$HTTP_GET_VARS['weight_in'];
> $weight_out=$HTTP_GET_VARS['weight_out'];
> $query_testingforadupe = "SELECT job_no FROM boards WHERE job_no ==
$job_no
> ORDER BY job_no ASC";
> $result_testingforadupe = @mysql_query ($query_testingforadupe);
> if ($result_testingforadupe) {
> echo "That's a duplicate work order number, you ditz. Try again, this time
> without screwing it all up.\n";
> echo "";
> echo "Work Order #: \n";
> echo "Customer Name:  Phone:  type=\"text\" name=\"phone\">\n";
> echo "Email Addy:  Date In:  type=\"text\" name=\"date\">\n";
> echo "Board Type and SN:  Last 3
of
> SN: \n";
> echo "Weight In:  Weight Out:
 type=\"text\" name=\"weight_out\">\n";
> echo "\n";
> echo "  type=\"reset\">\n";
> }
> else {
> $query_insert = "INSERT INTO boards (wo_num, name, phone, email, date,
> board_type, last_three, weight_in, weight_out) VALUES (\'$wo_num\',
> \'$name\', \'$phone\', \'$email\', \'$date\', \'$board_type\',
> \'$last_three\', \'$weight_in\', \'$weight_out\')";
> $result_insert = @mysql_query ($query_insert);
> if ($result_insert == "") {
> echo " echo "\n";
> }
> else {echo "OOPS! Your programmer is an idiot!\n";}
> }}
> mysql_close();
> ?>
> 
> 
>
>
>
>
>
> The database looks like this, in case you're curious:
> CREATE TABLE boards (
>   name varchar(40) default NULL,
>   phone varchar(12) default NULL,
>   email varchar(40) default NULL,
>   purveyor varchar(40) default NULL,
>   job_no int(5) unsigned NOT NULL default '0',
>   date varchar(10) NOT NULL default '',
>   board_type varchar(100) NOT NULL default '',
>   weight_in decimal(4,2) default NULL,
>   weight_out decimal(4,2) default NULL,
>   last_three int(3) unsigned default NULL,
>   PRIMARY KEY  (job_no),
>   KEY last-three (last_three)
> ) TYPE=MyISAM;
>
>
> Can anyone help me to get this thing working?
>
> TIA
> Dan
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

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