SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If active = 'X' then error to user

    Hi guys Hope every body is fine...

    i have a litttle problem...

    Code:
    PHP 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_result0) > 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:

    PHP 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..
    Code:
    if (mysql_result($sql_result,0,0) > 0)
    specailly here...

    Many thanks in advance..

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As i found there you have missed one AND operator in your SQL. So please try this query now:
    PHP Code:
    $sql "SELECT icnumber,acccode,active FROM accdtl WHERE icnumber = '" $cleaned_for_sql['icnumber'] . "' AND 
    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.");

    And why are you sing double equal to operator in active=='X'?

  3. #3
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I change the code as u write...

    But the error which say:

    Unable to jump to row 0 on MYSQL result index 6.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh so your error is in :
    PHP Code:
    if (mysql_result($sql_result,0,0) > 0) {
      
    error("This access code is used.\\n Please contact for another.");

    ???

    Write like this:
    PHP Code:
    if (mysql_result($sql_result,0,"active") == "X") {
      
    error("This access code is used.\\n Please contact for another.");

    Or simply you can use like this:
    PHP Code:
    if (mysql_num_rows($sql_result) >= 1) {
      
    error("This access code is used.\\n Please contact for another.");

    Does this help?

  5. #5
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Rajug,
    Its working fine...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •