Re: mysql query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Try the insertion like this:
$sql2 = mysql_query("insert into Inventory (`UPC`
, `quant`, `manuf`, `item`, `orderpt`, `ordrpt_flag`, `stock`)"
                                ."values ('$upc', $qnt,'$mnf','$itm',
'$odrpt', '0', '$stk') " ) or die(mysql_error());

On 22 August 2013 05:10, Daniel Krook <krook@xxxxxxxxxx> wrote:

> Ethan,
>
> What about:
>
> $result2 = mysqli_query(cxn, $sql2);
>
> Doesn't look like you're sending it a connection link as a variable ($cxn)
> and that's passed through as a literal?
>
>
>
>
> Thanks,
>
>
> Daniel Krook
> Software Engineer, Advanced Cloud Solutions, GTS
>
> IBM Senior Certified IT Specialist - L3 Thought Leader
> The Open Group Certified IT Specialist - L3 Distinguished
> Cloud, Java, PHP, BlackBerry, DB2 & Solaris Certified
>
>
>
>
>
>
> Ethan Rosenberg <erosenberg@xxxxxxxxxxxxxxxxxxxx> wrote on 08/21/2013
> 11:59:19 PM:
>
> > From: Ethan Rosenberg <erosenberg@xxxxxxxxxxxxxxxxxxxx>
> > To: Daniel Krook/White Plains/IBM@IBMUS
> > Cc: PHP Database List <php-db@xxxxxxxxxxxxx>
> > Date: 08/21/2013 11:59 PM
> > Subject: Re:  mysql query
> >
> > On 08/21/2013 11:30 PM, Daniel Krook wrote:
> > Ethan,
> >
> > It's hard to tell from the code formatting in your email what the
> > exact problem might be, but a few reasons that this might fail in
> > PHP rather than when sent to MySQL with hardcoded values:
> >
> > 1.  var_dump/print_r $_POST to see what you're getting as input is
> > what you expect (and sanitize!).
> >
> > 2.  Check that the SQL statement concatenation in PHP is building
> > the string you're expecting. It looks like you're joining 2 strings
> > when defining $sql2 that doesn't leave a space between the close
> > parentheses and "values." Compare this against what you're sending
> > "on the command line."
> >
> > 3.  Get rid of all single quotes... escape your double quotes where
> > needed. This will avoid any variable-in-string interpolation errors
> > and may help you find the issue with input data. Same with your echo
> > $sql2 statement... that's not going to give you the same thing as
> > the print_r below it.
> >
> >
> >
> > Thanks,
> >
> >
> > Daniel Krook
> > Software Engineer, Advanced Cloud Solutions, GTS
> >
> > IBM Senior Certified IT Specialist - L3 Thought Leader
> > The Open Group Certified IT Specialist - L3 Distinguished
> > Cloud, Java, PHP, BlackBerry, DB2 & Solaris Certified
> >
> >
> >
> >
> > Ethan Rosenberg <erosenberg@xxxxxxxxxxxxxxxxxxxx> wrote on 08/21/
> > 2013 07:48:12 PM:
> >
> > > From: Ethan Rosenberg <erosenberg@xxxxxxxxxxxxxxxxxxxx>
> > > To: PHP Database List <php-db@xxxxxxxxxxxxx>
> > > Date: 08/21/2013 07:48 PM
> > > Subject:  mysql query
> > >
> > > Dear List -
> > >
> > > I can't figure this out....
> > >
> > > mysql> describe Inventory;
> > > +-------------+-------------+------+-----+---------+-------+
> > > | Field       | Type        | Null | Key | Default | Extra |
> > > +-------------+-------------+------+-----+---------+-------+
> > > | UPC         | varchar(14) | YES  |     | NULL |       |
> > > | quant       | int(5)      | NO   |     | NULL |       |
> > > | manuf       | varchar(20) | YES  |     | NULL |       |
> > > | item        | varchar(50) | YES  |     | NULL |       |
> > > | orderpt     | tinyint(4)  | NO   |     | NULL |       |
> > > | ordrpt_flag | tinyint(3)  | YES  |     | NULL |       |
> > > | stock       | int(3)      | YES  |     | NULL |       |
> > > +-------------+-------------+------+-----+---------+-------+
> > >
> > > Here are code snippets -
> > >
> > >                            $upc   = $_SESSION['UPC'];
> > >                            $qnt   = $_POST['quant'];
> > >                            $mnf   = $_POST['manuf'];
> > >                            $itm   = $_POST['item'];
> > >                            $odrpt = $_POST['oderpt'];
> > >                            $opf   = $_POST['ordrpt_flag'];
> > >                            $stk    = $_POST['stock'];
> > >
> > >                            $sql2 = "insert into Inventory (UPC, quant,
>
> > > manuf, item, orderpt, ordrpt_flag, stock)"
> > >                                  ."values ('$upc', $qnt,'$mnf','$itm',
>
> > > odrpt, 0, $stk)";
> > >                            $result2 = mysqli_query(cxn, $sql2);
> > >                            echo '$sql2<br />';
> > >                            print_r($sql2);
> > >                            echo "<br />$upc $qnt $mnf $itm $odrpt $opf
>
> > > $stk<kbr />";
> > >                            if (!$result2)
> > >                                  die('Could not enter data: ' .
> > > mysqli_error());
> > >
> > > The mysql query fails.  I cannot figure out why.  It works from the
> > > command line.
> > >
> > > TIA
> > >
> > > Ethan
> > >
> > Daniel -
> >
> > Thanks.
> >
> > Tried all  your suggestions.
> >
> > Sorry, no luck.
> >
> > Ethan

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux