Re: lamer noob with repeat question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 "<pre>"; print_r($_REQUEST); print "</pre>";

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__ . "<br/>";


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 <?php ?> 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" <dan@xxxxxxxxxxxxxxxx>
To: <php-db@xxxxxxxxxxxxx>
Sent: Sunday, May 02, 2004 1:21 AM
Subject: 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:


<html>
<head><title>The Board Lady - Work Order Database 0.1a</title></head>
<body>
<?php
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<br>\n";
echo "<form action=\"add.php\" method=\"get\">";
echo "Work Order #: <input type=\"text\" name=\"wo_num\"><br>\n";
echo "Customer Name: <input type=\"text\" name=\"name\"> Phone: <input
type=\"text\" name=\"phone\"><br>\n";
echo "Email Addy: <input type=\"text\" name=\"email\"> Date In: <input
type=\"text\" name=\"date\"><br>\n";
echo "Board Type and SN: <input type=\"text\" name=\"board_type\"> Last 3

of


SN: <input type=\"text\" name=\"last_three\"><br>\n";
echo "Weight In: <input type=\"text\" name=\"weight_in\"> Weight Out:

<input


type=\"text\" name=\"weight_out\"><br>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"1\">\n";
echo "<INPUT type=\"submit\" value=\"Add Work Order\"> <INPUT
type=\"reset\"><br>\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.<br><br>\n";
echo "<form action=\"add.php\" method=\"get\">";
echo "Work Order #: <input type=\"text\" name=\"wo_num\"><br>\n";
echo "Customer Name: <input type=\"text\" name=\"name\"> Phone: <input
type=\"text\" name=\"phone\"><br>\n";
echo "Email Addy: <input type=\"text\" name=\"email\"> Date In: <input
type=\"text\" name=\"date\"><br>\n";
echo "Board Type and SN: <input type=\"text\" name=\"board_type\"> Last 3

of


SN: <input type=\"text\" name=\"last_three\"><br>\n";
echo "Weight In: <input type=\"text\" name=\"weight_in\"> Weight Out:

<input


type=\"text\" name=\"weight_out\"><br>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"1\">\n";
echo "<INPUT type=\"submit\" value=\"Add Work Order\"> <INPUT
type=\"reset\"><br>\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 "<input type=\"hidden\" name=\"action\" value=\"0\"\n";
echo "<INPUT type=\"submit\" value=\"Continue\">\n";
}
else {echo "OOPS! Your programmer is an idiot!\n";}
}}
mysql_close();
?>
</body>
</html>





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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux