SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Update Issue

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update Issue

    I am trying to UPDATE a column in my database table, I can pull the info from the database but updating is causing me grief, the commented out code is what is meant to make the update work but when I run this I get a parse error on the last line whcich is the closing ?> tag...

    PHP Code:
    <?php

    /* connect to the mysql database and use different queries for the count of members */

    include 'library/config.php';
    include 
    'library/opendb.php';

    //navigation
    include("nav.php");

    //if (isset($_REQUEST['Submit2'])) {

    $status $_REQUEST['status'];

    //$email = $_REQUEST['txtboxEmailBody'];
    //mysql_query("UPDATE `tblemail` SET `email_body_TXT`='$email' WHERE `email_Identifier_TXT`='$status'");

    //get Email info
    if ($status == "A") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'A'");

    }

    elseif (
    $status == "R") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'R'");

    }

    elseif (
    $status == "H") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'H'");

    }

    elseif (
    $status == "P") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'P'");

    }

    echo 
    '<table border="1" cellpadding="3" cellspacing="1"> 
    <tr valign="top"> 
        <td>Email</td> 
    </tr> 
    <tr valign="top"> 
        <td>Details</td> 
    </tr> 
    <tr valign="top"> 
        <td>Is Active</td> 
    </tr> 
    <tr valign="top"> 
        <td></td> 
    </tr>'
    ;

    //create the layout 
    ?> 

    <tr valign="top"> 
    <td> 
    <form name="editForm" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">

    <!--enter options for status menu-->
    <select name="status">

    <option value="A">Approved</option>
    <option value="P">Pending</option>
    <option value="H">On Hold</option>
    <option value="R">Rejected</option>

    </select>

    <textarea name="txtboxEmailBody" cols="45" rows="7"><?php print(stripslashes(mysql_result($info,0,"email_body_TXT"))) ?></textarea>


    <!-- <input type="hidden" name="id" value="<?=$_REQUEST['id'];?>"> -->
    <input type="submit" name="Submit2" value="Update">        

    </form>

    </td> 
    </tr> 

    <tr valign="top"> 
    <td>
        
    </td> 
    </tr>

    <?php 

    echo '</table>'

    include 
    'library/closedb.php'

    ?>

  2. #2
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be the problem:
    <?=$_REQUEST['id'];?>

    That equals sign.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Location
    Swindon, UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shouldnt be, because the = is basically an alias for echo...

    are you saying it doesnt work with the code commented or uncommented...

    if its when it is uncommented, you have an unclosed {
    Code:
    if (isset($_REQUEST['Submit2'])) {
    which will provide the parse error - just include the } at the end of the script!

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhhh thanks! That was it...

    I didn't have a closing tag, now it runs without the parse error but the data from the database no longer loads into the texfield... This is the full script with the added }

    PHP Code:
    <?php

    /* connect to the mysql database and use different queries for the count of members */

    include 'library/config.php';
    include 
    'library/opendb.php';

    //navigation
    include("nav.php");

    if (isset(
    $_REQUEST['Submit2'])) {

    $status $_REQUEST['status'];

    $email $_REQUEST['txtboxEmailBody'];
    mysql_query("UPDATE `tblemail` SET `email_body_TXT`='$email' WHERE `email_Identifier_TXT`='$status'");

    //get Email info
    if ($status == "A") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'A'");

    }

    elseif (
    $status == "R") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'R'");

    }

    elseif (
    $status == "H") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'H'");

    }

    elseif (
    $status == "P") {
    $info mysql_query("SELECT * FROM `tblemail` WHERE `email_Identifier_TXT` = 'P'");

    }

    }

    echo 
    '<table border="1" cellpadding="3" cellspacing="1"> 
    <tr valign="top"> 
        <td>Email</td> 
    </tr> 
    <tr valign="top"> 
        <td>Details</td> 
    </tr> 
    <tr valign="top"> 
        <td>Is Active</td> 
    </tr> 
    <tr valign="top"> 
        <td></td> 
    </tr>'
    ;

    //create the layout 
    ?> 

    <tr valign="top"> 
    <td> 
    <form name="editForm" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">

    <!--enter options for status menu-->
    <select name="status">

    <option value="A">Approved</option>
    <option value="P">Pending</option>
    <option value="H">On Hold</option>
    <option value="R">Rejected</option>

    </select>

    <textarea name="txtboxEmailBody" cols="45" rows="7"><?php print(stripslashes(mysql_result($info,0,"email_body_TXT"))) ?></textarea>


    <!-- <input type="hidden" name="id" value="<?=$_REQUEST['id'];?>"> -->
    <input type="submit" name="Submit2" value="Update">        

    </form>

    </td> 
    </tr> 

    <tr valign="top"> 
    <td>
        
    </td> 
    </tr>

    <?php 

    echo '</table>'

    include 
    'library/closedb.php'

    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Location
    Swindon, UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I can see, it will only show the value in the textbox once you submit the form!! Perhaps that is what you wanted - but your SELECT queries are inside your if statement. DOes it work after you submit the form?

  6. #6
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jazzer01 View Post
    From what I can see, it will only show the value in the textbox once you submit the form!! Perhaps that is what you wanted - but your SELECT queries are inside your if statement. DOes it work after you submit the form?
    Actually I would love to be able to do it so that when I select the menu item it changes automatically any ideas on how to do that?

  7. #7
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do some error checking with mysql_error(). After each query, put the following:

    PHP Code:
    if(!$info)
    {
         die(
    "mysql error: " mysql_error());

    I'm guessing you have some sort of MYSQL error in which case it should show up.

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Location
    Swindon, UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry I abandoned this thread - well, I didn't I just wasn't online for a few days and it got burried - I'm not entirly sure what u mean - trying to refresh my memory. Whaqt do you want to change automatically? Sorry if I'm being dense!


Bookmarks

Posting Permissions

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