Jump to content

Extending if statement


Xtremer360

Recommended Posts

This scripts works fine however I want to extend the if check against the database so that somehow instead of just telling the user that there was a problem on the on the form page I can tell them which was the actual problem so how could I extend it so that I can tell the user if it was the contentpage or the shortname that was the problem.

 

if (isset($_POST['editcontentpage'])) {
    
    $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']);
    $shortname = mysqli_real_escape_string($dbc, $_POST['shortname']);
    $contentcode = mysqli_real_escape_string($dbc, $_POST['contentcode']);
    $linebreak = mysqli_real_escape_string($dbc, $_POST['linebreak']);
    $backlink = mysqli_real_escape_string($dbc, $_POST['backlink']);
    $showheading = mysqli_real_escape_string($dbc, $_POST['showheading']);
    $visible = mysqli_real_escape_string($dbc, $_POST['visible']);
    $template = (int)$_POST['template'];
    $contentpageID = (int)$_POST['contentpageID'];

    $query = "SELECT * FROM `contentpages` WHERE `contentpage` = '".$contentpage."' OR `shortname` = '".$shortname."'";
    $result = mysqli_query ( $dbc, $query ); // Run The Query
    $rows = mysqli_num_rows($result);
    
    if ($rows == 0) {
        
        $query = "UPDATE `contentpages` 
            SET `contentpage` = '".$contentpage."', `shortname`='".$shortname."', `contentcode`='".$contentcode."', `linebreaks`='".$linebreak."', `backlink`='".$backlink."', `showheading`='".$showheading."', `visible`='".$visible."', `template_id`='".$template."' WHERE `id` = '".$contentpageID."'";  
    
        mysqli_query($dbc,$query);
        
        echo "good";
        
    } else {
        
        echo "bad";
        
    }
}

Link to comment
Share on other sites

well just make a check before you insert it.

 if (isset($_POST['submit'])){
      //shortname
      if (emtpy($_POST['shortname'])){
                 $errormessage .= 'you forgot a shortname<br />'; // using .= so more message can be shown.
                  $output ='bad';
      }else{
               $output = 'good';
        }
    //contentpage
    if (emtpy($_POST['contentpage'])){// any check can be done here, even regex
                 $errormessage .= 'you forgot  content<br />'; // using .= so more message can be shown.
                  $output ='bad';
      }else{
               $output = 'good';
        }

}


if (isset($_POST['editcontentpage']) && $output == 'good') { //check wether stuff is good or bad
    
    $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']);
    $shortname = mysqli_real_escape_string($dbc, $_POST['shortname']);
    $contentcode = mysqli_real_escape_string($dbc, $_POST['contentcode']);
    $linebreak = mysqli_real_escape_string($dbc, $_POST['linebreak']);
    $backlink = mysqli_real_escape_string($dbc, $_POST['backlink']);
    $showheading = mysqli_real_escape_string($dbc, $_POST['showheading']);
    $visible = mysqli_real_escape_string($dbc, $_POST['visible']);
    $template = (int)$_POST['template'];
    $contentpageID = (int)$_POST['contentpageID'];




    $query = "SELECT * FROM `contentpages` WHERE `contentpage` = '".$contentpage."' OR `shortname` = '".$shortname."'";
    $result = mysqli_query ( $dbc, $query ); // Run The Query
    $rows = mysqli_num_rows($result);
    
    if ($rows == 0) {
        
        $query = "UPDATE `contentpages` 
            SET `contentpage` = '".$contentpage."', `shortname`='".$shortname."', `contentcode`='".$contentcode."', `linebreaks`='".$linebreak."', `backlink`='".$backlink."', `showheading`='".$showheading."', `visible`='".$visible."', `template_id`='".$template."' WHERE `id` = '".$contentpageID."'";  
    
        mysqli_query($dbc,$query);
        
        echo "good";
        
    } else {
        
        echo "bad";
        echo $errormessage; // show the error messages
        
    }
}

Link to comment
Share on other sites

I have no idea what you really want.

Are you planning to first insert stuff in a database and than again select from that database to see if stuff is as you expect it? if that is the case i would not recommend that. I would make a check if things are as you expect them before you insert them in to a database.

Link to comment
Share on other sites

if ($row['contentpage'] == $contentpage) echo 'bad1';
        if ($row['shortname'] == $shortname) echo 'bad2';
       if (($row['contentpage'] == $contentpage) && ($row['shortname'] == $shortname)) echo 'bad3';  

 

When it gets down to the final if statement I keep getting bad1bad2bad3 on the clientside how can I get it to return ONLY bad3 if the last if part is true?

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.