Xtremer360 Posted January 12, 2011 Share Posted January 12, 2011 I'm just trying something new out here and wanted to know how it looked AND I'm having a hard time figuring out how to accomplish this with the else statement. Obviously on the else it would mean that there was already a template with the same name existing in the database table so I want the user to be sent back to the original form and I'll implement a jquery dialog box telling the user that there is already an existing template with that name. if (isset($_POST['edittemplate'])) { $templatename = mysqli_real_escape_string($dbc, $_POST['templatename']); $headercode = mysqli_real_escape_string($dbc, $_POST['headercode']); $footercode = mysqli_real_escape_string($dbc, $_POST['footercode']); $templateID = (int)$_POST['templateID']; $query = "SELECT * FROM `templates` WHERE `templatename` = $templatename"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); if ($rows == 0) { $query = "UPDATE `templates` SET `templatename` = '$templatename', `headercode`='".$headercode."', `footercode`='".$footercode."' WHERE `id` = '$templateID'"; mysqli_query($dbc,$query); } else { } } Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/ Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 $query = "SELECT * FROM `templates` WHERE `templatename` = $templatename"; if ($result = mysqli_query ( $dbc, $query )) { if (!mysqli_num_rows($result)) { $query = " UPDATE `templates` SET `templatename` = '$templatename', `headercode`='".$headercode."', `footercode`='".$footercode."' WHERE `id` = '$templateID' "; if (mysqli_query($dbc,$query)) { if (mysqli_affected_rows($dbc)) { // update successful. } else { trigger_error("UPDATE Failed - $query - " . mysqli_error()); } } else { trigger_error("Update Failed - $query - " . mysqli_error()); } } else { // template already exists } } else { trigger_error("SELECT Failed - $query - " . mysqli_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158611 Share on other sites More sharing options...
Xtremer360 Posted January 12, 2011 Author Share Posted January 12, 2011 That's pretty nice however how is it going to denote that it didn't go through so that I can send the user back to the form with a jquery dialog box. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158613 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 That would go where the.... // template already exists comment is. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158639 Share on other sites More sharing options...
Xtremer360 Posted January 12, 2011 Author Share Posted January 12, 2011 WHich didn't answer my original question. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158641 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 You didn't ask any question. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158643 Share on other sites More sharing options...
Xtremer360 Posted January 12, 2011 Author Share Posted January 12, 2011 Okay maybe I didn't phrase it in the form of a question. Obviously on the else it would mean that there was already a template with the same name existing in the database table so I want the user to be sent back to the original form and I'll implement a jquery dialog box telling the user that there is already an existing template with that name. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158645 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 So, redirect the user back to the form with a flag set that will trigger a pop-up. header("Location: http://yourdomain.com/form.php?m=template-exists"); If you need to repopulate the form with the data they have already submitted you would need to store that data in the $_SESSION array before redirecting, then retrieve it again on the form page. As for triggering the pop-up, that's a Javascript question. Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158646 Share on other sites More sharing options...
Xtremer360 Posted January 13, 2011 Author Share Posted January 13, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/224242-else-statement/#findComment-1158663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.