Xtremer360 Posted January 15, 2011 Share Posted January 15, 2011 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 https://forums.phpfreaks.com/topic/224539-extending-if-statement/ Share on other sites More sharing options...
fortnox007 Posted January 15, 2011 Share Posted January 15, 2011 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 https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159851 Share on other sites More sharing options...
Xtremer360 Posted January 15, 2011 Author Share Posted January 15, 2011 I came up with this but it's giving me back two responses. http://pastebin.com/MVLEL14D Link to comment https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159859 Share on other sites More sharing options...
fortnox007 Posted January 15, 2011 Share Posted January 15, 2011 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 https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159865 Share on other sites More sharing options...
Xtremer360 Posted January 15, 2011 Author Share Posted January 15, 2011 Well the idea behind this was to just able to notify the user back with what the problem was if there was a problem. And if there wasn't then insert into the database the users input. Link to comment https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159868 Share on other sites More sharing options...
fortnox007 Posted January 15, 2011 Share Posted January 15, 2011 I could be totally wrong, but wouldn't it make sense (just to repeat myself) to do the 'Wrong' check before you insert (like normally is the case with validation)? Just like i showed in the very first example? Link to comment https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159874 Share on other sites More sharing options...
Xtremer360 Posted January 15, 2011 Author Share Posted January 15, 2011 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 https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159980 Share on other sites More sharing options...
Xtremer360 Posted January 15, 2011 Author Share Posted January 15, 2011 Anyone see my issue with this? Link to comment https://forums.phpfreaks.com/topic/224539-extending-if-statement/#findComment-1159993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.