Xtremer360 Posted January 21, 2011 Share Posted January 21, 2011 My problem is that which it shows up as -Select- after the form submission to display the result. It works for the news category but not for the contentpage or application lines. I've alerted both the result and the actual variables of contentpagetext and applicationtext to verify that it had the right text however its still showing -Select- in the actual error display message. The lines I'm having trouble with is this line: elseif ($row['application_id'] == $application) $result = 'bad4'; elseif ($row['contentpage_id'] == $contentpage) $result = 'bad3'; Here is the code in its entirety. <?php error_reporting(E_ALL); // Include the database page require ('../inc/dbconfig.php'); $case = $_GET['case']; ?> <?php switch ($case){ case 'addnew': $menuid = $_POST['menuid']; ?> <script type="text/javascript"> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $('#menuitemform select').change(function(){ $("#itemurl").removeAttr('disabled'); $('#menuitemform select').not(this).val(0); $('#menuitemform select').each(function(){ if($(this).val().length > 0){ $("#itemurl").attr("value",""); } }); }); $("#itemurl").focus(function(){ $('#menuitemform select').val(0); }); var menuid = $("#menuid").val(); var dataString = 'menuid='+ menuid; $.ajax({ type: "POST", url: "processes/menuitem.php", data: dataString, success: function(result) { $("#sortorder").val(result); } }); $("input.submit").click(function() { $('div.message-error').hide(); var itemname = $("input#itemname").val(); if (itemname == "") { $("div.message-error").show(); $("input#itemname").focus(); return false; } var itemurl = $("input#itemurl").val(); var sortorder = $("input#sortorder").val(); if (sortorder == "") { $("div.message-error").show(); $("input#sortorder").focus(); return false; } var contentpage = $("select#contentpage").val(); var newscategory = $("select#newscategory").val(); var application = $("select#application").val(); var menuid = $("input#menuid").val(); if (menuid == "") { $("div.message-error").show(); $("input#menuid").focus(); return false; } var contentpagetext = $("select#contentpage option:selected").text(); var newscategorytext = $("select#newscategory option:selected").text(); var applicationtext = $("select#application option:selected").text(); var dataString = 'itemname=' + itemname + '&itemurl=' + itemurl + '&sortorder=' + sortorder + '&contentpage=' + contentpage + '&newscategory=' + newscategory + '&application=' + application + '&menuid=' + menuid + '&submitmenuitem=True'; alert(applicationtext); $.ajax({ type: "POST", url: "processes/menuitem.php", data: dataString, success: function(result) { if (result == 'good') { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>" + itemname + " saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow"); $(':input','#menuitemform') .not(':submit') .val('') } else if (result == 'bad1') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemname + " already exists in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad2') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemurl + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad3') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + contentpagetext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad4') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + applicationtext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad5') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + newscategorytext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad6') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemname + " and " + itemurl + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad7') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemname + " and " + contentpagetext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad8') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemname + " and " + applicationtext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad9') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + itemname + " and " + newscategorytext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } } }); return false; }); }); </script> <!-- Form --> <form action="#" id="menuitemform" > <fieldset> <legend>Add New Menu Item</legend> <div class="field required"> <label for="itemname">Item Name</label> <input type="text" class="text" name="itemname" id="itemname" title="Item Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field"> <label for="itemurl">Item URL</label> <input type="text" class="text" name="itemurl" id="itemurl" title="Item URL"/> </div> <div class="field required"> <label for="sortorder">Item Order</label> <input type="text" class="text" name="sortorder" id="sortorder" title="Item Order" readonly="readonly"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field"> <label for="contentpage">Content Page</label> <select class="dropdown" name="contentpage" id="contentpage" title="Content Page"> <option value="">- Select -</option> <?php $query = 'SELECT id, contentpage FROM contentpages'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['contentpage']."</option>\r"; } ?> </select> </div> <div class="field"> <label for="newscategory">News Category</label> <select class="dropdown" name="newscategory" id="newscategory" title="News Category"> <option value="">- Select -</option> <?php $query = 'SELECT id, categoryname FROM newscategories'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['categoryname']."</option>\r"; } ?> </select> </div> <div class="field"> <label for="application">Application</label> <select class="dropdown" name="application" id="application" title="Application"> <option value="">- Select -</option> <?php $query = 'SELECT id, applicationname FROM applications'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['applicationname']."</option>\r"; } ?> </select> </div> <input type="hidden" name="menuid" id="menuid" value="<?php echo $menuid; ?>" /> <input type="submit" class="submit" name="submitmenuitem" id="submitmenuitem" title="Submit Menu Item" value="Submit Menu Item"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Menu Item was added to the database.</p> </div> <!-- /Messages --> <?php break; case 'edit': break; default : } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225253-not-displaying-select-text/ Share on other sites More sharing options...
Xtremer360 Posted January 21, 2011 Author Share Posted January 21, 2011 Wow that's odd I can't even edit my own post. These are the lines I'm having trouble with those other two were from a different page. else if (result == 'bad3') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + contentpagetext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } else if (result == 'bad4') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + applicationtext + " is already assigned to an item in the database.</p>"); $("div.message-error").show(); } Quote Link to comment https://forums.phpfreaks.com/topic/225253-not-displaying-select-text/#findComment-1163344 Share on other sites More sharing options...
Xtremer360 Posted January 23, 2011 Author Share Posted January 23, 2011 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/225253-not-displaying-select-text/#findComment-1163781 Share on other sites More sharing options...
Xtremer360 Posted January 23, 2011 Author Share Posted January 23, 2011 After going through the code on my process page I realized what the issue is however this is now a php issue so if someone could move this topic to the php forum I would appreciate it. Thank you. This script works however it needs improved a small bit because for the parts that are bad6-bad9. I have it to where its checking for matches with those two at the same time however its trying to find matches when it occurs in the same row in the database when I really would like it to find any matches period even if they are involved in the same row. if (isset($_POST['submitmenuitem'])) { $menuid = (int) $_POST['menuid']; $itemname = trim($_POST['itemname']); $itemnameSQL = mysqli_real_escape_string($dbc, $itemname); $itemurl = trim($_POST['itemurl']); $itemurlSQL = mysqli_real_escape_string($dbc, $_POST['itemurl']); $sortorder = (int) $_POST['sortorder']; $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']); $newscategory = mysqli_real_escape_string($dbc, $_POST['newscategory']); $application = mysqli_real_escape_string($dbc, $_POST['application']); $query = "SELECT * FROM `menuitems` WHERE (`itemname` = '".$itemnameSQL."')\n"; $query .= (!empty($itemurl)) ? " OR `itemurl` = '".$itemurlSQL."'" : ''; $query .= (!empty($contentpage)) ? " OR `contentpage_id` = '".$contentpage."'" : ''; $query .= (!empty($application)) ? " OR `application_id` = '".$application."'" : ''; $query .= (!empty($newscategory)) ? " OR `newscategory_id` = '".$newscategory."'" : ''; $query .= " AND `menu_id` = '".$menuid."'"; $result = mysqli_query ( $dbc, $query ); // Run The Query if (mysqli_num_rows($result) == 0) { $query = "INSERT INTO `menuitems` (menu_id, itemname, itemurl, sortorder, contentpage_id, newscategory_id, application_id, creator_id, datecreated, enabled) VALUES ('".$menuid."', '".$itemname."', '".$itemurl."', '".$sortorder."', '".$contentpage."', '".$newscategory."', '".$application."', 1, NOW(), 0)"; mysqli_query($dbc, $query); $result = "good"; } else { $row = mysqli_fetch_array($result); if (($row['itemname'] == $itemname) && ($row['newscategory_id'] == $newscategory)) $result = 'bad9'; elseif (($row['itemname'] == $itemname) && ($row['application_id'] == $application)) $result = 'bad8'; elseif (($row['itemname'] == $itemname) && ($row['contentpage_id'] == $contentpage)) $result = 'bad7'; elseif (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl)) $result = 'bad6'; elseif ($row['newscategory_id'] == $newscategory) $result = 'bad5'; elseif ($row['application_id'] == $application) $result = 'bad4'; elseif ($row['contentpage_id'] == $contentpage) $result = 'bad3'; elseif ($row['itemurl'] == $itemurl) $result = 'bad2'; elseif ($row['itemname'] == $itemname) $result = 'bad1'; else $result = 'bad0'; } } Quote Link to comment https://forums.phpfreaks.com/topic/225253-not-displaying-select-text/#findComment-1164086 Share on other sites More sharing options...
Xtremer360 Posted January 25, 2011 Author Share Posted January 25, 2011 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/225253-not-displaying-select-text/#findComment-1164845 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.