PHP and sql problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bartosz Wegrzyn

    #1

    PHP and sql problem

    Please look at the code and if you can find my mistake.

    Please tell me why
    customerid is saved with wrong value the workorder table

    Instead of the correct value I get '0"

    When I try to display the $customerid value before the querry
    I have the correct value for example 1 but even that in the
    database I still have 0.

    Whats wrong???

    Thanks

    <?php


    $addcustomer = "insert into addressindex(na me,address,city ,state,zipcode, email,phone,ss, cc,exp,notes) values ('$name','$addr ess','$city','$ state','$zipcod e','$email','$p hone','$ss','$c c','$exp','$not es')";
    $addworkorder = "insert into workorder(custo merid,date,time ,service,due,sp ecial,extrawork ,due2,company,i nstaller,total) values ('$customerid', '$date','$time' ,'$service','$d ue','$special', '$extrawork','$ due2','$company ','$installer', '$total')";
    $getdata = "select * from addressindex where name = '$name' or customerid = '$customerid'";

    $rs = mysql_query($ge tdata);

    if(( $rs ) && ( mysql_errno() == 0 )) {

    // query was successful
    if( mysql_num_rows( $rs ) > 0 ) {

    $result2 = mysql_query($ad dworkorder);

    if ($result2) {
    include '../login/print.php';
    } else {
    include '../login/error-broken.php';}

    } else {

    $result = mysql_query($ad dcustomer);

    echo $customerid;

    $getid = "select customerid from addressindex where name = '$name'";
    $sqgetid = mysql_query($ge tid);
    $customerid = mysql_result($s qgetid,0);

    echo $customerid;

    //now i do a querry and even $customerid is 1 here now
    it is saved under 0


    $result2 = mysql_query($ad dworkorder);

    if ($result && $result2) {
    include '../login/print.php';
    } else {
    include '../login/error-broken.php';}

    }
    } else {
    include '../login/error-broken.php';}

    //Close connection with MySQL
    MySQL_close()


    ?>

  • Tom Thackrey

    #2
    Re: PHP and sql problem


    On 29-Aug-2003, "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> wrote:
    [color=blue]
    > Please look at the code and if you can find my mistake.
    >
    > Please tell me why
    > customerid is saved with wrong value the workorder table
    >
    > Instead of the correct value I get '0"
    >
    > When I try to display the $customerid value before the querry
    > I have the correct value for example 1 but even that in the
    > database I still have 0.
    >
    > Whats wrong???
    >
    > Thanks
    >
    > <?php
    >
    >
    > $addcustomer = "insert into
    > addressindex(na me,address,city ,state,zipcode, email,phone,ss, cc,exp,notes)
    > values
    > ('$name','$addr ess','$city','$ state','$zipcod e','$email','$p hone','$ss','$c c','$exp','$not es')";
    > $addworkorder = "insert into
    > workorder(custo merid,date,time ,service,due,sp ecial,extrawork ,due2,company,i nstaller,total)
    > values
    > ('$customerid', '$date','$time' ,'$service','$d ue','$special', '$extrawork','$ due2','$company ','$installer', '$total')";
    > $getdata = "select * from addressindex where name = '$name' or customerid
    > = '$customerid'";[/color]

    Please cross-post!!!

    It looks like you are inserting customerid into workorder but trying
    retrieving it from addressindex.



    --
    Tom Thackrey

    Comment

    • Bartosz Wegrzyn

      #3
      Re: PHP and sql problem

      Thats is correct !

      Thats what I want to do.

      On my main form I do enter all the data for customer and work order.

      Customer is is created automaticaly.

      I do not know how to add that id to my work order so I
      query what is that id and than I try to add it.

      On Fri, 29 Aug 2003 19:31:12 +0000, Tom Thackrey wrote:
      [color=blue]
      >
      > On 29-Aug-2003, "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> wrote:
      >[color=green]
      >> Please look at the code and if you can find my mistake.
      >>
      >> Please tell me why
      >> customerid is saved with wrong value the workorder table
      >>
      >> Instead of the correct value I get '0"
      >>
      >> When I try to display the $customerid value before the querry
      >> I have the correct value for example 1 but even that in the
      >> database I still have 0.
      >>
      >> Whats wrong???
      >>
      >> Thanks
      >>
      >> <?php
      >>
      >>
      >> $addcustomer = "insert into
      >> addressindex(na me,address,city ,state,zipcode, email,phone,ss, cc,exp,notes)
      >> values
      >> ('$name','$addr ess','$city','$ state','$zipcod e','$email','$p hone','$ss','$c c','$exp','$not es')";
      >> $addworkorder = "insert into
      >> workorder(custo merid,date,time ,service,due,sp ecial,extrawork ,due2,company,i nstaller,total)
      >> values
      >> ('$customerid', '$date','$time' ,'$service','$d ue','$special', '$extrawork','$ due2','$company ','$installer', '$total')";
      >> $getdata = "select * from addressindex where name = '$name' or customerid
      >> = '$customerid'";[/color]
      >
      > Please cross-post!!!
      >
      > It looks like you are inserting customerid into workorder but trying
      > retrieving it from addressindex.[/color]

      Comment

      • Matthew Vickers

        #4
        Re: PHP and sql problem

        On Fri, 29 Aug 2003 18:00:41 GMT
        "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> wrote:
        [color=blue]
        > Please look at the code and if you can find my mistake.
        >
        > Please tell me why
        > customerid is saved with wrong value the workorder table
        >
        > Instead of the correct value I get '0"
        >
        > When I try to display the $customerid value before the querry
        > I have the correct value for example 1 but even that in the
        > database I still have 0.
        >
        > Whats wrong???
        >
        > Thanks
        >
        > <?php
        >
        >
        > $addcustomer = "insert into
        > addressindex(na me,address,city ,state,zipcode, email,phone,ss, cc,exp,no
        > tes) values
        > ('$name','$addr ess','$city','$ state','$zipcod e','$email','$p hone','$s
        > s','$cc','$exp' ,'$notes')";$ad dworkorder = "insert into
        > workorder(custo merid,date,time ,service,due,sp ecial,extrawork ,due2,com
        > pany,installer, total) values
        > ('$customerid', '$date','$time' ,'$service','$d ue','$special', '$extrawo
        > rk','$due2','$c ompany','$insta ller','$total') ";$getdata = "select *
        > from addressindex where name = '$name' or customerid = '$customerid'";[/color]

        <SNIP>

        Just a thought:

        Is customerid declared as an integer in the MySQL table ?
        You are inserting it as a char value.

        Matt


        --
        Quispiam Power Computing | "There are two major products that come out
        Pendle Hill, Australia | of Berkeley: LSD and UNIX. We don't believe
        +61 2 9631 7719 | this to be a coincidence. "
        www.quispiam.com | - Jeremy S. Anderson

        Comment

        Working...