Re: [PHP-DB] mysql query
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 wrote on 08/21/2013 11:59:19 PM: > From: Ethan Rosenberg > To: Daniel Krook/White Plains/IBM@IBMUS > Cc: PHP Database List > Date: 08/21/2013 11:59 PM > Subject: Re: [PHP-DB] 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 wrote on 08/21/ > 2013 07:48:12 PM: > > > From: Ethan Rosenberg > > To: PHP Database List > > Date: 08/21/2013 07:48 PM > > Subject: [PHP-DB] 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'; > >print_r($sql2); > >echo "$upc $qnt $mnf $itm $odrpt $opf > > $stk"; > >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
Re: [PHP-DB] mysql query
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 wrote on 08/21/2013 07:48:12 PM: > From: Ethan Rosenberg > To: PHP Database List > Date: 08/21/2013 07:48 PM > Subject: [PHP-DB] 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'; >print_r($sql2); >echo "$upc $qnt $mnf $itm $odrpt $opf > $stk"; >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 > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
Re: [PHP-DB] mysql query
On 08/21/2013 07:52 PM, Toby Hart Dyke wrote: 1) What is the error message? 2) This has an error: >values ('$upc', $qnt,'$mnf','$itm', odrpt, 0, $stk) Missing '$' in front of 'odrpt'. Toby On 8/22/2013 12:48 AM, Ethan Rosenberg wrote: 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'; print_r($sql2); echo "$upc $qnt $mnf $itm $odrpt $opf $stk"; 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 Toby - The problem is that I do not get any error messages. From this if (!$result2) die('Could not enter data: ' . mysqli_error()); I only get the 'Could not enter data: and no error message. Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql query
1) What is the error message? 2) This has an error: >values ('$upc', $qnt,'$mnf','$itm', odrpt, 0, $stk) Missing '$' in front of 'odrpt'. Toby On 8/22/2013 12:48 AM, Ethan Rosenberg wrote: 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'; print_r($sql2); echo "$upc $qnt $mnf $itm $odrpt $opf $stk"; 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] 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'; print_r($sql2); echo "$upc $qnt $mnf $itm $odrpt $opf $stk"; 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php