Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    unknown error. column data not found?

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

    Code:
    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`)
    ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    Last edited by utinaeniduin; 01-19-2007 at 05:48 PM. Reason: organization

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i don't think the problem is in my insert code. it has always worked fine before...

    PHP Code:
    $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");} 

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •