Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default PHP Update basics

    Hello,
    I am using the below code to update a database field:

    <?php
    require_once('Connections/ConModelz.php');
    mysql_select_db($database_ConModelz, $ConModelz);

    $str="UPDATE pictures SET Showcase = 0";
    mysql_query($str) or die("Query failed:<br>".mysql_error());


    if ($_SERVER['REQUEST_METHOD']=="POST"){
    if (is_array($_POST['selected'])){
    $str=$_POST['selected']
    $str="UPDATE pictures SET Showcase = 1 WHERE Id IN ($str)";
    mysql_query($str) or die("Query failed:<br>".mysql_error());
    header ("Location: pics.php");
    } else {
    echo "Please Hit the back button and check atleast one Radio button. ";
    }
    }
    ?>
    I need to update a field based on ID and the username.
    I modified the line:

    $str="UPDATE pictures SET Showcase = 1 WHERE Id IN ($str)";
    to
    $str="UPDATE pictures SET Showcase = 1 WHERE Username = $name, Id = ($str)";

    and also added the code :
    session_start();
    if(isset($HTTP_SESSION_VARS['MM_Username'])){
    $name=$HTTP_SESSION_VARS['MM_Username'];
    }

    on the top of the page, which is off course no working.
    Can anybody please tell me what i am doing wrong and what should i take care
    of while coding such scripts?
    I thank you for any advices.



    joy Guest

  2. Similar Questions and Discussions

    1. need basics of FMS
      Hi guys, Im new to FMS.so,Can anyone tell me how to install the Flash media server 2 and how to run a sample application in it.and how to build a...
    2. SSL Basics
      Hi there, I'm building a new site and have just dived into SSL - I'm totally lost. My provider has given me two directories to work with. ...
    3. 3D basics
      hello i was wondering if someone could tell me about 3D in director 8.5, which i have only recently got. I know you can make 3D text and i saw a...
    4. [PHP] some html basics please
      Chris Shiflett wrote: I knew that ./ was the current directory on a *nix system, but a browser will respect that also?
    5. Just the basics please...
      I'm new to Elements and really not getting much of use in the help or tutorials. The state of A's technical writing is low. I am VERY familiar with...
  3. #2

    Default Re: PHP Update basics

    Just a small correction:
    the line:
    $str=$_POST['selected']
    is actually:
    $str=join(",",$_POST['selected']);


    "joy" <joy@lycos.com> schrieb im Newsbeitrag
    news:d2olse$68f$1@forums.macromedia.com...
    > Hello,
    > I am using the below code to update a database field:
    >
    > <?php
    > require_once('Connections/ConModelz.php');
    > mysql_select_db($database_ConModelz, $ConModelz);
    >
    > $str="UPDATE pictures SET Showcase = 0";
    > mysql_query($str) or die("Query failed:<br>".mysql_error());
    >
    >
    > if ($_SERVER['REQUEST_METHOD']=="POST"){
    > if (is_array($_POST['selected'])){
    > $str=$_POST['selected']
    > $str="UPDATE pictures SET Showcase = 1 WHERE Id IN ($str)";
    > mysql_query($str) or die("Query failed:<br>".mysql_error());
    > header ("Location: pics.php");
    > } else {
    > echo "Please Hit the back button and check atleast one Radio button. ";
    > }
    > }
    > ?>
    > I need to update a field based on ID and the username.
    > I modified the line:
    >
    > $str="UPDATE pictures SET Showcase = 1 WHERE Id IN ($str)";
    > to
    > $str="UPDATE pictures SET Showcase = 1 WHERE Username = $name, Id =
    > ($str)";
    >
    > and also added the code :
    > session_start();
    > if(isset($HTTP_SESSION_VARS['MM_Username'])){
    > $name=$HTTP_SESSION_VARS['MM_Username'];
    > }
    >
    > on the top of the page, which is off course no working.
    > Can anybody please tell me what i am doing wrong and what should i take
    > care of while coding such scripts?
    > I thank you for any advices.
    >
    >
    >

    joy Guest

  4. #3

    Default Re: PHP Update basics

    Your WHERE clause is wrong:

    $str="UPDATE pictures SET Showcase = 1 WHERE Username = $name, Id = ($str)";

    Should be:

    $str="UPDATE pictures SET Showcase = 1 WHERE Username = '$name' AND Id =
    '$str' ";


    --
    Gareth - TMM Dreamweaver
    [url]http://www.dreamweavermxsupport.com/[/url]
    [url]http://www.garethdp.com/[/url]

    PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
    [url]http://www.phploginsuite.co.uk/[/url]

    Co-Author: Dreamweaver MX: Instant Troubleshooter - Apress
    Co-Author: Practical Intranet Development - Apress
    Co-Author: Dreamweaver MX: Advanced PHP Web Development - Apress
    Co-Author: Dreamweaver MX: PHP Web Development - Wrox


    gareth Guest

  5. #4

    Default Re: PHP Update basics

    .oO(joy)
    > header ("Location: pics.php");
    header("Location: http://$_SERVER[HTTP_HOST]/pics.php");
    >I need to update a field based on ID and the username.
    >I modified the line:
    >
    > $str="UPDATE pictures SET Showcase = 1 WHERE Id IN ($str)";
    >to
    >$str="UPDATE pictures SET Showcase = 1 WHERE Username = $name, Id = ($str)";
    $str = "
    UPDATE pictures
    SET Showcase = 1
    WHERE Username = '$name'
    AND Id = $str";
    >and also added the code :
    >session_start();
    >if(isset($HTTP_SESSION_VARS['MM_Username'])){
    > $name=$HTTP_SESSION_VARS['MM_Username'];
    >}
    Use the $_SESSION array instead of the old $HTTP_*.
    >on the top of the page, which is off course no working.
    You should always post the error messages you received from PHP or
    MySQL, just saying "doesn't work" isn't of much help.

    Micha
    Michael Fesser Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139