SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, all. I have this piece of code to allow me to add data via from to my database. However, it doesn't work for me at all and so i would appreicate if anyone can point me the errors, as i new to this


    Code:


    <?

    if (!isset($submit)):

    ?>


    <html>
    <head><title>New Game Entry</title>
    <link rel="stylesheet" href="http://www.xplodercodes.com/xiccc.css" type="text/css">
    </head>

    <body bgcolor="#000000" text="#ffffff" link="#00ff00" vlink="#c0d9d9" alink="#ffffff">

    <h3>New Game Entry</h3><p>

    <form method=post action="<?=$PHP_SELF?>">

    <center>
    <table border=0 cellpadding=0 cellspacing=5>

    <tr><td align=right>Alpha</td>
    <td><input name=Alpha type=text maxlength=100 size=25>
    </td>
    </tr>

    <tr><td align=right>Game</td>
    <td><input name=Game type=text maxlength=100 size=25> </td>
    </tr>

    <tr>
    <td align=right>Publisher</td>
    <td><input name=Publisher type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right>Developer</td>
    <td><input name=Developer type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right colspan=2>
    <input type=reset value="Reset Form">
    <input type=submit name=”submit” value="Submit">
    </td>
    </tr>
    </table>
    </form>
    </center>

    </body>
    </html>

    <?php
    else:

    $dbhost = "localhost";
    $dbuser = "xiccc";
    $dbpass = "******";

    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
    or die("The database appears to be down.");

    if ($db!="" and !@mysql_select_db($db))
    die("The site database is unavailable.");

    return $dbcnx;


    if ($Alpha=="" or $Game=="" or $Publisher=="" or $Developer=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    }

    $sql = "INSERT INTO PlaystationRpg SET
    Alpha = '$Alpha',
    Game = '$Game',
    Publisher = '$Publisher',
    Developer = '$Developer'";

    if (!mysql_query($sql)) {
    error("A database error occurred in processing your submission.");
    }

    ?>

    <html>
    <head><title> Adding Complete </title></head>
    <body>
    <p>Entry Successfully Added!
    </body>
    </html>

    <?php
    endif;
    ?>

    Last edited by XploreR; May 24, 2001 at 05:17.

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($db!="" and !@mysql_select_db($db))
    die("The site database is unavailable.");

    Where do you define $db? I dont see that anywhere.

    return $dbcnx;

    Why do you do that? Its not needed. You're not working inside a function.


    if ($Alpha=="" or $Game=="" or $Publisher=="" or $Developer=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    }

    You realize that if the variables are blank it will print that out and still try to add them.

    Include a exit(); within that if statement.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Didn't Work Either

    Hi aspen!

    below is my corrected code but it didn't work either
    No matter what i do, after i clicked the submit, nothin happens

    Code


    <?

    if (!isset($submit)):

    ?>


    <html>
    <head><title>New Game Entry</title>
    <link rel="stylesheet" href="http://www.xplodercodes.com/xiccc.css" type="text/css">
    </head>

    <body bgcolor="#000000" text="#ffffff" link="#00ff00" vlink="#c0d9d9" alink="#ffffff">

    <h3>New Game Entry</h3><p>

    <form method=post action="<?=$PHP_SELF?>">

    <center>
    <table border=0 cellpadding=0 cellspacing=5>

    <tr><td align=right>Alpha</td>
    <td><input name=Alpha type=text maxlength=100 size=25>
    </td>
    </tr>

    <tr><td align=right>Game</td>
    <td><input name=Game type=text maxlength=100 size=25> </td>
    </tr>

    <tr>
    <td align=right>Publisher</td>
    <td><input name=Publisher type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right>Developer</td>
    <td><input name=Developer type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right colspan=2>
    <input type=reset value="Reset Form">
    <input type=submit name=”submit” value="Submit">
    </td>
    </tr>
    </table>
    </form>
    </center>

    </body>
    </html>

    <?php
    else:

    $dbhost = "localhost";
    $dbuser = "xiccc";
    $dbpass = "******";

    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
    or die("The database appears to be down.");

    if (!@mysql_select_db($db))
    die("The site database is unavailable.");

    if ($Alpha=="" or $Game=="" or $Publisher=="" or $Developer=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    exit();
    }

    $sql = "INSERT INTO PlaystationRpg SET
    Alpha = '$Alpha',
    Game = '$Game',
    Publisher = '$Publisher',
    Developer = '$Developer'";

    if (!mysql_query($sql)) {
    error("A database error occurred in processing your submission.");
    }

    ?>

    <html>
    <head><title> Adding Complete </title></head>
    <body>
    <p>Entry Successfully Added!
    </body>
    </html>

    <?php
    endif;
    ?>

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're still not defining $db.
    Last edited by CyberFuture; May 24, 2001 at 11:05.

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also add an exit; here:

    f (!mysql_query($sql)) {
    error("A database error occurred in processing your submission.");
    }

    above the }

  6. #6
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This right here is confusing me:
    PHP Code:
    if (!isset($submit)): 
    Why are you checking if $submit has a value and then ending the conditional? Instead of the semicolon shouldn't you have a set of braces with the desired content when $submit isn't set?
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, That is another way of doing the curly braces, using colons.

  8. #8
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really? Hmm...ok. How does that work? Syntax wise.
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  9. #9
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, not working either Please help Is there any thing i have missed out or placed in the wrong part?


    Code:


    <?

    if (!isset($submit)):

    ?>


    <html>
    <head><title>New Game Entry</title>
    <link rel="stylesheet" href="http://www.xplodercodes.com/xiccc.css" type="text/css">
    </head>

    <body bgcolor="#000000" text="#ffffff" link="#00ff00" vlink="#c0d9d9" alink="#ffffff">

    <h3>New Game Entry</h3><p>

    <form method=post action="<?=$PHP_SELF?>">

    <center>
    <table border=0 cellpadding=0 cellspacing=5>

    <tr><td align=right>Alpha</td>
    <td><input name=Alpha type=text maxlength=100 size=25>
    </td>
    </tr>

    <tr><td align=right>Game</td>
    <td><input name=Game type=text maxlength=100 size=25> </td>
    </tr>

    <tr>
    <td align=right>Publisher</td>
    <td><input name=Publisher type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right>Developer</td>
    <td><input name=Developer type=text maxlength=100 size=25></td>
    </tr>

    <tr><td align=right colspan=2>
    <input type=reset value="Reset Form">
    <input type=submit name=”submit” value="Submit">
    </td>
    </tr>
    </table>
    </form>
    </center>

    </body>
    </html>

    <?php
    else:

    $dbhost = "localhost";
    $dbuser = "xiccc";
    $dbpass = "*****";

    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
    or die("The database appears to be down.");

    $db = mysql_select_db("xiccc", $dbcnx) ;

    if (! @mysql_select_db("xiccc") ) {
    echo( "<P>Unable to locate the database at this time.</P>" );
    exit();
    }

    if ($Alpha=="" or $Game=="" or $Publisher=="" or $Developer=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    exit();
    }

    $sql = "INSERT INTO PlaystationRpg
    (Alpha, Game, Publisher, Developer)
    values ('$Alpha', '$Game', '$Publisher', '$Developer')";

    if (!mysql_query($sql)) {
    error("A database error occurred in processing your submission.");
    exit();
    }

    ?>

    <html>
    <head><title> Adding Complete </title></head>
    <body>
    <p>Entry Successfully Added!
    </body>
    </html>

    <?php
    endif;
    ?>

    Last edited by XploreR; May 24, 2001 at 21:39.


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
  •