SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help On Inserting The Record In Mysql Table

    I have sql embbed in php code below. All the sql statements are able to insert record as developed, but the sql at the end is not inserting the record as expected it is given the error. what is the problem Iam using Mysql 5.0 and php 5.2. The sql that is not working is below in bold. Your help will be highly appreciated.


    if (($tAllowanceID !='') && ($Claimcodezz !='') && ($AmountRequiredzz !='')){

    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
    "VALUES ('$tAllowanceID','$Claimcodezz','$AmountRequiredzz')" ;
    mysql_query($mysql_query) or die('Error test, insert query failed');

    }



    PHP Code:
    if (($tAllowanceID != '') && ($dClaimCode != '') && ($dAmountRequired != '')){

    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$dClaimCode','$dAmountRequired')" ;
    mysql_query($mysql_query) or die('Error2, insert query failed'); 
    }

    if ((
    $tAllowanceID != '') && ($eClaimCode != '') && ($eAmountRequired != '')) {

    $mysql_query="INSERT INTO aftertravel  (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$eClaimCode','$eAmountRequired')" ;
    mysql_query($mysql_query) or die('Error3, insert query failed'); 

    }
    if ((
    $tAllowanceID !='') && ($fClaimCode != '') && ($fAmountRequired != '')){

    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode, Amount)".
     
    "VALUES ('$tAllowanceID','$fClaimCode','$fAmountRequired')" ;
     
    mysql_query($mysql_query)or die('4Error4, insert query failed'); 
    }
    if ((
    $tAllowanceID != '') && ($gClaimCode != '') && ($gAmountRequired != ''))
    {

    $mysql_query="INSERT INTO aftertravel (AllowanceId, ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$gClaimCode','$gAmountRequired')" ;
    mysql_query($mysql_query) or die('5Error, insert query failed'); 
    }
    if ((
    $tAllowanceID != '') && ($hClaimcode !='') && ($hAmountRequired != ''))
    {
    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$hClaimcode','$hAmountRequired')" ;
    mysql_query($mysql_query) or die('6Error, insert query failed'); 
    }
    if ((
    $tAllowanceID != '') && ($iClaimcode != '') && ($iAmountRequired != ''))
    {

    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$iClaimcode','$iAmountRequired')" ;
    mysql_query($mysql_query) or die('7Error, insert query failed'); 
    }
    if ((
    $tAllowanceID != '') && ($jClaimcode !='') && ($jAmountRequired != ''))
    {
    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$jClaimcode','$jAmountRequired')" ;
    mysql_query($mysql_query) or die('8Error, insert query failed'); 
    }


    if ((
    $tAllowanceID !='') && ($lClaimcode != '') && ($lAmountRequired != ''))
    {
    $mysql_query="INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$lClaimcode','$lAmountRequired')" ;
    mysql_query($mysql_query) or die('9Error, insert query failed'); 

    }

    if ((
    $tAllowanceID !='') && ($Docem != '') && ($mdetails != '')){

    $mysql_query="INSERT INTO attdocumentation  (AllowanceId,Documentname,Details)".
     
    "VALUES ('$tAllowanceID','$Docem','$mdetails')" ;
    mysql_query($mysql_query) or die('10Error, insert query failed'); 

    }

    [
    B]if (($tAllowanceID !='') && ($Claimcodezz !='') && ($AmountRequiredzz !='')){

    $mysql_query="INSERT INTO aftertravel  (AllowanceId,ClaimCode,Amount)".
     
    "VALUES ('$tAllowanceID','$Claimcodezz','$AmountRequiredzz')" ;
    mysql_query($mysql_query) or die('Error test, insert query failed'); [/B


    Last edited by zamzam; Sep 29, 2006 at 03:24.

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $$tAllowanceID should be $tAllowanceID.
    Also, I'd replace this:
    PHP Code:
    or die('Error test, insert query failed'); 
    with this:
    PHP Code:
    or die(mysql_error()); 
    as it gives you more information of where the query went wrong.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mudshark
    I have changed but I am still receiving the same error.

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you put in the mysql_error() bit I mentioned? What error do you get?

  5. #5
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the error Iam receiving below

    Data truncated for column 'Amount' at row 1

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Before the mysql_query() function put this ...

    PHP Code:
    echo $mysql_query;
    exit; 
    What SQL command gets shown on the screen?
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what Iam receiving below


    INSERT INTO aftertravel (AllowanceId,ClaimCode,Amount)VALUES ('1','Supper?>','40000?>')

  8. #8
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think those "?>"-s should be there... Something's wrong with those (posted?) values.

  9. #9
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Grand Rapids, MI
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your using MySQL 5 with PHP5, you should be using the mysqli functions.


Bookmarks

Posting Permissions

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