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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    having trouble trying to INSERT information into my table...

    PHP Code:
    <?PHP
    include 'dbconnect-include.php';

    $TableName maxforcepc;

    $link mysql_connect ($Host$User$Password);  
    mysql_select_db($DBName$link);

    $Query "INSERT INTO products (Cat_ID, Sub_Cat_ID, Product_Number, Product, Man_ID, Descriptions, In_Stock, Show_Quanity, Quanity, Cost, Sell_Price, Taxable, Tax_Price, Dementions, Weight) VALUES ('$_POST['Category']', '$_POST['Subcategory']', '$_POST['ProductNumber']', '$_POST['ProductName']', '$_POST['Manufacturers']', '$_POST['Descriptions']', '$_POST['InStockCheck']', '$_POST['ShowQCheck']', '$_POST['Quanity']', '$_POST['OurCost']', '$_POST['SellPrice']', '$_POST['TaxableCheck']', '$_POST['TaxPrice']', '$_POST['Dementions']', '$_POST['Weight']')";
    $Result mysql_query ($Query) or die (mysql_error());

    $validate = array('Category' 'Subcategory' 'ProductNumber' 'ProductName' 'Manufacturers' 'Descriptions' 'Quantity' 'OurCost' 'SellPrice' 'TaxPrice' 'Dementions' 'Weight') ; 
    $numbers = array('ProductNumber' 'Quanity' 'OurCost' 'SellPrice' 'TaxPrice' 'Dementions' 'Weight');

    foreach(
    $validate as  $k=> $v) { 
        if( ( empty( 
    $_POST[$k] ) ) && ( in_array$v$numbers ) ) ) { 
            
    $errs[] = "Field ".$v." is required to be filled out in numberic form.";
        }elseif( empty( 
    $_POST[$k] ) ) {
            
    $errs[] = "Field ".$v." is required to be filled out.";
        }


    if( isset( 
    $errs ) ){ 
        echo 
    implode'<br />' $errs );
    }else{
         
    //insert code here to INSERT information to database


    ?>
    The error checking to make sure nothing is left out works great until I added the query statement or something... I'm not really too sure what the problem is here. A quick explaination of what It's doing is: Gets the variables from the form as you can tell by the sql query statement, checks for anything blank if there isn't then execute the query statement which I'm not too sure how to do that. Any help would be greatly appreciated thanks :-)

    -peace

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this
    PHP Code:
    <?PHP
    include 'dbconnect-include.php';

    $TableName "maxforcepc";

    $link mysql_connect ($Host$User$Password);  
    mysql_select_db($DBName$link);

    $Query "INSERT INTO `products`(`Cat_ID`,`Sub_Cat_ID`,`Product_Number`,`Product`,`Man_ID`,`Descriptions`,`In_Stock`,`Show_Quanity`,`Quanity`,`Cost`,`Sell_Price`,`Taxable`,`Tax_Price`,`Dementions`,`Weight`) VALUES ('{$_POST['Category']}','{$_POST['Subcategory']}','{$_POST['ProductNumber']}', '{$_POST['ProductName']}','{$_POST['Manufacturers']}','{$_POST['Descriptions']}','{$_POST['InStockCheck']}','{$_POST['ShowQCheck']}','{$_POST['Quanity']}','{$_POST['OurCost']}','{$_POST['SellPrice']}','{$_POST['TaxableCheck']}','{$_POST['TaxPrice']}','{$_POST['Dementions']}','{$_POST['Weight']}')";
    $Result mysql_query($Query) or die(mysql_error());

    $validate = array('Category' 'Subcategory' 'ProductNumber' 'ProductName' 'Manufacturers' 'Descriptions' 'Quantity' 'OurCost' 'SellPrice' 'TaxPrice' 'Dementions' 'Weight') ; 
    $numbers = array('ProductNumber' 'Quanity' 'OurCost' 'SellPrice' 'TaxPrice' 'Dementions' 'Weight');

    foreach(
    $validate as  $k=> $v) { 
        if( ( empty( 
    $_POST[$k] ) ) && ( in_array$v$numbers ) ) ) { 
            
    $errs[] = "Field ".$v." is required to be filled out in numberic form.";
        }elseif( empty( 
    $_POST[$k] ) ) {
            
    $errs[] = "Field ".$v." is required to be filled out.";
        }


    if( isset( 
    $errs ) ){ 
        echo 
    implode'<br />' $errs );
    }else{
         
    //insert code here to INSERT information to database


    ?>
    Sometimes, MySQL can be picky about entering data, so i added a ` to all the field names and { } around the variables being entered.

    Hope that works.

    Stevie
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!


  •  

    Posting Permissions

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