View Full Version : unknown error. column data not found?

01-19-2007, 02:02 AM
i am having this problem where my html form/php handler are not inserting the correct values into the database. I am trying to simply insert a row into a database using the same php code that i always do. could it be the different mysql structure that i am using? when i click the submit button on the page it inserts a row with all 0s. (-|-|0|0|0.00).

sql structure is as followed. i have never set up my own table with integer fields..

CREATE TABLE `mytable` (
`id` bigint(20) NOT NULL auto_increment,
`date` varchar(100) NOT NULL,
`amt_sold` smallint(5) NOT NULL,
`amt_rem` smallint(5) NOT NULL,
`raised` decimal(8,2) NOT NULL,
KEY `id` (`id`)

01-19-2007, 10:44 PM
The problem is that the Blue Ox that you are trying to fit into the Mini Cooper, obviously has not seen the relevant code, thus forcing him to guess at it. Rebelling, he will not bide by the wishes of Paul Bunyon, leaving Paul flummoxed at what to do next.

01-19-2007, 10:49 PM
If you can't guess from my response above, I'm hinting that you have shown no insert code so people can't guess what is wrong.

I will tell you one thing in the organization of your column types, they need to be changed. If you are starting an auto increment from 2 there is no way, or almost none, to fill a BIGINT type, you should use INT or something smaller.
Use the correct data types when necessary.

Further to that you are storing a date in a character field 100 characters in length. A date field is at most 10 characters in length, (yyyy-mm-dd is the longest accepted), and using varchar instead of DATE as your date type causes you to lose all DATE and TIME functions available to you in doing calculations on your data.

Should you prefer to change that field, you can see the link in my signature below to see how to do so.

lastly the (5) after smallint are not necessary, I'll guess you put them there out of habit of seeing them done like that, or you are using a GUI that erroneously puts them there. That (5) is only necessary when you have a column of ZEROFILL type.

Anyhow, enough of that, post your code that is doing the insert and I, or someone else, will have a look at it for you.

01-21-2007, 12:36 AM
well i don't think the problem is in my insert code. it has always worked fine before...

$update = $_GET['update'];
$uid = $_GET['uid'];

$cDate = $_POST['cDate'];
$amt_sold = $_POST['amt_sold'];
$amt_rem = $_POST['amt_rem'];
$raised = $_POST['raised'];

if ($update=="1"){//////////////////////////////////

mysql_query("UPDATE `$fname` SET `amt_sold`='$amt_sold', `amt_rem`='$amt_rem', `raised`='$raised' WHERE `date`='$cDate'");

Header("Location: home.php?uid=$uid");

} elseif ($update=="0") {///////////////////////////////

mysql_query("INSERT INTO `$fname` (`date`, `amt_sold`, `amt_rem`, `raised`)". "VALUES ('$cDate', '$amt_sold', '$amt_rem', '$raised')");

Header("Location: home.php?uid=$uid");}

01-22-2007, 06:42 PM
i figured by echoing some of my variables that the update=1 works but update=0 does not. it is weird because 1 works even though there was no row to update; it works just like an insert query. in both cases the $Date variable does not pass to the database, though it does echo in the update=1

01-23-2007, 12:35 AM
oh my goodness, i am sorry if anyone is still working on my problem. i did something really stupid. i forgot to correctly name the textfields in the html. all of the php works just fine. sorry again. lol