[PHP/MYSQL] POST Returns 0

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello,

For some reason when I post the username data to PHP, it stores it in the database as 0.
I've posted my source below, ignore the JavaScript for now.

install-2.php
HTML:
<!DOCTYPE html>
<html>
<head>
    <title>Live Chat Admin</title>
    <link rel="stylesheet" href="install_style.css" type="text/css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div id="install_container">
<h1>Live Chat Administration</h1>
<input type="text" id="username" name="username" placeholder="Admin Username..." /><br />
<input type="password" id="password" name="password" placeholder="Admin Password..." /><br />
<a href="" id="goBack">Go Back</a><a href="index.php" class="transition">Complete Setup</a>
<div id="tip">
<p><b>Tip:</b> Before running the installation, you should create the database and run the SQL files included in the ZIP</p>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
    function submitData(){
    var username = $('#username').val();
    var password = $('#password').val();
      /* get some values from elements on the page: */
        url = "set_admin.php";
  /* Send the data using post */
  var posting = $.post( url, {username:  username, password: password} );
    }
    $("body").css("display", "none");
 
    $("body").fadeIn(2000);
 
    $("a.transition").click(function(event){
        submitData();
        event.preventDefault();
        linkLocation = this.href;
        $("body").fadeOut(1000, redirectPage);   
    });
     
    function redirectPage() {
        window.location = linkLocation;
    }
 
});
$("#goBack").click(function(event) {
    event.preventDefault();
    history.back(1);
});
</script>
</html>

set_admin.php
PHP:
<?php
    include("config.php");
    $con = mysql_connect($host,$usrnme,$psswrd);
    mysql_select_db($db, $con);
    $username = $_POST["username"];
    $password = hash("sha512", $_POST['password']);
    $old_password = hash("sha512", "password");
        $q = "UPDATE chat_admins SET username = '$username' AND password = '$password' WHERE username = 'Josh' AND password = '$old_password'";
        if(!mysql_query($q)){
            $fp = fopen('config.php' , 'w');
            fwrite($fp, "Could not set save some setting... try again.");
            fclose($fp);
        }
?>

Any help would be appreciated.
Thanks.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,457
Not sure, but anyways do your query's like this:
PHP:
$q = "UPDATE chat_admins SET username = '".$username."' AND password = '".$password."' WHERE username = 'Josh' AND password = '".$old_password." '";
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Note to people using UPDATE: Do not use AND when specifying changes (UPDATE something=something AND something=something) but instead use ",".
(Except when specifying what to change them to (WHERE something=something))
I was trying to fix this for 2 hours.
It was something as simple as that.
Please close thread.
 

Users who are viewing this thread

Top