+ Reply to Thread
Results 1 to 5 of 5

Thread: action="update.php" make new page :(

  1. #1
    martynball is offline x10Hosting Member martynball is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Stoke-on-Trent, UK
    Posts
    60

    action="update.php" make new page :(

    Question 1:
    Sorry about the vast amount of threads I am making, but don't want to confuse people by posting new questions in the same threads.

    Here, I have a form, and action script. It updates my database with the values in the form. The only problem with it is that when I click submit, the script is loaded up and has the echo written on the screen.

    I do not want this, I want it to write something like "Updated Successfully" under the submit button, or at least load a different page.

    PHP Code:
    <form name="form1" method="post" action="scripts/update.php" onsubmit="return validate_form(this)">
            <
    class="g2">Name:</p>
            <
    input type="text" class="contact-feild" name="name" size="20" />
            <
    br />
            <
    class="g2">Email:</p>
            <
    input type="text" class="contact-feild" name="email" size="20" />
            <
    br />
            <
    class="g2">Message:</p>
            <
    textarea name="message" class="contact-feild" style="width:300px; height:150px; overflow:scroll; overflow-x:hidden;">
      </
    textarea>
            <
    br />
            <
    input type="submit" value="Submit" class="button" name="submit"/>
          </
    form
    update.php
    PHP Code:
    <?php
    // Connect to database
    $con mysql_connect("localhost","martynba_martynb","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
      
    // Select table
    mysql_select_db("martynba_comments"$con);

    // Make varibles
    date_default_timezone_set('GMT');
    $name mysql_real_escape_string($_POST['name']);
    $email mysql_real_escape_string($_POST['email']);
    $message mysql_real_escape_string($_POST['message']);
    $date date("F j, Y, g:i a");

    // Insert data
    $query="INSERT INTO commentTable ( NAME, EMAIL, MESSAGE, DATE)
    VALUES ('"
    .$name."','".$email."','".$message."','".$date."')";
    $result mysql_query ($query);

        echo 
    "<p class=\"g2\">Thanks for your comment $name!</p>";

    ?>
    -------------------------------------------------

    Question 2:
    How can I make this php code display the results in a certain order, e.g. smallest "id" number first.
    PHP Code:
      <?php
    // Connect to the database server
    mysql_connect('localhost''martynba_martynb''password') or die('Error connecting to the database: ' mysql_error());
    // Select the database
    mysql_select_db('martynba_comments') or die('Error selecting database: ' mysql_error());

    //Get data...
    $result mysql_query("select * from commentTable");
    while (
    $row mysql_fetch_array($result))

    $id=$row["ID"];
    $name=$row["NAME"];
    $message=$row["MESSAGE"];
    $email=$row["EMAIL"];
    $today$row["DATE"];

    //Display results
        
    echo "<table class=\"comment-table\">";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-name\">Posted by: $name<div class=\"comments-date\">$today</div></td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-message\">$message";
        echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-id\">ID: $id";
        echo 
    "<form method=\"post\" action=\"scripts/delete.php\" class=\"del-form\"><input name=\"id\" id=\"id\" type=\"hidden\" value=\"$id\"><input type=\"image\" src=\"../images/del.png\"></form></td>"
        echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "<br />";
    }
    ?>
    Last edited by martynball; 11-26-2009 at 06:36 PM.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: action="update.php" make new page :(

    Quote Originally Posted by martynball View Post
    Sorry about the vast amount of threads I am making, but don't want to confuse people by posting new questions in the same threads.
    You're doing the right thing. New issues deserve new threads for exactly the reason you say: it prevents confusion. You can always include links to other relevant threads.

    You posted your DB username and password again; better edit your post.

    Quote Originally Posted by martynball View Post
    I do not want this, I want it to write something like "Updated Successfully" under the submit button, or at least load a different page.

    HTML Code:
    <form name="form1" method="post" action="scripts/update.php" onsubmit="return validate_form(this)">
            <p class="g2">Name:</p>
            <input type="text" class="contact-feild" name="name" size="20" />
            <br />
    With the <p> elements, the <br/> are unnecessary. <br/> have no semantic value; avoid them if possible (and it usually is possible).

    Quote Originally Posted by martynball View Post
    I do not want this, I want it to write something like "Updated Successfully" under the submit button, or at least load a different page.
    ...
    update.php
    PHP Code:
    // Insert data
    $query="INSERT INTO commentTable ( NAME, EMAIL, MESSAGE, DATE)
    VALUES ('"
    .$name."','".$email."','".$message."','".$date."')";
    $result mysql_query ($query); 
    Test the result; make sure it's not FALSE and at least one row was affected. If so, query was successful. If not, query failed. You can then either print a message or use header to redirect to another page. Note that header only works if NOTHING has yet been printed, not even spaces or the UTF-8 byte order mark, since no HTTP headers can be sent once you start sending the content.

    In some other file:
    PHP Code:
    // For illustration only. Not production-ready code.
    function uriScheme() {
        if (
    $_SERVER['SERVER_PORT'] == 443) {
            return 
    'https://';
        } else {
            return 
    "http://";
        }
    }

    function 
    uriPort() {
        switch (
    $_SERVER['SERVER_PORT']) {
        case 
    443:
        case 
    80:
            return 
    '';
        default:
            return 
    ':' $_SERVER['SERVER_PORT'];
        }
    }

    function 
    scriptBase() {
        static 
    $base null;
        if (
    is_null($base)) {
            
    $base uriScheme() . $_SERVER['HTTP_HOST'] . uriPort() . dirname($_SERVER['REQUEST_URI']);
        }
        return 
    $base;

    In "update.php":
    PHP Code:
    if ($result !== FALSE && mysql_num_rows($result) > 0) {
        
    header("Location: " scriptBase() . '/result.php?success' );
        
    // OR
        
    echo "Update successful.";
    } else {
        
    header("Location: " scriptBase() . '/result.php?fail&errno=' mysql_errno() );
        
    // OR 
        
    echo "Update failed.";
        
    // Now give a more specific and helpful message.
        
    switch (mysql_errno()) {
            ...
        }

    Quote Originally Posted by martynball View Post
    Question 2:
    How can I make this php code display the results in a certain order, e.g. smallest "id" number first.
    PHP Code:
      <?php
    //Get data...
    $result mysql_query("select * from commentTable");
    Use the "ORDER BY" clause:
    Code:
    SELECT * FROM commentTable ORDER BY id; -- smallest ID to largest
    SELECT * FROM commentTable ORDER BY name DESC; -- largest to smallest
    SELECT * FROM commentTable ORDER BY date, name; -- sort by date first, then name
    You should really find some good books or tutorials to read right now; they'll answer the questions you've been asking and more.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    martynball is offline x10Hosting Member martynball is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Stoke-on-Trent, UK
    Posts
    60

    Re: action="update.php" make new page :(

    One more quick question, when I enter txt longer than the table, it stretches the table... i want it go on a new line, like it was doing. :S

    http://martynleeball.x10hosting.com/contactus.php

    Click "Show Comments" at bottom of page.

    PHP Code:
    <?php
    // Connect to the database server
    mysql_connect('localhost''martynba_martynb''password') or die('Error connecting to the database: ' mysql_error());
    // Select the database
    mysql_select_db('martynba_comments') or die('Error selecting database: ' mysql_error());

    //Get data...
    $result mysql_query("select * from commentTable ORDER BY date;");
    while (
    $row mysql_fetch_array($result))

    $id=$row["ID"];
    $name=$row["NAME"];
    $message=$row["MESSAGE"];
    $email=$row["EMAIL"];
    $today$row["DATE"];

    //Display results
        
    echo "<table class=\"comment-table\">";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-name\"><div class=\"name-c\">Posted by: $name</div>
        <div class=\"comments-date\">
    $today</div></td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-message\">$message</div>";
        echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
        echo 
    "<td class=\"comment-id\"><div class=\"name-c\">ID: $id</div>";
        echo 
    "</td>"
        echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "<br />";
    }
    ?>
    Last edited by martynball; 11-26-2009 at 07:41 PM.

  4. #4
    spadija's Avatar
    spadija is offline x10Hosting Member spadija is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    48

    Re: action="update.php" make new page :(

    The css property "word-wrap: break-word" is supposed to force a line break. I say supposed to because it isn't implemented in all browsers yet. Check out this page for more information: http://www.css3.com/css-word-wrap/ The comments also contain some browser-specific css to get it working in Firefox and IE.

    You can also use the "max-width" property to keep the boxes from stretching, but then the text will overflow. You can use the "overflow" property to hide overflow or add scroll bars when the text is too long.

    There really isn't an elegant solution to this yet. One way to handle it is to use PHP insert a soft hyphen into long words, but there's no way to get the rendered width of text from PHP, so you run into problems with different fonts and text sizes on different browsers.

    Hope that answers your question.

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: action="update.php" make new page :(

    Another issue with the page you link to (http://martynleeball.x10hosting.com/contactus.php) is that the bottom bar covers up "Show comments" in FF 3.5 and Safari 4.0 (and probably others). The simplest solution is to put a bottom padding of 1em on .main_text. With this option, the scrollbar will extend down next to the bottom bar. Another option is to use the old IE 6 fixed positioning emulation, which places everything but the bottom bar in an absolutely position element. With this option, the scrollbar will stop just short of the bottom bar. Something like:
    HTML Code:
    <!DOCTYPE ...>
    <html>
      <head>...
        <style type="text/css">
            body { overflow: hidden; }
            #Body {
                position: absolute;
                top: 0px;
                left: 0px;
                bottom: 1em;
                right: 0px;
                overflow: auto;
            }
            .bottom-bar {
                position: absolute;
                bottom: 0px;
                left: 0px;
                width: 100%;
                height: 1em;
                z-index: 1;
            }
        </style>
      </head>
      <body>
        <div id="Body">
            ....
        </div>
        <div class="bottom-bar"></div>
      </body>
    </html>
    Unless you really don't like the scrollbar next to the bottom bar, I'd go with padding over restructuring the HTML.

    Forgot to mention earlier: the class "contact-feild" in the contact form is misspelled; it should be "contact-field".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. How to make a page like youtube?
    By qwertyuiop12 in forum Tutorials
    Replies: 21
    Last Post: 08-03-2009, 05:55 AM
  2. New x10 Hosting Account Splash Page
    By brainiacinside in forum Free Hosting
    Replies: 2
    Last Post: 04-27-2009, 01:58 PM
  3. make ads load after the page is done loading
    By igames in forum Programming Help
    Replies: 13
    Last Post: 01-29-2009, 04:21 PM
  4. Replies: 4
    Last Post: 04-10-2008, 09:33 PM
  5. How do i make the index page my homepage
    By jpz17 in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 09-19-2007, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers