Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

Thread: Little Problem

  1. #1
    Senior Member assassingod's Avatar
    Join Date
    Nov 2002
    Posts
    112
    Member #
    307
    Im having trouble updating some input fields with my script:

    PHP Code:
                    <?php

                        $connect 
    = @mysql_connect("localhost","root","");
                        
    $connect = @mysql_select_db("movie-shot");
                        
    $sqlcontent "select sitename,siteversion,sitedescription,sitecreator from admin";
                        
    $connect = @mysql_query($sqlcontent);
                        while(
    $site mysql_fetch_array($connect))

                        
    $form ="
                        <form action=\"
    $PHP_SELF\" method=\"post\">
                        <font size=\"2\" face=\"trebuchet ms\">
                        <b>Site Name:</b> <input type=\"text\" name=\"sitename\" size=\"30\" value=\"
    $site[sitename]\" /><br />
                        <b>Site Version:</b> <input type=\"text\" name=\"siteversion\" size\"30\" value=\"
    $site[siteversion]\" /><br />
                        <b>Site Description:</b> <br/><textarea name=\"sitedescription\" rows=\"5\" cols=\"30\">
    $site[sitedescription]</textarea><br />
                        <input type=\"submit\" name=\"submit\" value=\"Save!\">
                        </form>
                        "
    ;
                        if(
    $submit)
                        {
                        
    $connect2 = @mysql_connect("localhost","root","");
                        
    $selectdb = @mysql_select_db("movie-shot");
                        
    $sqlcontent2 "update admin set sitename = '$sitename', siteversion = '$siteversion', sitedescription = '$sitedescription'";
                        
    $selectdb = @mysql_query($sqlcontent2,$connect2)
                                    or die(
    "Query unsuccessful");
                        }

                        echo 
    $form;
                    
    ?>
    I realize its not the best way, but for now I want to keep the code within 1 file.

    All it does it refresh the page, it doesnt update the fields
    Can anyone shed some light on my problem?
    assassingod - vB.org Moderator :ichatsmile:

  2.  

  3. #2
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Should you not be referencing the variables using $_POST['sitename'] rather than $sitename ?

    The latter requires the server to be configured specially

    Sean

  4. #3
    Senior Member assassingod's Avatar
    Join Date
    Nov 2002
    Posts
    112
    Member #
    307
    Ah, I knew I missed something.

    But still it doesn't work, I dont believe it is running the query
    assassingod - vB.org Moderator :ichatsmile:

  5. #4
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Have you also fixed the submit variable ?

    It's also $_POST['submit']

    Sean

  6. #5
    Senior Member assassingod's Avatar
    Join Date
    Nov 2002
    Posts
    112
    Member #
    307
    Ah, missed that. But still, not doing anything
    assassingod - vB.org Moderator :ichatsmile:

  7. #6
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Hold on, I shall duplicate your page...

    Sean

  8. #7
    Senior Member assassingod's Avatar
    Join Date
    Nov 2002
    Posts
    112
    Member #
    307
    Ah, i've got it now. Thanks!
    assassingod - vB.org Moderator :ichatsmile:

  9. #8
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    well your update query will mess up your whole table. You should specify which row should be updated using "WHERE" clause.

    Update admin Set ........ WHERE sitename='old name';

    as for the code itself, try this and see if it works for you:
    PHP Code:
    <?php

    $connect 
    mysql_connect("localhost","root","");
    $connect mysql_select_db("movie-shot");

    if(
    $_POST['submit'])
    {
        
    // don't need to reconnect, just did that above.
        
    $currentname $_POST['currentname'];
        
    $sitename $_POST['sitename'];
        
    $siteversion $_POST['siteversion'];
        
    $sitedescription $_POST['sitedescription'];
        
    $sql2 "update admin set sitename = '$sitename', siteversion = '$siteversion', 
            sitedescription = '
    $sitedescription' WHERE sitename LIKE 'currentname';";
        
    $selectdb mysql_query($sql2,$connect) or die("Query unsuccessful.<br><br>".mysql_error());
    }
    else
    {
        
    $sqlcontent "select sitename,siteversion,sitedescription,sitecreator from admin";
        
    $connect mysql_query($sqlcontent);
        while(
    $site mysql_fetch_array($connect))

        
    $form ="
        <form action=\"
    $PHP_SELF\" method=\"post\">
        <input type=\"hidden\" name=\"currentname\" value=\"
    $site[sitename]\";
        <font size=\"2\" face=\"trebuchet ms\">
        <b>Site Name:</b> 
        <input type=\"text\" name=\"sitename\" size=\"30\" value=\"
    $site[sitename]\" /><br />
        <b>Site Version:</b> 
        <input type=\"text\" name=\"siteversion\" size\"30\" value=\"
    $site[siteversion]\" /><br />
        <b>Site Description:</b> <br/>
        <textarea name=\"sitedescription\" rows=\"5\" cols=\"30\">
    $site[sitedescription]</textarea><br />
        <input type=\"submit\" name=\"submit\" value=\"Save!\">
        </form>"
    ;
        
        echo 
    $form;
    }
    ?>
    There and Back Again :Ogre:

  10. #9
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    I need caffeine.
    There and Back Again :Ogre:

  11. #10
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    No, I disagree.... his update is fine, based on the fact that it is a single row table.

    His problem was that his code is in the wrong order. The page is constantly one submit behind the database...

    Here's a version that works...

    <html>
    <head></head>
    <body>
    <?php
    if($_POST['submit'])
    {
    $connect2 = @mysql_connect("localhost","phpweb_u1","p1");
    $selectdb = @mysql_select_db("phpweb_t1");
    $sqlcontent2 = "update admin set sitename = '" . $_POST['sitename'] . "', siteversion = '" . $_POST['siteversion'] . "', sitedescription = '" . $_POST['sitedescription'] . "'";
    $selectdb = @mysql_query($sqlcontent2,$connect2)
    or die("Query unsuccessful");
    }

    $connect = @mysql_connect("localhost","phpweb_u1","p1");
    $connect = @mysql_select_db("phpweb_t1");
    $sqlcontent = "select sitename,siteversion,sitedescription,sitecreator from admin";
    $connect = @mysql_query($sqlcontent);

    while($site = mysql_fetch_array($connect))
    $form ="
    <form action=\"$PHP_SELF\" method=\"post\">
    <font size=\"2\" face=\"trebuchet ms\">
    <b>Site Name:</b> <input type=\"text\" name=\"sitename\" size=\"30\" value=\"$site[sitename]\" /><br />
    <b>Site Version:</b> <input type=\"text\" name=\"siteversion\" size\"30\" value=\"$site[siteversion]\" /><br />
    <b>Site Description:</b> <br/><textarea name=\"sitedescription\" rows=\"5\" cols=\"30\">$site[sitedescription]</textarea><br />
    <input type=\"submit\" name=\"submit\" value=\"Save!\">
    </form>
    ";

    echo $form;
    ?>
    </body>
    </html>
    hth

    Sean


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:32 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com