have to "actions" or run two types of queries (select,and update) on the same form?

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

    #1

    have to "actions" or run two types of queries (select,and update) on the same form?

    Hello PHP programmers.

    I had a brilliant idea on one of my pages that selects some data from
    my mysql database.
    I first set the page up to display some info and an image, just one
    item, with a row of data, etc.

    then I thought it would be nice to do a select, and perhaps an update
    (the title of the image) on the same page.

    I am wondering if I am having the wrong idea. I have a form, with two
    submit buttons, one selects an image, and some info. the other will
    update the image title for the given image (id, and p).
    I am seeing that I have a mistake here, since it seems the update
    query will run as well as when the select query is run (select button
    clicked). this overwrites my image titles in the db.

    I have the wrong idea, but have not seen how to do this "right". I
    could use another php page for update, but I am guessing this can be
    done from the same page.

    Below is my poor code - i am not an expert programmer!!! any help,
    suggestions will be helpful.

    <?php

    $img = $_REQUEST["img"];
    $p = $_REQUEST["p"];

    echo '<div class="input">' ."".'</div>';
    //connection files for mysql
    @include 'c:/php/includes/db.inc';
    @include 'c:/php/includes/error.inc';
    //***@include '/usr/local/php/include/db.inc';
    //***@include '/usr/local/php/include/error.inc';
    //@require_once '/usr/local/php/include/size_image.php' ;

    global $dbconnect, $query;

    here is the select stuff...

    if ($_REQUEST['img'] != 0 && $_REQUEST['p'] 99 ) {


    echo $_REQUEST['updatetitle'];

    $dbconnect = @db_connect('po rtfolios') or
    trigger_error(" Error Connecting to Database: ". mysql_error(),
    E_USER_ERROR);

    $result = @mysql_query("S ELECT * FROM images3 WHERE id=" . $img . "
    AND p=" .$p. "");

    if (!$result)
    {
    echo("Error performing query: " . mysql_error() . "");
    exit();
    }

    $row = @mysql_fetch_ar ray($result);

    $imgid = $row["id"];
    $title = $row["title"];
    $mod = $row["modfolder"];
    $name = $row["name"];
    $height = $row["resize_hei ght"];
    $width = $row["resize_wid th"];
    $image = $row['modfolder'].'/'.$row['name'];

    }
    ?>
    <center><h2>Ima ge Database Query View</h2>
    <a><?php echo "Database Image Browser" ?></a>
    <body>
    <hr>
    <div id="entry">
    <h3>Enter ID for image...<!--input type="hidden" name="MAX_FILE_ SIZE"
    value="150000"-->
    <input type="hidden" name=updatetitl e value=<?php $update ?>>
    </h3>
    <form enctype=multipa rt/form-data action="display _orders.php"
    method=post>
    <?php
    //here is the update stuff
    if ($_REQUEST['title'] != '' )

    {

    $img = $_REQUEST["img"];
    $p = $_REQUEST["p"];
    $update = 1;

    $query = 'UPDATE images3 SET title =\' ' . TRIM($_REQUEST['title']).
    '\' WHERE id = ' . $_REQUEST['img'] .
    ' AND p=' . $_REQUEST['p'] .';';

    //echo $query;
    $dbconnect = @db_connect('po rtfolios') or
    trigger_error(" Error Connecting to Database: ". mysql_error(),
    E_USER_ERROR);

    $result = @mysql_query($q uery);

    if (!$result)
    {
    echo("Error performing query: " . mysql_error() . "");
    exit();
    }

    if ($result 0) echo '<div class="input">' ."Title Updated".'</div>';

    mysql_free_resu lt($result);
    mysql_close($db connect);
    }
    ?>
    <div id="imgid" class="input" >Enter Image ID: <input name=img
    type=text size="6"></div>
    <!--br-->
    <div class="input">E nter Portfolio Number: <input name=p type=text
    size="6"></div>
    <!--br-->
    <div id="btn" class="input">T hen Click: <input type="submit"
    value="Select Image"></div>
    <div id="udate">
    <div id="imgtitle" class="input" >Enter or Change Title: <input
    name=title type=text size="55"
    value=" <?php echo $title ?>" ></div>
    <div id="btn" class="update"> Click to Update: <input type="submit"
    value="Update Title"></div>
    </div>
    </form>
    </div>
    <hr>
    <table class="maintabl e" border=1>
    <tr class="rowbar"> <th>Image ID</th><th>Modfolde r</th><th>Name</
    th><th>Title</th><th>Resize(h )</th><th>Resize(w )</th></tr>
    <?php
    // get the data again??? no , move the pointer!!
    //*** $result = @mysql_query("S ELECT * FROM images3 WHERE id=" .
    $img . " AND p=" .$p. "");
    // generate the table
    //while ( $row = @mysql_fetch_ar ray($result) )
    //{
    ?>
    <tr>
    <td><?php echo $imgid ?></td>
    <td><?php echo $mod ?></td>
    <td><?php echo $name ?></td>
    <td><?php echo $title ?></td>
    <td><?php echo $height ?></td>
    <td><?php echo $width ?></td>
    </tr>
    <tr><td valign="middle" align="center" class="mainbox" colspan="6">
    <?php
    //$image = $row['modfolder'].'/'.$row['name'];
    echo '<img class="mainimag e" src="'. "$image" .'"'. ' alt=""
    '.'height="'.$h eight.'"'.' width="'.$width .'"' .'/>';

    ?>
    </td></tr>
    <?php
    mysql_free_resu lt($result);
    mysql_close($db connect);
    ?>
    </table>
    </body>
    </html>


    thanks for your suggestions, etc
    ewholz

  • Kimmo Laine

    #2
    Re: have to &quot;actions&q uot; or run two types of queries (select,and update) on the same form?

    "eholz1" <ewholz@gmail.c omwrote in message
    news:1171321767 .611070.208900@ p10g2000cwp.goo glegroups.com.. .
    Hello PHP programmers.
    >
    I had a brilliant idea on one of my pages that selects some data from
    my mysql database.
    I first set the page up to display some info and an image, just one
    item, with a row of data, etc.
    >
    then I thought it would be nice to do a select, and perhaps an update
    (the title of the image) on the same page.
    >
    I am wondering if I am having the wrong idea. I have a form, with two
    submit buttons, one selects an image, and some info. the other will
    update the image title for the given image (id, and p).
    I am seeing that I have a mistake here, since it seems the update
    query will run as well as when the select query is run (select button
    clicked). this overwrites my image titles in the db.
    >
    I have the wrong idea, but have not seen how to do this "right". I
    could use another php page for update, but I am guessing this can be
    done from the same page.
    >
    Below is my poor code - i am not an expert programmer!!! any help,
    suggestions will be helpful.

    Too long code, didn't read it all, but here's a tip for you: Have two submit
    buttons, but name them differently. On server-side you test which button was
    clicked based on which submit was sent. (Of several submit buttons, only the
    one that was clicked is sent in the form)
    <input type="submit" name"select" value="select-a-mundo!" />
    <input type="submit" name"update" value="update-a-mundo!" />

    on server-side this code will tell you which was clicked:
    <?php
    if(isset($_POST['select'])){
    // Now you run the select query
    } else if(isset($_POST['update'])){
    // Now run the update query
    }
    ?>


    --
    "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
    http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
    spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


    Comment

    • eholz1

      #3
      Re: have to &quot;actions&q uot; or run two types of queries (select,and update) on the same form?

      On Feb 12, 10:45 pm, "Kimmo Laine" <s...@outolempi .netwrote:
      "eholz1" <ewh...@gmail.c omwrote in message
      >
      news:1171321767 .611070.208900@ p10g2000cwp.goo glegroups.com.. .
      >
      >
      >
      Hello PHP programmers.
      >
      I had a brilliant idea on one of my pages that selects some data from
      my mysql database.
      I first set the page up to display some info and an image, just one
      item, with a row of data, etc.
      >
      then I thought it would be nice to do a select, and perhaps an update
      (the title of the image) on the same page.
      >
      I am wondering if I am having the wrong idea. I have a form, with two
      submit buttons, one selects an image, and some info. the other will
      update the image title for the given image (id, and p).
      I am seeing that I have a mistake here, since it seems the update
      query will run as well as when the select query is run (select button
      clicked). this overwrites my image titles in the db.
      >
      I have the wrong idea, but have not seen how to do this "right". I
      could use another php page for update, but I am guessing this can be
      done from the same page.
      >
      Below is my poor code - i am not an expert programmer!!! any help,
      suggestions will be helpful.
      >
      Too long code, didn't read it all, but here's a tip for you: Have two submit
      buttons, but name them differently. On server-side you test which button was
      clicked based on which submit was sent. (Of several submit buttons, only the
      one that was clicked is sent in the form)
      <input type="submit" name"select" value="select-a-mundo!" />
      <input type="submit" name"update" value="update-a-mundo!" />
      >
      on server-side this code will tell you which was clicked:
      <?php
      if(isset($_POST['select'])){
      // Now you run the select query} else if(isset($_POST['update'])){
      >
      // Now run the update query}
      >
      ?>
      >
      --
      "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
      s...@outolempi. net | rot13(x...@bhgb yrzcv.arg)
      Thanks for the tip - I will try your suggestion, thanks again
      ewholz

      Comment

      • eholz1

        #4
        Re: have to &quot;actions&q uot; or run two types of queries (select,and update) on the same form?

        On Feb 12, 10:45 pm, "Kimmo Laine" <s...@outolempi .netwrote:
        "eholz1" <ewh...@gmail.c omwrote in message
        >
        news:1171321767 .611070.208900@ p10g2000cwp.goo glegroups.com.. .
        >
        >
        >
        Hello PHP programmers.
        >
        I had a brilliant idea on one of my pages that selects some data from
        my mysql database.
        I first set the page up to display some info and an image, just one
        item, with a row of data, etc.
        >
        then I thought it would be nice to do a select, and perhaps an update
        (the title of the image) on the same page.
        >
        I am wondering if I am having the wrong idea. I have a form, with two
        submit buttons, one selects an image, and some info. the other will
        update the image title for the given image (id, and p).
        I am seeing that I have a mistake here, since it seems the update
        query will run as well as when the select query is run (select button
        clicked). this overwrites my image titles in the db.
        >
        I have the wrong idea, but have not seen how to do this "right". I
        could use another php page for update, but I am guessing this can be
        done from the same page.
        >
        Below is my poor code - i am not an expert programmer!!! any help,
        suggestions will be helpful.
        >
        Too long code, didn't read it all, but here's a tip for you: Have two submit
        buttons, but name them differently. On server-side you test which button was
        clicked based on which submit was sent. (Of several submit buttons, only the
        one that was clicked is sent in the form)
        <input type="submit" name"select" value="select-a-mundo!" />
        <input type="submit" name"update" value="update-a-mundo!" />
        >
        on server-side this code will tell you which was clicked:
        <?php
        if(isset($_POST['select'])){
        // Now you run the select query} else if(isset($_POST['update'])){
        >
        // Now run the update query}
        >
        ?>
        >
        --
        "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
        s...@outolempi. net | rot13(x...@bhgb yrzcv.arg)
        Hello Ohjelmoija,

        thanks, this worked fine.

        ewholz

        Comment

        Working...