Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17527 > unrolled thread

Where did the parens come from

Started bybill <william@TechServSys.com>
First post2017-07-10 14:19 -0400
Last post2017-07-11 08:40 +0200
Articles 16 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  Where did the parens come from bill <william@TechServSys.com> - 2017-07-10 14:19 -0400
    Re: Where did the parens come from "J.O. Aho" <user@example.net> - 2017-07-10 21:17 +0200
      Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-11 07:31 -0400
        Re: Where did the parens come from "J.O. Aho" <user@example.net> - 2017-07-11 18:05 +0200
    Re: Where did the parens come from Jerry Stuckle <jstucklex@attglobal.net> - 2017-07-10 18:53 -0400
      Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-11 07:29 -0400
      Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-11 07:33 -0400
        Re: Where did the parens come from Jerry Stuckle <jstucklex@attglobal.net> - 2017-07-11 09:12 -0400
          Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-11 10:26 -0400
            Re: Where did the parens come from "Peter H. Coffin" <hellsop@ninehells.com> - 2017-07-11 12:55 -0500
              Re: Where did the parens come from "Peter H. Coffin" <hellsop@ninehells.com> - 2017-07-11 13:52 -0500
            Re: Where did the parens come from Jerry Stuckle <jstucklex@attglobal.net> - 2017-07-11 14:57 -0400
              Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-12 08:03 -0400
              Re: Where did the parens come from "Peter H. Coffin" <hellsop@ninehells.com> - 2017-07-12 13:51 -0500
                Re: Where did the parens come from bill <william@TechServSys.com> - 2017-07-13 07:37 -0400
    Re: Where did the parens come from "R.Wieser" <address@not.available> - 2017-07-11 08:40 +0200

#17527 — Where did the parens come from

Frombill <william@TechServSys.com>
Date2017-07-10 14:19 -0400
SubjectWhere did the parens come from
Message-ID<ok0gfs$1pkp$1@gioia.aioe.org>
this works, but...
---------------------------------------------
echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." 
|<pre>";
print_r($postData);
echo "</pre>";	

	$sql = "INSERT INTO `dogs`
	(`hName`,
	`street`,
	`city`,
	`state`,
	`zip`,
	`hPhone`,
	`wPhone`,
	`mPhone`,
	`email`
	)
	VALUES (
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})'
	)
	";
echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";

------------------------------------

the test data:
ogs-basic.php: 251-> mSavePersonData |

Array
(
     [org] => IWROM
     [hName] => my name
     [street] => 123 willoughby
     [city] => MASON
     [state] => MI
     [zip] => 44444
     [hphone] => home
     [wphone] => work
     [cphone] => (517* 881-6007
     [email] => yad@yada
)

dogs-basic.php: 277: sql=>INSERT INTO `dogs`
  (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`, 
`mPhone`, `email` )
VALUES (
  '(my name)', '(my name)', '(my name)', '(my name)', '(my 
name)', '(my name)', '(my name)', '(my name)', '(my name)' )

The sql produced has parens around all the values to be saved 
(and it shouldn't) and I can't figure out where they come form.

yes, I know that I am saving the same value into each cell, it is 
just test data

bill

[toc] | [next] | [standalone]


#17528

From"J.O. Aho" <user@example.net>
Date2017-07-10 21:17 +0200
Message-ID<esi26tFeq43U1@mid.individual.net>
In reply to#17527
On 07/10/17 20:19, bill wrote:

> '$connection->real_escape_string({$postData['hName']})'
>  '(my name)'
> The sql produced has parens around all the values to be saved (and it
> shouldn't) and I can't figure out where they come form.

I would guess it's your { and } which generates the parentheses, try with

"$connection->real_escape_string($postData['hName'])"

-- 

 //Aho

[toc] | [prev] | [next] | [standalone]


#17532

Frombill <william@TechServSys.com>
Date2017-07-11 07:31 -0400
Message-ID<ok2cv5$h9s$2@gioia.aioe.org>
In reply to#17528
On 7/10/2017 3:17 PM, J.O. Aho wrote:
> On 07/10/17 20:19, bill wrote:
> 
>> '$connection->real_escape_string({$postData['hName']})'
>>   '(my name)'
>> The sql produced has parens around all the values to be saved (and it
>> shouldn't) and I can't figure out where they come form.
> 
> I would guess it's your { and } which generates the parentheses, try with
> 
> "$connection->real_escape_string($postData['hName'])"
> 

This results in:
  PHP Parse error:  syntax error, unexpected '$connection' 
(T_VARIABLE) in 
/home/michigan/public_html/IrishWolfhoundRescue.org/application/dogs-basic.php 
on line 268

[toc] | [prev] | [next] | [standalone]


#17536

From"J.O. Aho" <user@example.net>
Date2017-07-11 18:05 +0200
Message-ID<eskba2F7i9U1@mid.individual.net>
In reply to#17532
On 07/11/17 13:31, bill wrote:
> On 7/10/2017 3:17 PM, J.O. Aho wrote:
>> On 07/10/17 20:19, bill wrote:
>>
>>> '$connection->real_escape_string({$postData['hName']})'
>>>   '(my name)'
>>> The sql produced has parens around all the values to be saved (and it
>>> shouldn't) and I can't figure out where they come form.
>>
>> I would guess it's your { and } which generates the parentheses, try with
>>
>> "$connection->real_escape_string($postData['hName'])"
>>
> 
> This results in:
>  PHP Parse error:  syntax error, unexpected '$connection' (T_VARIABLE)
> in
> /home/michigan/public_html/IrishWolfhoundRescue.org/application/dogs-basic.php
> on line 268

Maybe it's better to have it outside the string:

. $connection->real_escape_string($postData['hName']) . ", "


-- 

 //Aho

[toc] | [prev] | [next] | [standalone]


#17529

FromJerry Stuckle <jstucklex@attglobal.net>
Date2017-07-10 18:53 -0400
Message-ID<ok108o$pgf$1@jstuckle.eternal-september.org>
In reply to#17527
On 7/10/2017 2:19 PM, bill wrote:
> this works, but...
> ---------------------------------------------
> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." |<pre>";
> print_r($postData);
> echo "</pre>";   
> 
>     $sql = "INSERT INTO `dogs`
>     (`hName`,
>     `street`,
>     `city`,
>     `state`,
>     `zip`,
>     `hPhone`,
>     `wPhone`,
>     `mPhone`,
>     `email`
>     )
>     VALUES (
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})'
>     )
>     ";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
> 
> ------------------------------------
> 
> the test data:
> ogs-basic.php: 251-> mSavePersonData |
> 
> Array
> (
>     [org] => IWROM
>     [hName] => my name
>     [street] => 123 willoughby
>     [city] => MASON
>     [state] => MI
>     [zip] => 44444
>     [hphone] => home
>     [wphone] => work
>     [cphone] => (517* 881-6007
>     [email] => yad@yada
> )
> 
> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>  (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
> `mPhone`, `email` )
> VALUES (
>  '(my name)', '(my name)', '(my name)', '(my name)', '(my name)', '(my
> name)', '(my name)', '(my name)', '(my name)' )
> 
> The sql produced has parens around all the values to be saved (and it
> shouldn't) and I can't figure out where they come form.
> 
> yes, I know that I am saving the same value into each cell, it is just
> test data
> 
> bill

Are you sure this is the code you're using?  If so, look at the source
code for your page.

The code you showed does not match the output you displayed.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17531

Frombill <william@TechServSys.com>
Date2017-07-11 07:29 -0400
Message-ID<ok2cqk$h9s$1@gioia.aioe.org>
In reply to#17529
On 7/10/2017 6:53 PM, Jerry Stuckle wrote:
> On 7/10/2017 2:19 PM, bill wrote:
>> this works, but...
>> ---------------------------------------------
>> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." |<pre>";
>> print_r($postData);
>> echo "</pre>";
>>
>>      $sql = "INSERT INTO `dogs`
>>      (`hName`,
>>      `street`,
>>      `city`,
>>      `state`,
>>      `zip`,
>>      `hPhone`,
>>      `wPhone`,
>>      `mPhone`,
>>      `email`
>>      )
>>      VALUES (
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})'
>>      )
>>      ";
>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>
>> ------------------------------------
>>
>> the test data:
>> ogs-basic.php: 251-> mSavePersonData |
>>
>> Array
>> (
>>      [org] => IWROM
>>      [hName] => my name
>>      [street] => 123 willoughby
>>      [city] => MASON
>>      [state] => MI
>>      [zip] => 44444
>>      [hphone] => home
>>      [wphone] => work
>>      [cphone] => (517* 881-6007
>>      [email] => yad@yada
>> )
>>
>> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>>   (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
>> `mPhone`, `email` )
>> VALUES (
>>   '(my name)', '(my name)', '(my name)', '(my name)', '(my name)', '(my
>> name)', '(my name)', '(my name)', '(my name)' )
>>
>> The sql produced has parens around all the values to be saved (and it
>> shouldn't) and I can't figure out where they come form.
>>
>> yes, I know that I am saving the same value into each cell, it is just
>> test data
>>
>> bill
> 
> Are you sure this is the code you're using?  If so, look at the source
> code for your page.
> 
> The code you showed does not match the output you displayed.

I acknowledge I am a terrible proofreader, but I did not edit the 
output before I cut/pasted it here.
Where do you see the mismatch ?
bill

[toc] | [prev] | [next] | [standalone]


#17533

Frombill <william@TechServSys.com>
Date2017-07-11 07:33 -0400
Message-ID<ok2d24$h9s$3@gioia.aioe.org>
In reply to#17529
On 7/10/2017 6:53 PM, Jerry Stuckle wrote:
> On 7/10/2017 2:19 PM, bill wrote:
>> this works, but...
>> ---------------------------------------------
>> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." |<pre>";
>> print_r($postData);
>> echo "</pre>";
>>
>>      $sql = "INSERT INTO `dogs`
>>      (`hName`,
>>      `street`,
>>      `city`,
>>      `state`,
>>      `zip`,
>>      `hPhone`,
>>      `wPhone`,
>>      `mPhone`,
>>      `email`
>>      )
>>      VALUES (
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})'
>>      )
>>      ";
>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>
>> ------------------------------------
>>
>> the test data:
>> ogs-basic.php: 251-> mSavePersonData |
>>
>> Array
>> (
>>      [org] => IWROM
>>      [hName] => my name
>>      [street] => 123 willoughby
>>      [city] => MASON
>>      [state] => MI
>>      [zip] => 44444
>>      [hphone] => home
>>      [wphone] => work
>>      [cphone] => (517* 881-6007
>>      [email] => yad@yada
>> )
>>
>> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>>   (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
>> `mPhone`, `email` )
>> VALUES (
>>   '(my name)', '(my name)', '(my name)', '(my name)', '(my name)', '(my
>> name)', '(my name)', '(my name)', '(my name)' )
>>
>> The sql produced has parens around all the values to be saved (and it
>> shouldn't) and I can't figure out where they come form.
>>
>> yes, I know that I am saving the same value into each cell, it is just
>> test data
>>
>> bill
> 
> Are you sure this is the code you're using?  If so, look at the source
> code for your page.
> 
> The code you showed does not match the output you displayed.
> 
Jerry, here is the full source code of the function

//---------------------------------------------------------page 1 
of a dog needs help -------------------

function mSavePersonData($postData)   { // mSavePersonData
	global $connection;
	// $postData contains the $_POST data from rescueDog1.php
echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." 
|<pre>";
print_r($postData);
echo "</pre>";	
	$sql = "INSERT INTO `dogs`
	(`status`,
	`hName`,
	`street`,
	`city`,
	`state`,
	`zip`,
	`hPhone`,
	`wPhone`,
	`mPhone`,
	`email`
	)
	VALUES (
	'new',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])',
'$connection->real_escape_string($postData["hName"])'
	)
	";
echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
	$result =mysqli_query($connection, $sql);
	if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." 
on line " . __LINE__ . "  " .  $connection->error);

     } //mSavePersonData
	

[toc] | [prev] | [next] | [standalone]


#17534

FromJerry Stuckle <jstucklex@attglobal.net>
Date2017-07-11 09:12 -0400
Message-ID<ok2ik8$tjc$1@jstuckle.eternal-september.org>
In reply to#17533
On 7/11/2017 7:33 AM, bill wrote:
> On 7/10/2017 6:53 PM, Jerry Stuckle wrote:
>> On 7/10/2017 2:19 PM, bill wrote:
>>> this works, but...
>>> ---------------------------------------------
>>> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ."
>>> |<pre>";
>>> print_r($postData);
>>> echo "</pre>";
>>>
>>>      $sql = "INSERT INTO `dogs`
>>>      (`hName`,
>>>      `street`,
>>>      `city`,
>>>      `state`,
>>>      `zip`,
>>>      `hPhone`,
>>>      `wPhone`,
>>>      `mPhone`,
>>>      `email`
>>>      )
>>>      VALUES (
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})',
>>> '$connection->real_escape_string({$postData['hName']})'
>>>      )
>>>      ";
>>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>>
>>> ------------------------------------
>>>
>>> the test data:
>>> ogs-basic.php: 251-> mSavePersonData |
>>>
>>> Array
>>> (
>>>      [org] => IWROM
>>>      [hName] => my name
>>>      [street] => 123 willoughby
>>>      [city] => MASON
>>>      [state] => MI
>>>      [zip] => 44444
>>>      [hphone] => home
>>>      [wphone] => work
>>>      [cphone] => (517* 881-6007
>>>      [email] => yad@yada
>>> )
>>>
>>> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>>>   (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
>>> `mPhone`, `email` )
>>> VALUES (
>>>   '(my name)', '(my name)', '(my name)', '(my name)', '(my name)', '(my
>>> name)', '(my name)', '(my name)', '(my name)' )
>>>
>>> The sql produced has parens around all the values to be saved (and it
>>> shouldn't) and I can't figure out where they come form.
>>>
>>> yes, I know that I am saving the same value into each cell, it is just
>>> test data
>>>
>>> bill
>>
>> Are you sure this is the code you're using?  If so, look at the source
>> code for your page.
>>
>> The code you showed does not match the output you displayed.
>>
> Jerry, here is the full source code of the function
> 
> //---------------------------------------------------------page 1 of a
> dog needs help -------------------
> 
> function mSavePersonData($postData)   { // mSavePersonData
>     global $connection;
>     // $postData contains the $_POST data from rescueDog1.php
> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." |<pre>";
> print_r($postData);
> echo "</pre>";   
>     $sql = "INSERT INTO `dogs`
>     (`status`,
>     `hName`,
>     `street`,
>     `city`,
>     `state`,
>     `zip`,
>     `hPhone`,
>     `wPhone`,
>     `mPhone`,
>     `email`
>     )
>     VALUES (
>     'new',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])',
> '$connection->real_escape_string($postData["hName"])'
>     )
>     ";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>     $result =mysqli_query($connection, $sql);
>     if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
> line " . __LINE__ . "  " .  $connection->error);
> 
>     } //mSavePersonData
>     
> 

When trying to run your code I get the following:

Parse error: syntax error, unexpected '"', expecting '-' or identifier
(T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

This occurs on your first

'$connection->real_escape_string($postData["hName"])',

line.

This is with PHP 7.1.4.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17535

Frombill <william@TechServSys.com>
Date2017-07-11 10:26 -0400
Message-ID<ok2n6c$1207$1@gioia.aioe.org>
In reply to#17534
On 7/11/2017 9:12 AM, Jerry Stuckle wrote:
> On 7/11/2017 7:33 AM, bill wrote:
>> On 7/10/2017 6:53 PM, Jerry Stuckle wrote:
>>> On 7/10/2017 2:19 PM, bill wrote:
>>>> this works, but...
>>>> ---------------------------------------------
>>>> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ."
>>>> |<pre>";
>>>> print_r($postData);
>>>> echo "</pre>";
>>>>
>>>>       $sql = "INSERT INTO `dogs`
>>>>       (`hName`,
>>>>       `street`,
>>>>       `city`,
>>>>       `state`,
>>>>       `zip`,
>>>>       `hPhone`,
>>>>       `wPhone`,
>>>>       `mPhone`,
>>>>       `email`
>>>>       )
>>>>       VALUES (
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})',
>>>> '$connection->real_escape_string({$postData['hName']})'
>>>>       )
>>>>       ";
>>>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>>>
>>>> ------------------------------------
>>>>
>>>> the test data:
>>>> ogs-basic.php: 251-> mSavePersonData |
>>>>
>>>> Array
>>>> (
>>>>       [org] => IWROM
>>>>       [hName] => my name
>>>>       [street] => 123 willoughby
>>>>       [city] => MASON
>>>>       [state] => MI
>>>>       [zip] => 44444
>>>>       [hphone] => home
>>>>       [wphone] => work
>>>>       [cphone] => (517* 881-6007
>>>>       [email] => yad@yada
>>>> )
>>>>
>>>> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>>>>    (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
>>>> `mPhone`, `email` )
>>>> VALUES (
>>>>    '(my name)', '(my name)', '(my name)', '(my name)', '(my name)', '(my
>>>> name)', '(my name)', '(my name)', '(my name)' )
>>>>
>>>> The sql produced has parens around all the values to be saved (and it
>>>> shouldn't) and I can't figure out where they come form.
>>>>
>>>> yes, I know that I am saving the same value into each cell, it is just
>>>> test data
>>>>
>>>> bill
>>>
>>> Are you sure this is the code you're using?  If so, look at the source
>>> code for your page.
>>>
>>> The code you showed does not match the output you displayed.
>>>
>> Jerry, here is the full source code of the function
>>
>> //---------------------------------------------------------page 1 of a
>> dog needs help -------------------
>>
>> function mSavePersonData($postData)   { // mSavePersonData
>>      global $connection;
>>      // $postData contains the $_POST data from rescueDog1.php
>> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ." |<pre>";
>> print_r($postData);
>> echo "</pre>";
>>      $sql = "INSERT INTO `dogs`
>>      (`status`,
>>      `hName`,
>>      `street`,
>>      `city`,
>>      `state`,
>>      `zip`,
>>      `hPhone`,
>>      `wPhone`,
>>      `mPhone`,
>>      `email`
>>      )
>>      VALUES (
>>      'new',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])',
>> '$connection->real_escape_string($postData["hName"])'
>>      )
>>      ";
>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>      $result =mysqli_query($connection, $sql);
>>      if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
>> line " . __LINE__ . "  " .  $connection->error);
>>
>>      } //mSavePersonData
>>      
>>
> 
> When trying to run your code I get the following:
> 
> Parse error: syntax error, unexpected '"', expecting '-' or identifier
> (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
> 
> This occurs on your first
> 
> '$connection->real_escape_string($postData["hName"])',
> 
> line.
> 
> This is with PHP 7.1.4.
> 

Sorry, that was the code J.O. Aho suggested.
Here is the current code.
----------------------
//---------------------------------------------------------page 1 
of a dog needs help -------------------
function mSavePersonData($postData)   { // mSavePersonData
	global $connection;
	// $postData contains the $_POST data from rescueDog1.php
	
	$sql = "INSERT INTO `dogs`
	(`hName`,
	`street`,
	`city`,
	`state`,
	`zip`,
	`hPhone`,
	`wPhone`,
	`cPhone`,
	`email`
	)
	VALUES (
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})',
'$connection->real_escape_string({$postData['hName']})'
	)
	";
echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
	$result =mysqli_query($connection, $sql);
	if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." 
on line " . __LINE__ . "  " .  $connection->error);
----------------------

interestingly, when the function runs the sql row generated has 
the parens.

This is with php 5.x (.5 I think)
-bill

[toc] | [prev] | [next] | [standalone]


#17537

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2017-07-11 12:55 -0500
Message-ID<slrnoma485.4ah.hellsop@nibelheim.ninehells.com>
In reply to#17535
On Tue, 11 Jul 2017 10:26:19 -0400, bill wrote:
> Here is the current code.
> ----------------------
> //---------------------------------------------------------page 1 
> of a dog needs help -------------------
> function mSavePersonData($postData)   { // mSavePersonData
> 	global $connection;
> 	// $postData contains the $_POST data from rescueDog1.php
> 	
> 	$sql = "INSERT INTO `dogs`
> 	(`hName`,
> 	`street`,
> 	`city`,
> 	`state`,
> 	`zip`,
> 	`hPhone`,
> 	`wPhone`,
> 	`cPhone`,
> 	`email`
> 	)
> 	VALUES (
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})'
> 	)
> 	";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
> 	$result =mysqli_query($connection, $sql);
> 	if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." 
> on line " . __LINE__ . "  " .  $connection->error);
> ----------------------
>
> interestingly, when the function runs the sql row generated has 
> the parens.

For giggles, try this:

function mSavePersonData($postData)   { // mSavePersonData
        global $connection;
        // $postData contains the $_POST data from rescueDog1.php

        $sql = "INSERT INTO `dogs`
        (`hName`,
        `street`,
        `city`,
        `state`,
        `zip`,
        `hPhone`,
        `wPhone`,
        `cPhone`,
        `email`
        )
        VALUES (
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})}',
'{$connection->real_escape_string({$postData['hName']})'
        )
        ";


Because that's how it's shown on the manual page for the string types.
There are no object variables that I can see that are both interpreted
inside quoted strings that aren't also brace-wrapped at the object
level.

It's also killing me inside that all the indexes are 'hName' and not
'street', 'city', etc.

-- 
"This system operates under martial law. The constitution is suspended.
 You have no rights except as declared by the area commander. Violators
 will be shot. Repeat violators will be repeatedly shot...."        
      -from "A_W_O_L"

[toc] | [prev] | [next] | [standalone]


#17538

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2017-07-11 13:52 -0500
Message-ID<slrnoma7ji.4ah.hellsop@nibelheim.ninehells.com>
In reply to#17537
On Tue, 11 Jul 2017 12:55:17 -0500, Peter H. Coffin wrote:
> '{$connection->real_escape_string({$postData['hName']})}',
> '{$connection->real_escape_string({$postData['hName']})}',
> '{$connection->real_escape_string({$postData['hName']})}',
> '{$connection->real_escape_string({$postData['hName']})}',
> '{$connection->real_escape_string({$postData['hName']})}',
> '{$connection->real_escape_string({$postData['hName']})'
I missed one here ---------------------------------------^
>         )
>         ";

-- 
Tomorrow is the first day of the rest of your life in a career where, if
you really suck, 100% of your work fails and if you're really good and 
really lucky only 99% of it is a complete waste of time. - Hal Bogerd

[toc] | [prev] | [next] | [standalone]


#17539

FromJerry Stuckle <jstucklex@attglobal.net>
Date2017-07-11 14:57 -0400
Message-ID<ok36qf$658$1@jstuckle.eternal-september.org>
In reply to#17535
On 7/11/2017 10:26 AM, bill wrote:
> function mSavePersonData($postData)   { // mSavePersonData
>     global $connection;
>     // $postData contains the $_POST data from rescueDog1.php
>     
>     $sql = "INSERT INTO `dogs`
>     (`hName`,
>     `street`,
>     `city`,
>     `state`,
>     `zip`,
>     `hPhone`,
>     `wPhone`,
>     `cPhone`,
>     `email`
>     )
>     VALUES (
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})'
>     )
>     ";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>     $result =mysqli_query($connection, $sql);
>     if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
> line " . __LINE__ . "  " .  $connection->error);

OK, I was able to duplicate it here.  Very interesting.  I haven't run
into this before because I really don't like trying to evaluate values
within a string.  I changed it to the following, which is more my style.
 It's a bit more of a hassle, but it works all the time.

function mSavePersonData($postData)   { // mSavePersonData
    global $connection;
    // $postData contains the $_POST data from rescueDog1.php

    $sql = "INSERT INTO `dogs`
    (`hName`,
    `street`,
    `city`,
    `state`,
    `zip`,
    `hPhone`,
    `wPhone`,
    `cPhone`,
    `email`
    )
    VALUES (
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "',
'" . $connection->real_escape_string($postData['hName']) . "'
    )
    ";
echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
    $result =mysqli_query($connection, $sql);
    if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
line " . __LINE__ . "  " .  $connection->error);
    } //mSavePersonData

Notice I've taken the function calls out of the quotes and just
concatenated them.

You could also use prepared statements and bound variables; some people
prefer doing it that way (and you don't need to escape the strings).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17540

Frombill <william@TechServSys.com>
Date2017-07-12 08:03 -0400
Message-ID<ok5366$5k9$1@gioia.aioe.org>
In reply to#17539
On 7/11/2017 2:57 PM, Jerry Stuckle wrote:
> On 7/11/2017 10:26 AM, bill wrote:
>> function mSavePersonData($postData)   { // mSavePersonData
>>      global $connection;
>>      // $postData contains the $_POST data from rescueDog1.php
>>      
>>      $sql = "INSERT INTO `dogs`
>>      (`hName`,
>>      `street`,
>>      `city`,
>>      `state`,
>>      `zip`,
>>      `hPhone`,
>>      `wPhone`,
>>      `cPhone`,
>>      `email`
>>      )
>>      VALUES (
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})',
>> '$connection->real_escape_string({$postData['hName']})'
>>      )
>>      ";
>> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>>      $result =mysqli_query($connection, $sql);
>>      if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
>> line " . __LINE__ . "  " .  $connection->error);
> 
> OK, I was able to duplicate it here.  Very interesting.  I haven't run
> into this before because I really don't like trying to evaluate values
> within a string.  I changed it to the following, which is more my style.
>   It's a bit more of a hassle, but it works all the time.
> 
> function mSavePersonData($postData)   { // mSavePersonData
>      global $connection;
>      // $postData contains the $_POST data from rescueDog1.php
> 
>      $sql = "INSERT INTO `dogs`
>      (`hName`,
>      `street`,
>      `city`,
>      `state`,
>      `zip`,
>      `hPhone`,
>      `wPhone`,
>      `cPhone`,
>      `email`
>      )
>      VALUES (
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "'
>      )
>      ";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>      $result =mysqli_query($connection, $sql);
>      if (!$result) die("MySql ERROR in dogs-basic: ".__FUNCTION__." on
> line " . __LINE__ . "  " .  $connection->error);
>      } //mSavePersonData
> 
> Notice I've taken the function calls out of the quotes and just
> concatenated them.

That's nice

-bill

[toc] | [prev] | [next] | [standalone]


#17541

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2017-07-12 13:51 -0500
Message-ID<slrnomcruc.4ah.hellsop@nibelheim.ninehells.com>
In reply to#17539
On Tue, 11 Jul 2017 14:57:31 -0400, Jerry Stuckle wrote:
> OK, I was able to duplicate it here.  Very interesting.  I haven't run
> into this before because I really don't like trying to evaluate values
> within a string.  I changed it to the following, which is more my style.
>  It's a bit more of a hassle, but it works all the time.

...

> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',
> '" . $connection->real_escape_string($postData['hName']) . "',

Yup, "build" the string instead of "interpret" the string. 
That's exactly how I rewrote it first, but I couldn't think of a good
reason to throw out what SHOULD work just because it ... didn't. So I
went looking for a difference that might make a difference to the
interpretor/parser that wouldn't make a difference to me, and that's
where I got to the "Wait, all of these objects have braces around the
whole thing. It didn't SAY it was needed, but the ostensibly Smart
People are doing it..."

-- 
63. Bulk trash will be disposed of in incinerators, not compactors. And
    they will be kept hot, with none of that nonsense about flames 
    going through accessible tunnels at predictable intervals.
	--Peter Anspach's list of things to do as an Evil Overlord

[toc] | [prev] | [next] | [standalone]


#17543

Frombill <william@TechServSys.com>
Date2017-07-13 07:37 -0400
Message-ID<ok7m2l$1q26$1@gioia.aioe.org>
In reply to#17541
On 7/12/2017 2:51 PM, Peter H. Coffin wrote:
> On Tue, 11 Jul 2017 14:57:31 -0400, Jerry Stuckle wrote:
>> OK, I was able to duplicate it here.  Very interesting.  I haven't run
>> into this before because I really don't like trying to evaluate values
>> within a string.  I changed it to the following, which is more my style.
>>   It's a bit more of a hassle, but it works all the time.
> 
> ...
> 
>> '" . $connection->real_escape_string($postData['hName']) . "',
>> '" . $connection->real_escape_string($postData['hName']) . "',
>> '" . $connection->real_escape_string($postData['hName']) . "',
> 
> Yup, "build" the string instead of "interpret" the string.
> That's exactly how I rewrote it first, but I couldn't think of a good
> reason to throw out what SHOULD work just because it ... didn't. 

LOL

>So I
> went looking for a difference that might make a difference to the
> interpretor/parser that wouldn't make a difference to me, and that's
> where I got to the "Wait, all of these objects have braces around the
> whole thing. It didn't SAY it was needed, but the ostensibly Smart
> People are doing it..."
> 

[toc] | [prev] | [next] | [standalone]


#17530

From"R.Wieser" <address@not.available>
Date2017-07-11 08:40 +0200
Message-ID<ok1rqq$1k1b$1@gioia.aioe.org>
In reply to#17527
Bill,

> has parens around all the values to be saved (and it shouldn't)

Are you sure (and why) ?

From https://www.w3schools.com/PHP/php_mysql_insert.asp

[quote]
Here are some syntax rules to follow:
...
String values inside the SQL query must be quoted
[/quote]

To me it looks as if your PHP environment just tries to be helpful (by
adding those quotes) ...

Regards,
Rudy Wieser


-- Origional message:
bill <william@TechServSys.com> schreef in berichtnieuws
ok0gfs$1pkp$1@gioia.aioe.org...
> this works, but...
> ---------------------------------------------
> echo basename(__FILE__).": " . __LINE__ . "-> " . __FUNCTION__ ."
> |<pre>";
> print_r($postData);
> echo "</pre>";
>
> $sql = "INSERT INTO `dogs`
> (`hName`,
> `street`,
> `city`,
> `state`,
> `zip`,
> `hPhone`,
> `wPhone`,
> `mPhone`,
> `email`
> )
> VALUES (
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})',
> '$connection->real_escape_string({$postData['hName']})'
> )
> ";
> echo basename(__FILE__) . ": " . __LINE__ . ": sql=>$sql<br />";
>
> ------------------------------------
>
> the test data:
> ogs-basic.php: 251-> mSavePersonData |
>
> Array
> (
>      [org] => IWROM
>      [hName] => my name
>      [street] => 123 willoughby
>      [city] => MASON
>      [state] => MI
>      [zip] => 44444
>      [hphone] => home
>      [wphone] => work
>      [cphone] => (517* 881-6007
>      [email] => yad@yada
> )
>
> dogs-basic.php: 277: sql=>INSERT INTO `dogs`
>   (`hName`, `street`, `city`, `state`, `zip`, `hPhone`, `wPhone`,
> `mPhone`, `email` )
> VALUES (
>   '(my name)', '(my name)', '(my name)', '(my name)', '(my
> name)', '(my name)', '(my name)', '(my name)', '(my name)' )
>
> The sql produced has parens around all the values to be saved
> (and it shouldn't) and I can't figure out where they come form.
>
> yes, I know that I am saving the same value into each cell, it is
> just test data
>
> bill

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web