Problem with Arrays and For Each

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ameshkin

    Problem with Arrays and For Each

    What I am trying to do is get all the information in the text area into
    the database. But what happens with this script, is that for each $div,
    a NEW entry gets put into the database. I want EVERYTHING in the text
    area into ONE new entry in the database...

    echo '<textarea name="style" cols="50" rows="5"
    onClick="this.f ocus();this.sel ect()">';
    foreach($match[0] as $div) {
    $div = str_replace('\' ', '"', $div);

    echo $div;

    }

    ?>

    <?php
    echo "</textarea>";

    $sql = mysql_query("IN SERT INTO `layoutsQ` ( `auto` , `site` , `cat` ,
    `code` , `name` )
    VALUES (
    '', 'myspace', '$cat', '$div', '$name'
    )",$piggyban k) or die("db error");

    ?>

  • Jerry Stuckle

    #2
    Re: Problem with Arrays and For Each

    ameshkin wrote:
    What I am trying to do is get all the information in the text area into
    the database. But what happens with this script, is that for each $div,
    a NEW entry gets put into the database. I want EVERYTHING in the text
    area into ONE new entry in the database...
    >
    echo '<textarea name="style" cols="50" rows="5"
    onClick="this.f ocus();this.sel ect()">';
    foreach($match[0] as $div) {
    $div = str_replace('\' ', '"', $div);
    >
    echo $div;
    >
    }
    >
    ?>
    >
    <?php
    echo "</textarea>";
    >
    $sql = mysql_query("IN SERT INTO `layoutsQ` ( `auto` , `site` , `cat` ,
    `code` , `name` )
    VALUES (
    '', 'myspace', '$cat', '$div', '$name'
    )",$piggyban k) or die("db error");
    >
    ?>
    >
    Well, your first problem is one of flow.

    PHP is executed server side. That means all the php in this page is
    executed before the page is sent to the browser.

    If you want the textarea to be inserted into a database, you have to
    create a form and post the form back to the server - the easiest for now
    just to use a second page. In that second page, get the data from the
    request ($_POST['style']) and insert it into the database.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...