mySQL database UPDATE table SET.... help

  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Quote:
<?php
error_reporting(E_ALL);
session_start();
include("top.php");
$id = $_SESSION["id"];
//echo $id;
$conn = mysql_connect("localhost","adm","******") or die(mysql_error());
$db = mysql_select_db("fs",$conn) or die(mysql_error());
$result = mysql_query("UPDATE users SET username='$username' WHERE id='$id'") or die(mysql_error());
echo "<p>Done!";
echo "<p>< a href='account.php'>Back To Account< /a>";
echo "<br>< a href='main.php'>Warehouse< /a>";
echo "<br>< a href='index.php'>Home< /a>";
include("bottom.php");
?>


could someone please tell me what is wrong with this, because it won't do what i ask it to (update selected row in table)please tell me whats wrong with it, or an alternative solution
btw I never get any errors while running this script, thats the scariest part of all, it wont work and wont show errors
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Well I would try getting rid of the ' around your variables in the mysql query statement. So instead of using:

Code: [ Select ]
UPDATE users SET username='$username' WHERE id='$id'


I would use:

Code: [ Select ]
UPDATE users SET username=$username WHERE id=$id


Usually when you put single quots around variables they will not be replaced with the actual value of the variable. I am not sure if that is causing your problem, but I would try that first. I have a feeling that is your problem though, because that would explain why you get no errors. It is simply doing nothing because it cannot find any id that matches '$id' since that isn't being replaced with anything (it just stays as $id literally). Let us know what happens!
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

man, I was honestly praying to God that what you said would work, since if it works my whole game is set, I can make the rest of it no problem
but Newton's (or Murphy's) Law says" everything that can go wrong, will"

Error:

Unknown column 'test' in 'field list'

test is the username and when username=$username in the sql query, it thinks of $username as a column (at least thats what i figure) please help, open to any and all suggestions
or could someone psot a script they use to update db
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Show the new code that you were using that produced the error you said above.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Quote:
<?php
error_reporting(E_ALL);
session_start();
include("top.php");
$id = $_SESSION["id"];
//echo $id;
$conn = mysql_connect("localhost","adm","******") or die(mysql_error());
$db = mysql_select_db("fs",$conn) or die(mysql_error());
$result = mysql_query("UPDATE users SET username=$username WHERE id=$id") or die(mysql_error());
echo "<p>Done!";
echo "<p>< a href='account.php'>Back To Account< /a>";
echo "<br>< a href='main.php'>Warehouse< /a>";
echo "<br>< a href='index.php'>Home< /a>";
include("bottom.php");
?>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I do not have an answer for you yet, but I just wanted to let you know that I replaced your password above in your code examples to ****** because I wasn't sure if you used fake credentials there. We do not need anyone trying to hack into your server. If that was your actual info you used, I would at least change that part before you post it here. Many of these posts can be viewed by thousands of people.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Bigwebmaster wrote:
I do not have an answer for you yet, but I just wanted to let you know that I replaced your password above in your code examples to ****** because I wasn't sure if you used fake credentials there. We do not need anyone trying to hack into your server. If that was your actual info you used, I would at least change that part before you post it here. Many of these posts can be viewed by thousands of people.

tnx, but dont u think i know that, that isnt a real server, it just a test server on my comp, so i dont bother replacing passwords and usernames
the real db on the website is completely different
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Well that is good to know, however, some people will suprise on what they will post so I was just taking precautions to protect you. (Just in case).
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

As far as you problem is concerned, this is how I usually use PHP to update the MySQL database:

Code: [ Select ]
$sql = "UPDATE users SET username = $username WHERE id = $id";
if ( !($result = $db->sql_query($sql)) )  {
  message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
}
  1. $sql = "UPDATE users SET username = $username WHERE id = $id";
  2. if ( !($result = $db->sql_query($sql)) )  {
  3.   message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
  4. }


Just so you know this requires some functions that I use from PHPBB to do it the way I do. You might download PHPBB to take a look at it.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

tnx for the concern

well i tried it the way you did it

Quote:
$sql = "UPDATE users SET username = $username WHERE id = $id";

if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
}

and it gave me this:
$result = mysql_query($sql);

Fatal error: Call to a member function on a non-object in c:\apache\htdocs\account_edit2.php on line 11
line 11 is the line where the if statement is placed
then i tried this
Quote:
$sql = "UPDATE users SET username = $username WHERE id = $id";
$result = mysql_query($sql);
if (!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
}


and it gives same error referring to the if statement, i tried altering it around a bit and it didnt work, please check, maybe u typed something wrong in there, i'm going back to looking for an answer to this
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Well like I said, it requires some other functions that came with PHPBB to do it the way I did. You would need to get those functions. I am sure you probably do not need all this though, and you could probably do it without all the functions. However, if you look at the functions you might be able to figure out the correct way to do it. Here are the functions that come with PHPBB in the mysql.php file:

Code: [ Select ]
<?php
/***************************************************************************
*                 mysql.php
*              -------------------
*  begin        : Saturday, Feb 13, 2001
*  copyright      : (C) 2001 The phpBB Group
*  email        : support@phpbb.com
*
*  $Id: mysql.php,v 1.16 2002/03/19 01:07:36 psotfx Exp $
*
***************************************************************************/

/***************************************************************************
*
*  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, or
*  (at your option) any later version.
*
***************************************************************************/

if(!defined("SQL_LAYER"))
{

define("SQL_LAYER","mysql");

class sql_db
{

    var $db_connect_id;
    var $query_result;
    var $row = array();
    var $rowset = array();
    var $num_queries = 0;

    //
    // Constructor
    //
    function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
    {

        $this->persistency = $persistency;
        $this->user = $sqluser;
        $this->password = $sqlpassword;
        $this->server = $sqlserver;
        $this->dbname = $database;

        if($this->persistency)
        {
            $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
        }
        else
        {
            $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
        }
        if($this->db_connect_id)
        {
            if($database != "")
            {
                $this->dbname = $database;
                $dbselect = @mysql_select_db($this->dbname);
                if(!$dbselect)
                {
                    @mysql_close($this->db_connect_id);
                    $this->db_connect_id = $dbselect;
                }
            }
            return $this->db_connect_id;
        }
        else
        {
            return false;
        }
    }

    //
    // Other base methods
    //
    function sql_close()
    {
        if($this->db_connect_id)
        {
            if($this->query_result)
            {
                @mysql_free_result($this->query_result);
            }
            $result = @mysql_close($this->db_connect_id);
            return $result;
        }
        else
        {
            return false;
        }
    }

    //
    // Base query method
    //
    function sql_query($query = "", $transaction = FALSE)
    {
        // Remove any pre-existing queries
        unset($this->query_result);
        if($query != "")
        {
            $this->num_queries++;

            $this->query_result = @mysql_query($query, $this->db_connect_id);
        }
        if($this->query_result)
        {
            unset($this->row[$this->query_result]);
            unset($this->rowset[$this->query_result]);
            return $this->query_result;
        }
        else
        {
            return ( $transaction == END_TRANSACTION ) ? true : false;
        }
    }

    //
    // Other query methods
    //
    function sql_numrows($query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = @mysql_num_rows($query_id);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_affectedrows()
    {
        if($this->db_connect_id)
        {
            $result = @mysql_affected_rows($this->db_connect_id);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_numfields($query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = @mysql_num_fields($query_id);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_fieldname($offset, $query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = @mysql_field_name($query_id, $offset);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_fieldtype($offset, $query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = @mysql_field_type($query_id, $offset);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_fetchrow($query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $this->row[$query_id] = @mysql_fetch_array($query_id);
            return $this->row[$query_id];
        }
        else
        {
            return false;
        }
    }
    function sql_fetchrowset($query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            unset($this->rowset[$query_id]);
            unset($this->row[$query_id]);
            while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
            {
                $result[] = $this->rowset[$query_id];
            }
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_fetchfield($field, $rownum = -1, $query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            if($rownum > -1)
            {
                $result = @mysql_result($query_id, $rownum, $field);
            }
            else
            {
                if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
                {
                    if($this->sql_fetchrow())
                    {
                        $result = $this->row[$query_id][$field];
                    }
                }
                else
                {
                    if($this->rowset[$query_id])
                    {
                        $result = $this->rowset[$query_id][$field];
                    }
                    else if($this->row[$query_id])
                    {
                        $result = $this->row[$query_id][$field];
                    }
                }
            }
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_rowseek($rownum, $query_id = 0){
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = @mysql_data_seek($query_id, $rownum);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_nextid(){
        if($this->db_connect_id)
        {
            $result = @mysql_insert_id($this->db_connect_id);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_freeresult($query_id = 0){
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }

        if ( $query_id )
        {
            unset($this->row[$query_id]);
            unset($this->rowset[$query_id]);

            @mysql_free_result($query_id);

            return true;
        }
        else
        {
            return false;
        }
    }
    function sql_error($query_id = 0)
    {
        $result["message"] = @mysql_error($this->db_connect_id);
        $result["code"] = @mysql_errno($this->db_connect_id);

        return $result;
    }

} // class sql_db

} // if ... define

?>
  1. <?php
  2. /***************************************************************************
  3. *                 mysql.php
  4. *              -------------------
  5. *  begin        : Saturday, Feb 13, 2001
  6. *  copyright      : (C) 2001 The phpBB Group
  7. *  email        : support@phpbb.com
  8. *
  9. *  $Id: mysql.php,v 1.16 2002/03/19 01:07:36 psotfx Exp $
  10. *
  11. ***************************************************************************/
  12. /***************************************************************************
  13. *
  14. *  This program is free software; you can redistribute it and/or modify
  15. *  it under the terms of the GNU General Public License as published by
  16. *  the Free Software Foundation; either version 2 of the License, or
  17. *  (at your option) any later version.
  18. *
  19. ***************************************************************************/
  20. if(!defined("SQL_LAYER"))
  21. {
  22. define("SQL_LAYER","mysql");
  23. class sql_db
  24. {
  25.     var $db_connect_id;
  26.     var $query_result;
  27.     var $row = array();
  28.     var $rowset = array();
  29.     var $num_queries = 0;
  30.     //
  31.     // Constructor
  32.     //
  33.     function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
  34.     {
  35.         $this->persistency = $persistency;
  36.         $this->user = $sqluser;
  37.         $this->password = $sqlpassword;
  38.         $this->server = $sqlserver;
  39.         $this->dbname = $database;
  40.         if($this->persistency)
  41.         {
  42.             $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
  43.         }
  44.         else
  45.         {
  46.             $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
  47.         }
  48.         if($this->db_connect_id)
  49.         {
  50.             if($database != "")
  51.             {
  52.                 $this->dbname = $database;
  53.                 $dbselect = @mysql_select_db($this->dbname);
  54.                 if(!$dbselect)
  55.                 {
  56.                     @mysql_close($this->db_connect_id);
  57.                     $this->db_connect_id = $dbselect;
  58.                 }
  59.             }
  60.             return $this->db_connect_id;
  61.         }
  62.         else
  63.         {
  64.             return false;
  65.         }
  66.     }
  67.     //
  68.     // Other base methods
  69.     //
  70.     function sql_close()
  71.     {
  72.         if($this->db_connect_id)
  73.         {
  74.             if($this->query_result)
  75.             {
  76.                 @mysql_free_result($this->query_result);
  77.             }
  78.             $result = @mysql_close($this->db_connect_id);
  79.             return $result;
  80.         }
  81.         else
  82.         {
  83.             return false;
  84.         }
  85.     }
  86.     //
  87.     // Base query method
  88.     //
  89.     function sql_query($query = "", $transaction = FALSE)
  90.     {
  91.         // Remove any pre-existing queries
  92.         unset($this->query_result);
  93.         if($query != "")
  94.         {
  95.             $this->num_queries++;
  96.             $this->query_result = @mysql_query($query, $this->db_connect_id);
  97.         }
  98.         if($this->query_result)
  99.         {
  100.             unset($this->row[$this->query_result]);
  101.             unset($this->rowset[$this->query_result]);
  102.             return $this->query_result;
  103.         }
  104.         else
  105.         {
  106.             return ( $transaction == END_TRANSACTION ) ? true : false;
  107.         }
  108.     }
  109.     //
  110.     // Other query methods
  111.     //
  112.     function sql_numrows($query_id = 0)
  113.     {
  114.         if(!$query_id)
  115.         {
  116.             $query_id = $this->query_result;
  117.         }
  118.         if($query_id)
  119.         {
  120.             $result = @mysql_num_rows($query_id);
  121.             return $result;
  122.         }
  123.         else
  124.         {
  125.             return false;
  126.         }
  127.     }
  128.     function sql_affectedrows()
  129.     {
  130.         if($this->db_connect_id)
  131.         {
  132.             $result = @mysql_affected_rows($this->db_connect_id);
  133.             return $result;
  134.         }
  135.         else
  136.         {
  137.             return false;
  138.         }
  139.     }
  140.     function sql_numfields($query_id = 0)
  141.     {
  142.         if(!$query_id)
  143.         {
  144.             $query_id = $this->query_result;
  145.         }
  146.         if($query_id)
  147.         {
  148.             $result = @mysql_num_fields($query_id);
  149.             return $result;
  150.         }
  151.         else
  152.         {
  153.             return false;
  154.         }
  155.     }
  156.     function sql_fieldname($offset, $query_id = 0)
  157.     {
  158.         if(!$query_id)
  159.         {
  160.             $query_id = $this->query_result;
  161.         }
  162.         if($query_id)
  163.         {
  164.             $result = @mysql_field_name($query_id, $offset);
  165.             return $result;
  166.         }
  167.         else
  168.         {
  169.             return false;
  170.         }
  171.     }
  172.     function sql_fieldtype($offset, $query_id = 0)
  173.     {
  174.         if(!$query_id)
  175.         {
  176.             $query_id = $this->query_result;
  177.         }
  178.         if($query_id)
  179.         {
  180.             $result = @mysql_field_type($query_id, $offset);
  181.             return $result;
  182.         }
  183.         else
  184.         {
  185.             return false;
  186.         }
  187.     }
  188.     function sql_fetchrow($query_id = 0)
  189.     {
  190.         if(!$query_id)
  191.         {
  192.             $query_id = $this->query_result;
  193.         }
  194.         if($query_id)
  195.         {
  196.             $this->row[$query_id] = @mysql_fetch_array($query_id);
  197.             return $this->row[$query_id];
  198.         }
  199.         else
  200.         {
  201.             return false;
  202.         }
  203.     }
  204.     function sql_fetchrowset($query_id = 0)
  205.     {
  206.         if(!$query_id)
  207.         {
  208.             $query_id = $this->query_result;
  209.         }
  210.         if($query_id)
  211.         {
  212.             unset($this->rowset[$query_id]);
  213.             unset($this->row[$query_id]);
  214.             while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
  215.             {
  216.                 $result[] = $this->rowset[$query_id];
  217.             }
  218.             return $result;
  219.         }
  220.         else
  221.         {
  222.             return false;
  223.         }
  224.     }
  225.     function sql_fetchfield($field, $rownum = -1, $query_id = 0)
  226.     {
  227.         if(!$query_id)
  228.         {
  229.             $query_id = $this->query_result;
  230.         }
  231.         if($query_id)
  232.         {
  233.             if($rownum > -1)
  234.             {
  235.                 $result = @mysql_result($query_id, $rownum, $field);
  236.             }
  237.             else
  238.             {
  239.                 if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
  240.                 {
  241.                     if($this->sql_fetchrow())
  242.                     {
  243.                         $result = $this->row[$query_id][$field];
  244.                     }
  245.                 }
  246.                 else
  247.                 {
  248.                     if($this->rowset[$query_id])
  249.                     {
  250.                         $result = $this->rowset[$query_id][$field];
  251.                     }
  252.                     else if($this->row[$query_id])
  253.                     {
  254.                         $result = $this->row[$query_id][$field];
  255.                     }
  256.                 }
  257.             }
  258.             return $result;
  259.         }
  260.         else
  261.         {
  262.             return false;
  263.         }
  264.     }
  265.     function sql_rowseek($rownum, $query_id = 0){
  266.         if(!$query_id)
  267.         {
  268.             $query_id = $this->query_result;
  269.         }
  270.         if($query_id)
  271.         {
  272.             $result = @mysql_data_seek($query_id, $rownum);
  273.             return $result;
  274.         }
  275.         else
  276.         {
  277.             return false;
  278.         }
  279.     }
  280.     function sql_nextid(){
  281.         if($this->db_connect_id)
  282.         {
  283.             $result = @mysql_insert_id($this->db_connect_id);
  284.             return $result;
  285.         }
  286.         else
  287.         {
  288.             return false;
  289.         }
  290.     }
  291.     function sql_freeresult($query_id = 0){
  292.         if(!$query_id)
  293.         {
  294.             $query_id = $this->query_result;
  295.         }
  296.         if ( $query_id )
  297.         {
  298.             unset($this->row[$query_id]);
  299.             unset($this->rowset[$query_id]);
  300.             @mysql_free_result($query_id);
  301.             return true;
  302.         }
  303.         else
  304.         {
  305.             return false;
  306.         }
  307.     }
  308.     function sql_error($query_id = 0)
  309.     {
  310.         $result["message"] = @mysql_error($this->db_connect_id);
  311.         $result["code"] = @mysql_errno($this->db_connect_id);
  312.         return $result;
  313.     }
  314. } // class sql_db
  315. } // if ... define
  316. ?>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I looked a little more at your original script and I really do not see why that one shouldn't work. I went and viewed a few other sample scripts and they look simliliar to yours. Here is one I looked at:

Code: [ Select ]
$mysql_link = mysql_connect("hostname", "username", "password");
$mysql_select_db("database", $mysql_link);
$query = "Update table set field2 = $name";
$result = mysql_query($query);
  1. $mysql_link = mysql_connect("hostname", "username", "password");
  2. $mysql_select_db("database", $mysql_link);
  3. $query = "Update table set field2 = $name";
  4. $result = mysql_query($query);


It looks almost idential to yours, but the query is made in its own variable. Also have you already created the tables in your MySQL database that you are trying to update?
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

yes i have created the tables, otherwise there would be nothin to update, and yeah, that script does look identical to mine except variable names, i honestly dont know y this doesn't work
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

i just tried this on a completely different mySQL database, on my website, hoping that this was just an error with the mysql on my comp, and once again, nothing happens, and no errors.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Have you tested to make sure data is stored in the $username and $id variables? In other words they are not blank correct? Also I know you said you had the MySQL table setup, but do you have an ID in that MySQL table that matches the ID that you are sending through the $id variable?

Also, what version of MySQL and PHP are you using?

Finally have you tried to run that MySQL query manually through MyPHPAdmin or some other interface if you have it, just to make sure it actually works on your database?

I am just shooting blanks in the dark here, since you really haven't provided me much to work with but your little snippet of code. Hopefully one of these blanks will hit something soon :)
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Bigwebmaster wrote:
Have you tested to make sure data is stored in the $username and $id variables? In other words they are not blank correct? Also I know you said you had the MySQL table setup, but do you have an ID in that MySQL table that matches the ID that you are sending through the $id variable?

Also, what version of MySQL and PHP are you using?

Finally have you tried to run that MySQL query manually through MyPHPAdmin or some other interface if you have it, just to make sure it actually works on your database?

I am just shooting blanks in the dark here, since you really haven't provided me much to work with but your little snippet of code. Hopefully one of these blanks will hit something soon :)

yes I have tested everything, and i can get anyone to register from website so through php, no problem, i can delete too, but the one thing is the UPDATE function that dont work

yes there is an id and it does match, if u want i'll post up all my code on my site and you can see it

on my comp i'm runnign the latest php and mysql (using PHPTriad -PHP, mySQL, Apache server), on my website i'm not sure but i believe my host is also using the latest versions
yes I have used phpMyAdmin to make it work and it once again works no problem

i'll go put up all the code that i got, for everything related to this and maybe u could make heads or tales of the problem.
the url will be
http://www.dragonsoftheweb.com/fs/
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

ok, all the files are up on
http://www.dragonsoftheweb.com/fs
had to put them in txt format so u cna read them, and dont know how to make code appear using xml yet
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Well I have gone through many of your files and I am as really stumped as you are. If there is a problem in the code I am not seeing it. The only thing that I see that varies with your structure in some of your files is at times you will use:

Code: [ Select ]
$db = mysql_select_db("fs",$conn) or die(mysql_error());


and other times you will use:

Code: [ Select ]
$db = mysql_select_db("fs");


The only other thing I can suggest is to first view your mysql logs and httpd log files if you can. On my system the httpd and mysql logs are located at:

/var/log/mysqld.log
/var/log/httpd/error_log
/var/log/httpd/access_log

The log files might give you some clues. You might consider also turning the debugging level up higher in your conf files so that more errors/warnings show up that might put you in the right direction.

Also another thing I usually do when I am stumped is insert print/echo command after each line of code you execute so you can see exactly what is going on with everything. I would usually print out all variables after each line so I can evalute everything and see if anything looks wrong there. The fact that you are not getting any internal server errors is telling you that your syntax is right, and probably some kind of logical error exists (which are probably the hardest ones to figure out, just like we haven't figured it out yet).

Anyway unless someone else has some ideas, I am all out. If you do figure this out I would love to know what the problem is.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

thanks for the help, i'm gonna go try to find my error log folders on my server, hpefully i'll be able to solve this error
  • bveditz
  • Novice
  • Novice
  • bveditz
  • Posts: 15

Post 3+ Months Ago

Bigwebmaster wrote:
Have you tested to make sure data is stored in the $username and $id variables? In other words they are not blank correct? Also I know you said you had the MySQL table setup, but do you have an ID in that MySQL table that matches the ID that you are sending through the $id variable?

I agree with you here, looking at his code it should work. My experience with these issues has always been bad data. If I were him, I'd verify the data he's trying to input is valid as well as verify that it matches the format he's trying to input. For instance, $username and Username fields are both text and $id and id are both numbers. Don't know how strict mysql is on this, but it would kill other brands sql.

Another thought is to post the same query to the screen as you send to mssql. After it prints to the screen, verify it looks correct and isn't adding any quotes or anything, then copy the statement into phpmyadmin or mysql directly and run it.
  • Voetsjoeba
  • Novice
  • Novice
  • User avatar
  • Posts: 31
  • Loc: Belgium, Ghent.

Post 3+ Months Ago

I believe you needed double quotes around the values:

UPDATE tablename SET field = "theNewValue" WHERE field = "theOldValue";

In PHP that would become:

Code: [ Select ]
$conn = mysql_connect("host","username","pw");
$q = "UPDATE tablename SET field = \"$newValue\" WHERE field = \"$theOldValue\"";
$result = mysql_query($q,$conn);
  1. $conn = mysql_connect("host","username","pw");
  2. $q = "UPDATE tablename SET field = \"$newValue\" WHERE field = \"$theOldValue\"";
  3. $result = mysql_query($q,$conn);


Give it a try :)
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Voetsjoeba wrote:
I believe you needed double quotes around the values:

UPDATE tablename SET field = "theNewValue" WHERE field = "theOldValue";

In PHP that would become:

Code: [ Select ]
$conn = mysql_connect("host","username","pw");
$q = "UPDATE tablename SET field = "$newValue" WHERE field = "$theOldValue"";
$result = mysql_query($q,$conn);
  1. $conn = mysql_connect("host","username","pw");
  2. $q = "UPDATE tablename SET field = "$newValue" WHERE field = "$theOldValue"";
  3. $result = mysql_query($q,$conn);


Well the double quotes were the first thing I used, (look at the previous versions of code on this page)
but the backslashes I'll try, never saw a command line like that with backslashes though

Give it a try :)
  • Voetsjoeba
  • Novice
  • Novice
  • User avatar
  • Posts: 31
  • Loc: Belgium, Ghent.

Post 3+ Months Ago

The backslashes are there to make sure PHP doesn't see the " as the ending of the string definition.

Example:

$a = "Variable goes here"; //valid
$b = "This is a double quote: \""; //valid
$c = "This is a double quote: ""; //invalid

By the way, " is not the same as ' for MySQL.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Voetsjoeba wrote:
The backslashes are there to make sure PHP doesn't see the " as the ending of the string definition.

Example:

$a = "Variable goes here"; //valid
$b = "This is a double quote: ""; //valid
$c = "This is a double quote: ""; //invalid

By the way, " is not the same as ' for MySQL.

I tried it with the backslashes and it didn't work, and yes, I do know there is a difference b/w the " and the ' and I already tried both and neither work.
  • Voetsjoeba
  • Novice
  • Novice
  • User avatar
  • Posts: 31
  • Loc: Belgium, Ghent.

Post 3+ Months Ago

Hmn ... then it should work. Are you sure the database and table exist, and that you have the right to edit them ?
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

Voetsjoeba wrote:
Hmn ... then it should work. Are you sure the database and table exist, and that you have the right to edit them ?


I though I already said this, but if not, the whole server mySQl PhP, etc are all on my machine its localhost. so I have the editing rights and the table is fine. Anyways, thanks for all the help guys and I finally got it to work

Code: [ Select ]
<?php
session_start();
echo "Hi \n";
echo $_SESSION["username"];
//echo "\n";
$id = $_SESSION["id"];
//echo $id;
echo "\n";
//echo $user;

/*$result = MYSQL_QUERY("INSERT INTO users (strength)". "VALUES ('$strup')"); */
    $conn = mysql_connect("localhost","adm","alphax") or die(mysql_error());
    $db = mysql_select_db("fs",$conn) or die(mysql_error());
    $sql = "UPDATE users SET username = '$user' WHERE id = $id";
    $result = mysql_query($sql);
echo "<p>Done!<br>";
    echo "Your username is now $user !!!";
    
    echo "<p><a href='account.php'>Back To Account</a>";
    echo "<br><a href='main.php'>Warehouse</a>";
    echo "<br><a href='index.php'>Home</a>";
include("bottom.php");
?>
  1. <?php
  2. session_start();
  3. echo "Hi \n";
  4. echo $_SESSION["username"];
  5. //echo "\n";
  6. $id = $_SESSION["id"];
  7. //echo $id;
  8. echo "\n";
  9. //echo $user;
  10. /*$result = MYSQL_QUERY("INSERT INTO users (strength)". "VALUES ('$strup')"); */
  11.     $conn = mysql_connect("localhost","adm","alphax") or die(mysql_error());
  12.     $db = mysql_select_db("fs",$conn) or die(mysql_error());
  13.     $sql = "UPDATE users SET username = '$user' WHERE id = $id";
  14.     $result = mysql_query($sql);
  15. echo "<p>Done!<br>";
  16.     echo "Your username is now $user !!!";
  17.     
  18.     echo "<p><a href='account.php'>Back To Account</a>";
  19.     echo "<br><a href='main.php'>Warehouse</a>";
  20.     echo "<br><a href='index.php'>Home</a>";
  21. include("bottom.php");
  22. ?>


don't know why it wasnt working earlier, but I played around with the code a bit changed very small things couple times, and changed variable names also and now it works.
Hopefully I'll have the game up and running in about a month I'll be srue to post here once it is done.
  • mykh
  • Novice
  • Novice
  • mykh
  • Posts: 16

Post 3+ Months Ago

now I got another question, let's say I want to display every username in the table what would be the code?

Post Information

  • Total Posts in this topic: 27 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.