SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Info not being INSERTed in database? Help!

    I'm using php-nuke, Since the whole site is database driven I belive, and correct me if i'm wrong, all my pages include a mainfile.php.

    I'n the mainfile.php it connects to the database & uses the config.php to get name, pass, etc.

    having said that I don't need to place code to "connect" to the database, only code to use it. Right?

    Here's the question:
    Why won't this code insert the data in the form into the database?

    PHP Code:
    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!isset($mainfile)) { include("mainfile.php"); }
    include(
    "header.php");

    if (
    "SUBMIT" == $addplayer) { 
        
    $sql "INSERT INTO player_profile SET " 
        
    "playerrealname='$playerrealname', " 
        
    "location='$location', " 
        
    "playerjob='$playerjob', " 
        
    "playercharactor='$playercharactor', " 
        
    "playerquote='$playerquote', " 
        
    "playerstatus='$playerstatus', " 
        
    "playerweapons='$playerweapons', " 
        
    "playerpicture='$playerpicture', " 
        
    "playerrealname='$playerrealname', " 
        
    "playername='$playername', ";
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been added.</P>"); 
        } else {
        echo(
    "<P>Error adding submitted profile: " 
        
    mysql_error() . "</P>"); }}
    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
    <P>Enter the new player:<BR><br>
    Name:       <INPUT TYPE="TEXT" NAME="playerrealname" SIZE=20MAXLENGTH=100><BR>
    Location:   <INPUT TYPE="TEXT" NAME="location" SIZE=20MAXLENGTH=100><BR>
    Job:        <INPUT TYPE="TEXT" NAME="playerjob" SIZE=20MAXLENGTH=100><BR>
    charactor:  <INPUT TYPE="TEXT" NAME="playercharactor" SIZE=20MAXLENGTH=100><BR>
    Quote:      <INPUT TYPE="TEXT" NAME="playerquote" SIZE=20MAXLENGTH=100><BR>
    Status:     <INPUT TYPE="TEXT" NAME="playerstatus" SIZE=20MAXLENGTH=100><BR>
    Weapons:    <INPUT TYPE="TEXT" NAME="playerweapons" SIZE=20MAXLENGTH=100><BR>
    Picture:    <INPUT TYPE="TEXT" NAME="playerpicture" SIZE=20MAXLENGTH=100><BR>
    Char. Name:    <INPUT TYPE="TEXT" NAME="playername" SIZE=20MAXLENGTH=100><BR>

    <INPUT TYPE="submit" NAME="addplayer" VALUE="Add Player"></P></FORM>

    <?php include("footer.php"); ?>
    P.S. It's not giving any errors, but it just reloads the page. There is no "Your profile has been added." or "Error adding submitted profile."

    TIA!
    Last edited by whofarted; Sep 3, 2001 at 01:42.
    You smell something?

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not totally sure that would generate an error, regardless of whether the query worked.

    Also I think you might have a bit of the query screwed up...There shouldn't be a comma at the end.

    Try this:
    PHP Code:
    if ("SUBMIT" == $addplayer) { 
        
    $sql "INSERT INTO player_profile SET " 
        
    "playerrealname='$playerrealname', " 
        
    "location='$location', " 
        
    "playerjob='$playerjob', " 
        
    "playercharactor='$playercharactor', " 
        
    "playerquote='$playerquote', " 
        
    "playerstatus='$playerstatus', " 
        
    "playerweapons='$playerweapons', " 
        
    "playerpicture='$playerpicture', " 
        
    "playerrealname='$playerrealname', " 
        
    "playername='$playername'";
    $query mysql_query($sql) or die(mysql_error());
    if (
    $query) {
        echo(
    "<P>Your profile has been added.</P>"); 
    }

    Kevin

  3. #3
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that didn't work either. Still the same problem.
    You smell something?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that chunk of code never gets run. You are checking for
    PHP Code:
    if ("SUBMIT" == $addplayer) { 
    And in your form you have the value of $addplayer set to Add Player

    PHP Code:

    <INPUT TYPE="submit" NAME="addplayer" VALUE="Add Player"

    You need to change the first line to

    PHP Code:
    if ("Add Player" == $addplayer) { 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I may have found another problem.

    The form is suppose to be:

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="POST">


    And it's being output as:

    <FORM ACTION="/profileadd.php" METHOD="POST">
    You smell something?

  6. #6
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
        $sql = "INSERT INTO player_profile VALUES(" . 
        "'$playerrealname', " . 
        "'$location', " . 
        "'$playerjob', " . 
        "'$playercharactor', " . 
        "'$playerquote', " . 
        "'$playerstatus', " . 
        "'$playerweapons', " . 
        "'$playerpicture', " . 
        "'$playerrealname', " . 
        "'$playername')";
    Try using that as the query. And did you select the database you want to use? You can do that by either calling mysql_select_db("DBNAME"); before you run the query, or use mysql_db_query("DBNAME", $sql);.
    signature

  7. #7
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That didn't work either.

    as I said before I'm using PHP nuke 5.2. I think by including mainfile.php it already has connection & database name chosen for you.

    I have yet to be told different.
    You smell something?

  8. #8
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, now its adding the info without me entering anything, It seems to remember the last time I tried to enter the info & is trying to re-enter it as I refresh the page.

    If I refresh Again I get the message

    "Error adding submitted profile: Duplicate entry 'testname' for key 1"

    It's tring to add that profile again without me filling anything in or even hitting the submit button.

    It's not waiting for me to submit anything so appearantly the code is running before I can do anything.

    How do I stop it?

    PS I used some of the suggestions above in a combination & the code is changed now.



    Here's the current code:
    PHP Code:
    <?php

    /************************************************************************/
    /* PHP-NUKE: Web Portal System                                          */
    /* ===========================                                          */
    /*                                                                      */
    /* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
    /* h*tp://phpnuke.org                                                   */
    /*                                                                      */
    /* This program is free software. You can redistribute it and/or modify */
    /* it under the terms of the GNU General Public License as published by */
    /* the Free Software Foundation; either version 2 of the License.       */
    /************************************************************************/

    if(!isset($mainfile)) { include("mainfile.php"); }
    include(
    "header.php");

    if (
    "Add Player" == $addplayer) { 
        
    $sql "INSERT INTO player_profile VALUES(" 
        
    "'$playerrealname', " 
        
    "'$location', " 
        
    "'$playerjob', " 
        
    "'$playercharactor', " 
        
    "'$playerquote', " 
        
    "'$playerstatus', " 
        
    "'$playerweapons', " 
        
    "'$playerpicture', " 
        
    "'$playername')";
    if (
    mysql_query($sql)) {
        echo(
    "<P>Your profile has been added.</P>"); 
        } else {
        echo(
    "<P>Error adding submitted profile: " 
        
    mysql_error() . "</P>"); }}
    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>"  METHOD="POST">
    <P>Enter the new player:<BR><br>
    Name:       <INPUT TYPE="TEXT" NAME="playerrealname" SIZE=20MAXLENGTH=100><BR>
    Location:   <INPUT TYPE="TEXT" NAME="location" SIZE=20MAXLENGTH=100><BR>
    Job:        <INPUT TYPE="TEXT" NAME="playerjob" SIZE=20MAXLENGTH=100><BR>
    charactor:  <INPUT TYPE="TEXT" NAME="playercharactor" SIZE=20MAXLENGTH=100><BR>
    Quote:      <INPUT TYPE="TEXT" NAME="playerquote" SIZE=20MAXLENGTH=100><BR>
    Status:     <INPUT TYPE="TEXT" NAME="playerstatus" SIZE=20MAXLENGTH=100><BR>
    Weapons:    <INPUT TYPE="TEXT" NAME="playerweapons" SIZE=20MAXLENGTH=100><BR>
    Picture:    <INPUT TYPE="TEXT" NAME="playerpicture" SIZE=20MAXLENGTH=100><BR>
    Char. Name:    <INPUT TYPE="TEXT" NAME="playername" SIZE=20MAXLENGTH=100><BR>

    <INPUT TYPE="submit" NAME="addplayer" VALUE="Add Player"></P></FORM>
    You smell something?

  9. #9
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind this one.....Got it all figured out!
    You smell something?


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
  •