Jump to content

Not sure where im going wrong with this code, could anyone give me a hand please


Njowils

Recommended Posts

Alright, this is the code that i cant seem to get working. Its supposed to update the pin_lock field in my database. I have two databases that it needs to read from, the Account database to verify the login, then the Game database to modify the pin_lock field. It comes up that its sucessfully modified the entry but when i check it, its still the same as it was before.

 

session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') 
{ print("<center>Incorrect verification code!"); die(); }
require_once('config.php');
mysql_select_db($accdb);
$accountid=$_POST['accountid'];
$pass=$_POST['pass'];
$email=$_POST["email"];
$idnumber=$_POST["question"];
$phone=$_POST["answer"];
session_start(); 
if(!$_POST["accountid"]) { print("<center>Account ID Field Empty!"); die(); }
if(!$_POST["email"]) { print("<center>E-mail Address Field Empty!"); die(); }
if(!$_POST["question"]) { print("<center>Security Questions Field Empty!"); die(); }
if(!$_POST["answer"]) { print("<center>Answer Field Empty!"); die(); }
if(!ereg("^[0-9a-z]{4,12}$",$accountid)) { print("<center>Account ID Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 12 characters"); die(); }
if(!ereg("^[0-9a-z]{4,14}$",$pass)) { print("<center>Password Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 14 characters"); die(); }
if(!ereg("^[0-9a-zA-Z_]{4,128}$", (strtr($email, Array('@'=>'','.'=>'')))))  { print("<center>E-mail Only letters a to z and special chars @ . are allowed!"); die(); }
if($_POST["pass"]!=$_POST["pass2"]) { print("<center>Passwords do not match!"); die(); }

$ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'")));
if (!$ac)
{ print("<center>Account ID does not exist!"); die(); }

$em = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND email='$email'")));
if (!$em)
{ print("<center>E-mail is incorrect!"); die(); }

$q = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND idnumber='$idnumber'")));
if (!$q)
{ print("<center>Security Question is incorrect!"); die(); }

$an = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND phone='$phone'")));
if (!$an)
{ print("<center>Answer is incorrect!"); die(); }
$ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'")));
mysql_select_db($gamedb);
$temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'");
  if (!mysql_query($temp["query"])) { die(mysql_error()); }
  else { print("<center>You bank pin has been removed!"); }

 

Any ideas what is wrong with it?

Link to comment
Share on other sites

My best guess is that the query string doesn't contain the values you'd expect it to contain. An UPDATE query can execute successfully even if it doesn't actually change anything, so it's best to check the result with mysql_affected_rows.

 

$temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'");
  if (!mysql_query($temp["query"])) {
  	die(mysql_error());
} else {
if( mysql_affected_rows() === 1 ) {
	print("<center>You bank pin has been removed!");
} elseif( mysql_affected_rows() !== 0 ) {
	echo '<br><font color="red">' . mysql_affected_rows() . " records were updated by the query:</font> {$temp['query']}<br>";
}
}

Link to comment
Share on other sites

I just noticed something I left in there from a different train of thought I was having. The elseif() needs to be removed and replace with just an else{}:

 

$temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'");
  if (!mysql_query($temp["query"])) {
  	die(mysql_error());
} else {
if( mysql_affected_rows() === 1 ) {
	print("<center>You bank pin has been removed!");
} else {
	echo "<br>No records were updated by the query: {$temp['query']}<br>";
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.