mmarif4u Posted February 5, 2007 Share Posted February 5, 2007 Hi guys Hope every body is fine... i have a litttle problem... Code: else: $dbcnx = dbConnect('db'); $required_fields = array( 'icnumber','acccode','username', 'email', 'hp'); foreach ($required_fields as $field) { if (!isset($_POST[$field]) || empty($_POST[$field])) { error("One or more required fields were left blank. \\n Please fill them in and try again."); } else { $cleaned_for_sql[$field] = mysql_real_escape_string($_POST[$field]); } } $sql = "SELECT COUNT(*) FROM loguser WHERE username = '" . $cleaned_for_sql['username'] . "'"; $sql_result = mysql_query($sql); if (mysql_result($sql_result, 0) > 0) { error("This username is already in use.\\n Please choose another."); } $sql = "SELECT icnumber,acccode,active FROM accdtl WHERE icnumber = '" . $cleaned_for_sql['icnumber'] . "' acccode = '" . $cleaned_for_sql['acccode'] . "' AND active == 'X'"; $sql_result = mysql_query($sql); if (mysql_result($sql_result,0,0) > 0) { error("This access code is used.\\n Please contact for another."); } $email = $cleaned_for_sql['email']; $password = substr(md5(time()),0,6); $ic = "X"; $sql = "UPDATE `loguser` SET "; $sql .= "`password` = PASSWORD('" . $password . "'), "; $sql .= "`email` = ('" . $email . "'), "; $sql .= "`hp` = '" . $cleaned_for_sql['hp'] . "', "; $sql .= "`icactive` = '" . $ic . "', "; $sql .= "`username` = '" . $cleaned_for_sql['username'] . "' "; $sql .= "WHERE `icnumber` = '" . $cleaned_for_sql['icnumber'] . "' "; $sql .= "AND `acccode` = '" . $cleaned_for_sql['acccode'] . "' "; $sql_result = mysql_query($sql) or error("Error executing query [$sql]: " . mysql_error()); if (mysql_affected_rows($dbcnx) == 0) { error("Your IC number and Access Code do not match to database data. \\n Please try again."); } $sql1 = "UPDATE `accdtl` SET "; $sql1 .= "`active` = '" . $ic . "' "; $sql1 .= "WHERE `icnumber` = '" . $cleaned_for_sql['icnumber'] . "' "; $sql1 .= "AND `acccode` = '" . $cleaned_for_sql['acccode'] . "' "; $sql_result = mysql_query($sql1) or error("Error executing query [$sql1]: " . mysql_error()); if (trim($email)=='' || !eregi("^[a-z0-9_]+\.[a-z0-9_]+@[a-z0-9\-]+\.+[a-z0-9\-\.]+$",$email)) If we look the code above its fine and working but one error it has that is here in the code: $sql = "SELECT icnumber,acccode,active FROM accdtl WHERE icnumber = '" . $cleaned_for_sql['icnumber'] . "' acccode = '" . $cleaned_for_sql['acccode'] . "' AND active == 'X'"; $sql_result = mysql_query($sql); if (mysql_result($sql_result,0,0) > 0) { error("This access code is used.\\n Please contact for another."); } here i want that the sql query check the active field if is 'X' then error to user but if not then proced to next step(means query or script). How to perform a check on this query.. if (mysql_result($sql_result,0,0) > 0) specailly here... Many thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/37104-if-active-x-then-error-to-user/ Share on other sites More sharing options...
KrisNz Posted February 5, 2007 Share Posted February 5, 2007 replace if (mysql_result($sql_result,0,0) > 0) with if(mysql_num_rows($sql_result) > 0) You're also missing an 'AND' in the sql statement before 'acccode ' Link to comment https://forums.phpfreaks.com/topic/37104-if-active-x-then-error-to-user/#findComment-177218 Share on other sites More sharing options...
mmarif4u Posted February 5, 2007 Author Share Posted February 5, 2007 Thanks KrisNz for ur reply... I change the code as u mention in ur post. but now this error: Warning: Wrong parameter count for mysql_result() in E:\Arif\Doc Drive\WWW\reg1\user.php on line 120 Link to comment https://forums.phpfreaks.com/topic/37104-if-active-x-then-error-to-user/#findComment-177220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.