简体   繁体   中英

failure to post PHP update to MySQL

i have a button i am trying to get where if i click it it updates the column 'gorg' in the table users to giver according to the current user (session) logged in. Everytime i click the button i get

Access denied for user 'root'@'localhost' (using password: NO)

Here is the top of the php page (BTW i am 100% positive my DB Connection info is correct)

<?php
session_start();
include('src/sql_handler.php'); //this is where my DB Connection info is located
include('src/facebook_handler_core.php');
if(isset($_POST['submitgiver'])) {
    $query = "UPDATE users SET gorg='giver' WHERE email='".mysql_real_escape_string($_SESSION['email'])."'";
    $result = mysql_query($query) or die(mysql_error());

}

{
  if(isset($_SESSION['gorg'])=="Giver")
  {
    header('Location: picktreetype.php');
  }
  else if(isset($_SESSION['gorg'])=="Gatherer")
  {
    header('Location: gatherermap.php');
  }

}

?>

and now for the html

<form method="post" action="<?php echo $PHP_SELF;?>">

<input type="submit" class="button orange" name="submitgiver" value="Giver">

</form>

UPDATE:

heres the SQL_HANDLER

<?php


class MySQL_Con {

    private $host = 'localhost',

            $user = 'fruitfo1_admin',

            $pass = 'password',

            $db = 'fruitfo1_fruitforest',

            $_CON;



    function MySQL_Con() {

        $this->_CON = mysql_connect($this->host, $this->user, $this->pass);

        if(!$this->_CON)

            die(mysql_error());

        else {

            $select_db = mysql_select_db($this->db);

            if(!$select_db)

                die('Error Connecting To Database'.mysql_error());

        }

    }

    function End_Con() {

        mysql_close($this->_CON);

    }

}

?>

Apparently your connection setup doesn't include a password. Please post the sql_handler (WITH OBFUSCATED password) to be able to debug further.

If you're 100% positive it's correct, as you're saying, you can try explicitly passing sql handle to mysql_query .

Another note, mysql_* are deprecated, you really should consider switching to either mysqli or PDO .

Also, using root user for ANY kinds of web-applications is a no-no.

Your DB doesn't have a password. Try this

  private $host = 'localhost',

        $user = 'fruitfo1_admin',

        $pass = '',

        $db = 'fruitfo1_fruitforest',

        $_CON;

i found my issue, it did have to do with exactly what i thought it was. heres my updated code

if(isset($_POST['submitgiver'])) {
$mysql_hostname = "localhost";
$mysql_user = "fruitfo1_admin";
$mysql_password = "password";
$mysql_database = "fruitfo1_fruitforest";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
$query = "UPDATE users SET gorg='giver' WHERE email='".mysql_real_escape_string($_SESSION['email'])."'";
$result = mysql_query($query) or die(mysql_error());
}

basically that IF statement that was attempting to POST wasnt linking back to my handler, so i placed the SAME db connection from the handler and carried it over inside the if isset statement and it worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM