Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Question + REP - PHP Help

    I have the following code, but the info submitted doesn't submit to the database.

    Any help?

    PHP Code:
        <?php
        
    // The database
        
    include 'config.php';
        
    // The variables
    $name = ($_POST["name"]);
    $grade = ($_POST["grade"]);
    $comment = ($_POST["comment"]);
    $ip $_SERVER[REMOTE_ADDR];

    //Those horrible IF's - Form data
    if ($_GET["action"] == "submit")
    {
    if (
    $name == "")
        {
            echo 
    "Whoops! You didn't enter your name.";
            exit;
        }
        
        
    if (
    $comment== "")
        {
            echo 
    "Whoops! You didn't enter a comment.";
            exit;
        }
            
    $name addslashes(htmlspecialchars($name));  
            
    $grade addslashes(htmlspecialchars($grade));
            
    $comment addslashes(htmlspecialchars($comment));
             
    $addpetition mysql_query("INSERT INTO `petition` (`name`, `grade`, `comment`, `ip`) VALUES ('$name','$grade','$comment', '$ip')"); 
            
        
    // The form details are fine, display text & details
        
    echo "XX: <br />
    Name: 
    $name<br />
    Grade: 
    $grade<br />
    Your comment: 
    $comment<br />
    <br />
    To view all the signatures, click <a href=\"petition.php?view=entries\">here.</a> To go back to the home page, click <a href=\"index.php\">here.</a>"
    ;
    exit;
    }

    else
    // Display the form
    {
        echo 
    "
    <div align\"center\">XX</div><br />
    <br />
    <form action=\"?action=submit\" method=\"post\">
        <div id=\"title\">Name:</div>
        <input type=\"text\" name=\"name\"><br /><br />
        <div id=\"title\">XX:</div>
        <select name=\"XX\">
        <option id=\"5\">XX</option>
        <option id=\"5\">XX</option>
        <option id=\"6\">XX</option>
        <option id=\"7\">XX</option>
        <option id=\"8\">XX</option>
        </select><br /><br />
        <div id=\"title\">Comment:</div>
        <style=\"width=\"169\"; height=\"116\"><textarea rows=\"7\" input type=\"text\" name=\"comment\" cols=\"28\"></textarea><br />
        <input type=\"submit\" name=\"submit\" value=\"Sign the petition!\">
        </form>"
    ;
        exit;
        }
        
    ?>


    Selling DJ/Habbo layout, more info here.


  2. #2
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
      <?php
    // The database
    include 'config.php';

    // The variables
    $name = ($_POST["name"]);
    $grade = ($_POST["grade"]);
    $comment = ($_POST["comment"]);
    $ip $_SERVER[REMOTE_ADDR];

    //Those horrible IF's - Form data
    if ($_GET["action"] == "submit") {
        if (
    $name == "") {
            echo 
    "Whoops! You didn't enter your name.";
            exit;
        }


        if (
    $comment == "") {
            echo 
    "Whoops! You didn't enter a comment.";
            exit;
        }
        
    $name addslashes(htmlspecialchars($name));
        
    $grade addslashes(htmlspecialchars($grade));
        
    $comment addslashes(htmlspecialchars($comment));
        
    $addpetition mysql_query("INSERT INTO `petition` (`name`, `grade`, `comment`, `ip`) VALUES ('$name','$grade','$comment', '$ip')") or die(mysql_error());

        
    // The form details are fine, display text & details
        
    echo "XX: <br />
    Name: 
    $name<br />
    Grade: 
    $grade<br />
    Your comment: 
    $comment<br />
    <br />
    To view all the signatures, click <a href=\"petition.php?view=entries\">here.</a> To go back to the home page, click <a href=\"index.php\">here.</a>"
    ;
        exit;
    } else 
    // Display the form
    {
        echo 
    "
    <div align\"center\">XX</div><br />
    <br />
    <form action=\"?action=submit\" method=\"post\">
        <div id=\"title\">Name:</div>
        <input type=\"text\" name=\"name\"><br /><br />
        <div id=\"title\">XX:</div>
        <select name=\"XX\">
        <option id=\"5\">XX</option>
        <option id=\"5\">XX</option>
        <option id=\"6\">XX</option>
        <option id=\"7\">XX</option>
        <option id=\"8\">XX</option>
        </select><br /><br />
        <div id=\"title\">Comment:</div>
        <style=\"width=\"169\"; height=\"116\"><textarea rows=\"7\" input type=\"text\" name=\"comment\" cols=\"28\"></textarea><br />
        <input type=\"submit\" name=\"submit\" value=\"Sign the petition!\">
        </form>"
    ;
        exit;
    }
    ?>
    Should output a MySQL error.

  3. #3
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Default

    Did you edit the code?

    And don't bother - I fixed it.

    I have one more question, what is wrong with this code, it's suppose to display the data from a mysql database but it doesn't.
    PHP Code:
    <?php

    include "config.php";

    $sql "SELECT * FROM petition";
    $check mysql_query($connect$sql)
    // The above variables will be used to check our connection to MySQL.

    if ($check) { // If we're able to connect, we continue in displaying.

    while ($display mysql_fetch_array($checkMYSQL_ASSOC)) {

    $name $display['name'];
    $grade $display['grade'];
    $comment $display['comment'];

    // Above are variables defined for our Name, XX and Comment.

    echo "
    Name: 
    $name 
    <br> 
    <br>
    XX: 
    $XX
    <br>
    <br>
    Comment: <br><br> 
    $comment
    <br>
    ___________________
    "
    ;

    } else {

    echo(
    "Sorry. We could not retrieve the information requested. Please try again later");
    }


    Selling DJ/Habbo layout, more info here.


  4. #4
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php

    include "config.php";

    $sql "SELECT * FROM petition";
    $check mysql_query("SELECT name, grade, comment FROM petition") or die("Cannot get it.");
    // The above variables will be used to check our connection to MySQL.

    while ($display mysql_fetch_array($check)) {

        
    $name $display['name'];
        
    $grade $display['grade'];
        
    $comment $display['comment'];

        
    // Above are variables defined for our Name, XX and Comment.

        
    echo "
    Name: 
    $name 
    <br> 
    <br>
    XX: 
    $XX
    <br>
    <br>
    Comment: <br><br> 
    $comment
    <br>
    ___________________
    "
    ;

    }
    ?>

  5. #5
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    I think your PHP configuration for MySQL is preventing it from generating errors...

  6. #6
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    The PHP configuration is probably preventing the whole script from generating errors, place this at the top of your file, see what it gives you on load.

    PHP Code:
    ini_set("display_errors""1");
    error_reporting(E_ALL); 
    before anything.

  7. #7
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Default

    The code you posted earlier works fine.

    When I add that display_errors code to the top of my code, I get: Notice: Use of undefined constant xx_who - assumed 'xx_who' in /home/voonu/public_html/miss/config.php on line 3
    Last edited by adamFTW; 06-12-2007 at 01:00 AM.


    Selling DJ/Habbo layout, more info here.


  8. #8
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    Yeah, remove it now. That just displays everything. If you just want to display errors use E_ERROR

  9. #9
    Join Date
    Apr 2007
    Location
    england
    Posts
    536
    Tokens
    0

    Default

    Okay, thank you.


    Selling DJ/Habbo layout, more info here.


Posting Permissions

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