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


Groups > comp.lang.php > #17535

Re: Where did the parens come from

From bill <william@TechServSys.com>
Newsgroups comp.lang.php
Subject Re: Where did the parens come from
Date 2017-07-11 10:26 -0400
Organization Aioe.org NNTP Server
Message-ID <ok2n6c$1207$1@gioia.aioe.org> (permalink)
References <ok0gfs$1pkp$1@gioia.aioe.org> <ok108o$pgf$1@jstuckle.eternal-september.org> <ok2d24$h9s$3@gioia.aioe.org> <ok2ik8$tjc$1@jstuckle.eternal-september.org>

Show all headers | View raw


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

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web