php-general Digest 14 Jul 2010 23:13:55 -0000 Issue 6846

Topics (messages 306887 through 306896):

Re: Posting values of dynamically generated text fields at a  time
        306887 by: Saravanan Murugesan
        306888 by: Saravanan Murugesan

updating a database
        306889 by: David Mehler
        306890 by: Bastien Koert
        306891 by: Bob McConnell
        306892 by: Ashley Sheridan
        306895 by: Tommy Pham

Problem when adding special characters to an XML file
        306893 by: te0t3l

Re: Static Class Member References
        306894 by: David Harkness

Malformed UTF-8 Data in JSON
        306896 by: Dave M G

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---

Regards,

Saravanan Murugesan
Sr. Media Developer

----------------------------------------
Hurix Systems Pvt. Ltd
New No.34 / Old No.10, Taylors Road, Kilpauk, Chennai 600010. INDIA
Phone: +91-044-42284888 ext.852
Mobile: +91-9940295951

----- Original Message ----- From: "Ashley Sheridan" <[email protected]>
To: <[email protected]>
Cc: "Amit Bobade" <[email protected]>; <[email protected]>
Sent: Wednesday, July 14, 2010 2:00 PM
Subject: Re: [PHP] Posting values of dynamically generated text fields at a time


On Wed, 2010-07-14 at 12:08 +0530, Saravanan Murugesan wrote:

> Hi is anybody there to help me out on this?????
>
>>
>> Hi all,
>> I am new to PHP and JS.
>>
>> I am adding new text fields using javascript and I have to save the
>> values
>> of these fields in database in single row. So, how should I post these
>> values? So that I can save them in the db.
>>
>> Additional Info: There are 6 text fields in the row. I have to post >> the
>> information of all the fields collectively.
>>
>> So, please suggest me a way.........
>> --
>> Thanks and Regards,
>> Amit
>>
>>
>
>
> --
> Thanks and Regards,
> Amit
> eArth Solutions Pvt. Ltd
>

Hi,

this would help you,
http://www.w3schools.com/PHP/php_mysql_insert.asp

Thanks,
Saravana


===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not the addressee please tell the sender immediately, and destroy this email without using, sending or storing it. Any opinions, express or implied, in this email, are those of the sender, and are not necessarily approved by Hurix Systems. Except as expressly stated, this e-mail should not be regarded as an offer, solicitation, recommendation or agreement to buy or sell products or services, or to enter into any contract. E-mail transmissions are not secure and may suffer errors, viruses, delay, interception and amendment. Hurix Systems does not accept liability
for damage caused by any of the foregoing.

HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
============================================================



Erm, that's not even remotely an answer to the OPs question...

Thanks,
Ash
http://www.ashleysheridan.co.uk



Hi Amit,

I couldn't able understand exactly what your requirement is. I have attached a php page, just see whether this helps...

This one generates text fields dynamically in a page and then onSubmit it takes the values to DB process...

Thanks,
saravana

===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not 
the addressee
please tell the sender immediately, and destroy this email without using, 
sending or storing
it. Any opinions, express or implied, in this email, are those of the sender, 
and are not
necessarily approved by Hurix Systems. Except as expressly stated, this e-mail 
should not be
regarded as an offer, solicitation, recommendation or agreement to buy or sell 
products or
services, or to enter into any contract. E-mail transmissions are not secure 
and may suffer
errors, viruses, delay, interception and amendment. Hurix Systems does not 
accept liability
for damage caused by any of the foregoing.

HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
============================================================

--- End Message ---
--- Begin Message ---
I couldn't able understand exactly what your requirement is. I have attached 
a php page below, just see whether this helps...

This one generates text fields dynamically in a page and then onSubmit it 
takes the values to DB process...

Thanks,
saravana 

<?php
$postflag = false;
if(isset($_POST['Submit'])) {
$postflag = true;
//Store the values of Text Fields in an Array from global variable $_POST
//{ ... }
print_r($_POST);

$host = "localhost"; //database location
$user = "root"; //database username
$pass = ""; //database password
$db_name = "sample"; //database name

//database connection
$link = mysql_connect($host, $user, $pass);
if (!$link){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $link);

//Query to insert the data
$query = "INSERT INTO sampledb1 ..."; //Insert query including all the values 
stored from $_POST
mysql_query($query, $link);
mysql_close($link);
}
?>
<html>
<head>
<title>DB Sample</title>
<script language="javascript" type="text/javascript">
function addFieldsx() {
document.getElementById('tbl').style.display = 'none';
var n = document.getElementById('x').value;
var frm = document.forms[0];

var dynamicTable = document.createElement("table");
dynamicTable.width = 500;
dynamicTable.border = 0;
dynamicTable.cellpadding = 5;
dynamicTable.cellspacing = 0;
dynamicTable.name = "tbl2";
dynamicTable.id = "tbl2";

for(var i = 0; i < n; i++) {
row = dynamicTable.insertRow(i);
cell0 = row.insertCell(0);
cell0.width = 200;
cell0.align = "right";
cell0.innerHTML = "Text " + (i + 1);

cell1 = row.insertCell(1);
input = document.createElement("input");
input.type = "text"; // set the input's type to a textbox
input.name =  "txt" + (i + 1); // the elements name is "txtArea51"
cell1.appendChild(input);
}

row = dynamicTable.insertRow(i);
cell0 = row.insertCell(0);
cell0.width = 200;
cell0.align = "right";
cell0.innerHTML = "&nbsp;";

cell1 = row.insertCell(1);
input = document.createElement("input");
input.type = "submit"; // set the input's type to a textbox
input.name =  "Submit"; // the elements name is "txtArea51"
cell1.appendChild(input);

frm.appendChild(dynamicTable)

}
</script>
</head>
<body> 
<?PHP
if (!$postflag) {
?> 
<form name="dbfrm" id="dbfrm" action="" method="post"> 
  <table width="500" border="0" cellspacing="5" cellpadding="0" id="tbl"> 
    <tr> 
      <td width="200">&nbsp;</td> 
      <td>&nbsp;</td> 
    </tr> 
    <tr> 
      <td width="200" align="right">No of Fields: </td> 
      <td><input type="textfield" name="x" id="x"/></td> 
    </tr> 
    <tr> 
      <td width="200">&nbsp;</td> 
      <td><input type="button" name="Add" value="Add Fields" 
onClick="addFieldsx()"></td> 
    </tr> 
  </table> 
</form> 
<?php } ?> 
</body>
</HTML>



----- Original Message ----- 
From: "Ashley Sheridan" <[email protected]>
To: <[email protected]>
Cc: "Amit Bobade" <[email protected]>; <[email protected]>
Sent: Wednesday, July 14, 2010 2:00 PM
Subject: Re: [PHP] Posting values of dynamically generated text fields at a time


> On Wed, 2010-07-14 at 12:08 +0530, Saravanan Murugesan wrote:
> 
>> > Hi is anybody there to help me out on this?????
>> >
>> >>
>> >> Hi all,
>> >> I am new to PHP and JS.
>> >>
>> >> I am adding new text fields using javascript and I have to save the
>> >> values
>> >> of these fields in database in single row. So, how should I post these
>> >> values? So that I can save them in the db.
>> >>
>> >> Additional Info: There are 6 text fields in the row. I have to post the
>> >> information of all the fields collectively.
>> >>
>> >> So, please suggest me a way.........
>> >> --
>> >> Thanks and Regards,
>> >> Amit
>> >>
>> >>
>> >
>> >
>> > --
>> > Thanks and Regards,
>> > Amit
>> > eArth Solutions Pvt. Ltd
>> >
>> 
>> Hi,
>> 
>> this would help you,
>> http://www.w3schools.com/PHP/php_mysql_insert.asp
>> 
>> Thanks,
>> Saravana
>> 
>> 
>> ===========================================================
>> ***Disclaimer***
>> 
>> 
>> This email, and any attachments ("this email"), is confidential. If you are 
>> not the addressee
>> please tell the sender immediately, and destroy this email without using, 
>> sending or storing
>> it. Any opinions, express or implied, in this email, are those of the 
>> sender, and are not
>> necessarily approved by Hurix Systems. Except as expressly stated, this 
>> e-mail should not be
>> regarded as an offer, solicitation, recommendation or agreement to buy or 
>> sell products or
>> services, or to enter into any contract. E-mail transmissions are not secure 
>> and may suffer
>> errors, viruses, delay, interception and amendment. Hurix Systems does not 
>> accept liability
>> for damage caused by any of the foregoing.
>> 
>> HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
>> ============================================================
>> 
> 
> 
> Erm, that's not even remotely an answer to the OPs question...
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
>

--- End Message ---
--- Begin Message ---
Hello,
What i'm trying to do certainly doesn't seem hard conceptually, but
coding it has been rough. I'm wondering if anyone has anything
similar.
I've got a database with records. The first time the page is accessed
the submit button won't be selected, so display information about the
record with a checkbox for selection. If a user selects a checkbox and
hits submit, display only that specific record in a form for editing,
once editing is complete feed the edited data back to the database.
I'd like all this to be done in a single sticky file.
If anyone has any code similar to this i'd appreciate getting a look,
mine is nonworking.
Thanks.
Dave.

--- End Message ---
--- Begin Message ---
On Wed, Jul 14, 2010 at 9:59 AM, David Mehler <[email protected]> wrote:
> Hello,
> What i'm trying to do certainly doesn't seem hard conceptually, but
> coding it has been rough. I'm wondering if anyone has anything
> similar.
> I've got a database with records. The first time the page is accessed
> the submit button won't be selected, so display information about the
> record with a checkbox for selection. If a user selects a checkbox and
> hits submit, display only that specific record in a form for editing,
> once editing is complete feed the edited data back to the database.
> I'd like all this to be done in a single sticky file.
> If anyone has any code similar to this i'd appreciate getting a look,
> mine is nonworking.
> Thanks.
> Dave.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Are you passing back the id of the record that you want to see as the
value for the checkbox? It should be a simple matter then of pulling
just that id

<?php

//check and set the id
$id = '';
if(!empty($_POST['id'])){
  $id = (int)$_POST['id'];
}

$sql = "select * from table where 1 ";

if(!empty($id)){
  $sql = " and record_id = $id ";
}

//run query here

...

?>
-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
From: David Mehler

> What i'm trying to do certainly doesn't seem hard conceptually, but
> coding it has been rough. I'm wondering if anyone has anything
> similar.
> I've got a database with records. The first time the page is accessed
> the submit button won't be selected, so display information about the
> record with a checkbox for selection. If a user selects a checkbox and
> hits submit, display only that specific record in a form for editing,
> once editing is complete feed the edited data back to the database.
> I'd like all this to be done in a single sticky file.
> If anyone has any code similar to this i'd appreciate getting a look,
> mine is nonworking.

Mine looks something like this

-----8<-------------------------------------------
    $Submit   = $_POST['Submit'];

    if (isset($CCsubmit)) {
        ////////  DELETE
        if ($Submit == "Delete") {
            // Check to see if user authorized, then delete record

        }
        ////////  NEW
        else if ($Submit == "New" || $Submit == "Next"){
            // Issue empty form or next record

        }
        ////////  EDIT
        else if ($Submit == "Save") {
            // Validate and ssve the updated data. Reissue if validation
fails.

        }
    }
    else {
        // Issue form with initial data



    }
-----8<-------------------------------------------

You should also check in the Save option to see if anything was actually
changed. The record shouldn't be updated if nothing was edited.

Bob McConnell

--- End Message ---
--- Begin Message ---
On Wed, 2010-07-14 at 10:29 -0400, Bob McConnell wrote:

> From: David Mehler
> 
> > What i'm trying to do certainly doesn't seem hard conceptually, but
> > coding it has been rough. I'm wondering if anyone has anything
> > similar.
> > I've got a database with records. The first time the page is accessed
> > the submit button won't be selected, so display information about the
> > record with a checkbox for selection. If a user selects a checkbox and
> > hits submit, display only that specific record in a form for editing,
> > once editing is complete feed the edited data back to the database.
> > I'd like all this to be done in a single sticky file.
> > If anyone has any code similar to this i'd appreciate getting a look,
> > mine is nonworking.
> 
> Mine looks something like this
> 
> -----8<-------------------------------------------
>     $Submit   = $_POST['Submit'];
> 
>     if (isset($CCsubmit)) {
>       ////////  DELETE
>       if ($Submit == "Delete") {
>           // Check to see if user authorized, then delete record
> 
>       }
>       ////////  NEW
>       else if ($Submit == "New" || $Submit == "Next"){
>           // Issue empty form or next record
> 
>       }
>       ////////  EDIT
>       else if ($Submit == "Save") {
>             // Validate and ssve the updated data. Reissue if validation
> fails.
> 
>         }
>     }
>     else {
>         // Issue form with initial data
> 
> 
> 
>     }
> -----8<-------------------------------------------
> 
> You should also check in the Save option to see if anything was actually
> changed. The record shouldn't be updated if nothing was edited.
> 
> Bob McConnell
> 


David, are you looking for something broad or specific? phpMyAdmin does
what you want, so might be a good starting point?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Ashley Sheridan [mailto:[email protected]]
> Sent: Wednesday, July 14, 2010 11:29 AM
> To: Bob McConnell
> Cc: David Mehler; php-general
> Subject: RE: [PHP] updating a database
> 
> On Wed, 2010-07-14 at 10:29 -0400, Bob McConnell wrote:
> 
> > From: David Mehler
> >
> > > What i'm trying to do certainly doesn't seem hard conceptually, but
> > > coding it has been rough. I'm wondering if anyone has anything
> > > similar.
> > > I've got a database with records. The first time the page is
> > > accessed the submit button won't be selected, so display information
> > > about the record with a checkbox for selection. If a user selects a
> > > checkbox and hits submit, display only that specific record in a
> > > form for editing, once editing is complete feed the edited data back to
> the database.
> > > I'd like all this to be done in a single sticky file.
> > > If anyone has any code similar to this i'd appreciate getting a
> > > look, mine is nonworking.
> >
> > Mine looks something like this
> >
> > -----8<-------------------------------------------
> >     $Submit   = $_POST['Submit'];
> >
> >     if (isset($CCsubmit)) {
> >     ////////  DELETE
> >     if ($Submit == "Delete") {
> >         // Check to see if user authorized, then delete record
> >
> >     }
> >     ////////  NEW
> >     else if ($Submit == "New" || $Submit == "Next"){
> >         // Issue empty form or next record
> >
> >     }
> >     ////////  EDIT
> >     else if ($Submit == "Save") {
> >             // Validate and ssve the updated data. Reissue if
> > validation fails.
> >
> >         }
> >     }
> >     else {
> >         // Issue form with initial data
> >
> >
> >
> >     }
> > -----8<-------------------------------------------
> >
> > You should also check in the Save option to see if anything was
> > actually changed. The record shouldn't be updated if nothing was edited.
> >
> > Bob McConnell
> >
> 
> 
> David, are you looking for something broad or specific? phpMyAdmin does
> what you want, so might be a good starting point?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 

I think David is looking for a solution to edit a row from a specific query in 
his own app where the authorized user will edit the selected row.  There are 
several ways to accomplished this.

1) The fancy and less strain on the servers is via AJAX call.  When the user 
click on the check box or some kind of button (link or form type), your 
javascript function will send that particular id back to server and load all 
the relevant info for editing in a div tag.  Your div tag containing the form 
can then do update provided that it passes all the sanity and validation check. 
 Upon the successful update, your code can then reload the table with the 
updated data.

2) The straight forward way is to use the same checkbox or button and submit 
the form (via onclick).  That same page will detect the id and load all the 
relevant info and show the editing form via php's if or include.  After the 
user submit the edit form and the data passes the sanity and validation check, 
your same PHP page can update the data and reload the updated data to display 
in the table.  When you load the edit form, you can choose to display the 
original table data or not.  If you do, it would create unnecessary strain on 
the servers, IMO.

3) Do #2 but implement caching to reduce the strain on the servers.  This 
method will require you to maintain the cache for the updated data.

You'll have to look at your application design, the features & functionality of 
the site/application, your skillset (PHP, Javascript, XML, etc) and choose what 
you think is best.

Regards,
Tommy


--- End Message ---
--- Begin Message ---
Hi, I'm editing an XML file through a form:

$XML = new DOMDocument('1.0', 'UTF-8');
$XML->preserveWhiteSpace = false;
$XML->load("../xml/exposiciones.xml");
$raiz = $XML->documentElement;

$nodoContenedor = $XML->getElementsByTagName('texto');
        foreach ($nodoContenedor as $NuevoNodo)
            {
                //titulo
                $nodoTitulo = $XML->createElement("p",
"&quot;$titulo&quot;");
                $NuevoNodo->appendChild($nodoTitulo);
                $nodoTitulo->setAttribute("class", "titulo");
                $NuevoNodoHijo = $XML->createElement("subtitulo", "
$subtitulo");
                $nodoTitulo->appendChild($NuevoNodoHijo);
                $raiz->appendChild($NuevoNodo);
}

$NodoRefTitulo = $XML->getElementsByTagName('p')->item(0);
$NodoRefTitulo->parentNode->insertBefore($nodoTitulo, $NodoRefTitulo);
$XML->formatOutput = true;
$XML->save("../xml/exposiciones.xml");


The problem is that the special characters that I introduce through the form
(á,é,ó...) corrupt the XML file, and when I try to update again the file,
receipted this error:

Warning: DOMDocument::load() [domdocument.load]: Input is not proper UTF-8,
indicate encoding ! Bytes: 0xF3 0x6E 0x20 0x63 in........

I'd try to fix up it with the label <![CDATA[]]>, and by changing the
encoding -> UTF-8, iso-8859-1 as well,

here: $XML = new DOMDocument('1.0', 'UTF-8'); --> $XML = new
DOMDocument('1.0', 'iso-8859-1');

and in the XML file:

<?xml version="1.0" encoding="utf-8"?> .....

and also I was try:

$subtitulo = str_replace("ó" , "&#243;", utf8_encode($subtitulo));
$subtitulo = str_replace("ó" , "&oacute;;", utf8_encode($subtitulo));

When I open the XML file again i found an strange character between "i" and
"n" exposicion (exposición):

<p class="titulo">"A-foto"<subtitulo> *exposiciﻩn*colectiva.</subtitulo></p>


Anyone know how to solve this problem?

Thanks for your help,

Te0

--- End Message ---
--- Begin Message ---
Ah, so assigning a reference to a variable already holding a reference
changes that variable's reference only in the same way that unsetting a
reference doesn't unset the other variables referencing the same thing, yes?

$a = 5;
$b = &$a;
print $a;
> 5
unset($b);  // does not affect $a
print $a;
> 5

// and according to Mike's previous message
$b = &$a;
$c = 10;
$b = &$c;  // does not affect $a
print $a
> 5

That makes a lot of sense. If it didn't work this way there would be no easy
way to untangle references. In the case of

    foreach($array as $key => &$value) { ... }

the first value in the array would continuously be overwritten by the next
value.

1. $value gets reference to first array value
2. on each step through the loop, the first array value would be overwritten
by the next value in the loop since $value is forever tied to it by the
initial reference assignment.

That would be a Bad Thing (tm).

Thanks for the clarification, Mike.

David

--- End Message ---
--- Begin Message ---
PHP Users,

I'm decoding some JSON data in PHP to convert it into an array.

However, it's not working, and json_last_error() is returning a value of "4", which I believe means "Malformed UTF-8 characters, possibly incorrectly encoded".

I try at every turn in every setting to ensure that all my code and connections are in UTF-8.

But how can I be sure it's valid UTF-8? I've tried using the PHP command utf8_encode() on the string, but that hasn't changed anything.

And can I trust the error message?

Any help or advice would be much appreciated.

By the way, here is the code I'm currently testing with. I'm just encoding and then decoding a string right in the PHP just to get it to work before I even try getting the data from anywhere else.

$myData ='{"display_name":"Test
Guy","email":"[email protected]","timeout":"1279145273"}';
$myArray1 = json_encode($myData);
$myArray2 = utf8_encode (stripslashes($myArray1));
$myArray = json_decode($myArray2, true);
$jsonerror = json_last_error();

--
Dave M G

--- End Message ---

Reply via email to