Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
[PHP/MYSQL] POST Returns 0
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="NSA" data-source="post: 201761" data-attributes="member: 10034"><p>Hello,</p><p> </p><p>For some reason when I post the username data to PHP, it stores it in the database as 0.</p><p>I've posted my source below, ignore the JavaScript for now.</p><p> </p><p>install-2.php</p><p>[HTML]<!DOCTYPE html></p><p><html></p><p><head></p><p> <title>Live Chat Admin</title></p><p> <link rel="stylesheet" href="install_style.css" type="text/css" /></p><p> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script></p><p></head></p><p><body></p><p><div id="install_container"></p><p><h1>Live Chat Administration</h1></p><p><input type="text" id="username" name="username" placeholder="Admin Username..." /><br /></p><p><input type="password" id="password" name="password" placeholder="Admin Password..." /><br /></p><p><a href="" id="goBack">Go Back</a><a href="index.php" class="transition">Complete Setup</a></p><p><div id="tip"></p><p><p><b>Tip:</b> Before running the installation, you should create the database and run the SQL files included in the ZIP</p></p><p></div></p><p></div></p><p></body></p><p><script type="text/javascript"></p><p>$(document).ready(function() {</p><p> function submitData(){</p><p> var username = $('#username').val();</p><p> var password = $('#password').val();</p><p> /* get some values from elements on the page: */</p><p> url = "set_admin.php";</p><p> /* Send the data using post */</p><p> var posting = $.post( url, {username: username, password: password} );</p><p> }</p><p> $("body").css("display", "none");</p><p> </p><p> $("body").fadeIn(2000);</p><p> </p><p> $("a.transition").click(function(event){</p><p> submitData();</p><p> event.preventDefault();</p><p> linkLocation = this.href;</p><p> $("body").fadeOut(1000, redirectPage); </p><p> });</p><p> </p><p> function redirectPage() {</p><p> window.location = linkLocation;</p><p> }</p><p> </p><p>});</p><p>$("#goBack").click(function(event) {</p><p> event.preventDefault();</p><p> history.back(1);</p><p>});</p><p></script></p><p></html>[/HTML]</p><p> </p><p>set_admin.php</p><p>[PHP]<?php</p><p> include("config.php");</p><p> $con = mysql_connect($host,$usrnme,$psswrd);</p><p> mysql_select_db($db, $con);</p><p> $username = $_POST["username"];</p><p> $password = hash("sha512", $_POST['password']);</p><p> $old_password = hash("sha512", "password");</p><p> $q = "UPDATE chat_admins SET username = '$username' AND password = '$password' WHERE username = 'Josh' AND password = '$old_password'";</p><p> if(!mysql_query($q)){</p><p> $fp = fopen('config.php' , 'w');</p><p> fwrite($fp, "Could not set save some setting... try again.");</p><p> fclose($fp);</p><p> }</p><p>?></p><p>[/PHP]</p><p> </p><p>Any help would be appreciated.</p><p>Thanks.</p></blockquote><p></p>
[QUOTE="NSA, post: 201761, member: 10034"] 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>[/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); } ?> [/PHP] Any help would be appreciated. Thanks. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
[PHP/MYSQL] POST Returns 0
Top