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?

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>";
}
}

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>";
}
}

Okay, i tried it. It comes up with the "no records were updated by the query" error, can you see why it wont change the lock_key to 0?

 

im totally stuck and ive got very little knowledge of PHP this advanced.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.