SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem updating mysql from form

    Hello all,
    I'm trying to upadte a table via a form where the text boxes fill with the previous data. My first problem is that the boxes aren't filling and my second when I ignore that is that i get the error : Cannot modify header information - headers already sent,

    here an example of the form
    PHP Code:
    <?
                $link 
    mysql_connect("$host""$user");
                if (! 
    $link)
                die(
    "Couldn't connect to MySQL");
                
    mysql_select_db("$db")
                or die(
    "Couldn't open $db: ".mysql_error());
                
    $result=mysql_query("SELECT * FROM home_right");
                
    ?>
                
                <form action=process_home_right.php method=post name=home_right enctype=multipart/form-data>
                <table align=center>
                    <tr>
                        <td colspan=2><span class=sub_title>First Image</span></td>
                    </tr>
                    <tr>
                        <td align=right><span class=alt_text>Heading</span></td>
                        <td><input name=heading_1 type=text size=30 value="<? echo "$heading_1?>" /></td>
                    </tr>
                    <tr>
                        <td align=right><span class=alt_text>Description</span></td>
                        <td><textarea name=description_1 cols=30 rows=5><? echo "$description_1?></textarea></td>
                    </tr>
                    <tr>
                        <td align=right><span class=alt_text>Before Image</span></td>
                        <td><input name=before_1 type=file value="<? echo "$before_1?>" /></td>
                    </tr>
                    <tr>
                        <td align=right><span class=alt_text>After Image</span></td>
                        <td><input name=after_1 type=file value="<? echo "$after_1?>" /></td>
                    </tr>
    and heres the query which is causing the second problem,the line which is said to be the prob is the last

    PHP Code:
    <? require("../db/db_info.php"); 
    $link mysql_connect("$host""$user");
    if (! 
    $link)
    die(
    "Couldn't connect to MySQL");
    mysql_select_db("$db")
    or die(
    "Couldn't open $db: ".mysql_error());
    mysql_query
        
    ("
            UPDATE home_right 
            SET 
                heading_1 = '
    $heading_1',
                heading_2 = '
    $heading_2',
                heading_3 = '
    $heading_3',
                description_1 = '
    $description_1',
                description_2 = '
    $description_2',
                description_3 = '
    $description_3',
                before_1 = '
    $before_1',
                before_2 = '
    $before_2',
                before_3 = '
    $before_3',
                after_1 = '
    $after_1',
                after_2 = '
    $after_2',
                after_3 = '
    $after_3'
            WHERE
                home_right_id = '1'
        "
    );
     
    mysql_close ($link);
     
    header ("Location:index.php");?>
    I'm completly boggled with this,

    thanks for your help

    ad

    oh yeah before i forget i'm also having the same form prob with fckeditor but im thinking once one is solved so will the other

    PHP Code:
    <?php
    $oFCKeditor 
    = new FCKeditor('home_list') ;
    $oFCKeditor->BasePath 'FCKeditor/';
    $oFCKeditor->Value '$home_list';
    $oFCKeditor->Create() ;
    $oFCKeditor->Width  '600';
    $oFCKeditor->Height  '400';
    ?>
    Last edited by dunskii; Jul 27, 2005 at 21:59. Reason: just adding something

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2005
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all,
    the values are not being displayed because you are not fetching them.
    So:
    PHP Code:
    $result=mysql_query("SELECT * FROM home_right");
    $row mysql_fetch_assoc($result); 
    In order to assign them to the form use
    PHP Code:
    <?= $row[heading_1]; ?>
    The second problem occurs because there must be something in your code echoing data to the browser, before the parser reaches the header() function.
    Make sure you don't have any empty lines after the header() call

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahaaa, thanks for that, makes total sense. moving from cf to php is turning out to be more complex than i was expecting

    enjoy your day ad

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mmm, well i'm now filling the forms thanks for that but i'm still having the header problem. I've removed every stray space etc, but i'm still have the same problem. The only thing I can think of that could be printed is db errors which means it wouldn't get to the header() call

    PHP Code:
    <?
    require("../db/db_info.php");
    $link mysql_connect("$host""$user");
    if (! 
    $link)
        die(
    "Couldn't connect to MySQL");
        
    mysql_select_db("$db")
    or die(
    "Couldn't open $db: ".mysql_error());
        
    mysql_query
            
    ("
                UPDATE home_right
                SET
                    heading_1 = '
    $heading_1',
                    heading_2 = '
    $heading_2',
                    heading_3 = '
    $heading_3',
                    description_1 = '
    $description_1',
                    description_2 = '
    $description_2',
                    description_3 = '
    $description_3',
                    before_1 = '
    $before_1',
                    before_2 = '
    $before_2',
                    before_3 = '
    $before_3',
                    after_1 = '
    $after_1',
                    after_2 = '
    $after_2',
                    after_3 = '
    $after_3'
                WHERE
                    home_right_id = '1'
            "
    );
    mysql_close ($link);
    header("Location: index.php");
    ?>
    thanks again ad

  5. #5
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dunskii
    The only thing I can think of that could be printed is db errors which means it wouldn't get to the header() call
    bzzzzzt! wrong!

    the way you have your code written, your mysql_* command will send their errors to the client.

    but i don't think that your problem. you need to check all of your included files to make sure none of them output anything.


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
  •