kenrbnsn Posted June 14, 2010 Share Posted June 14, 2010 This is why you shouldn't double post the same problem. I'm working on this problem and so far I've determined that you if/elseif blocks are wrong. When I figure out why, I will post my conclusions. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1071701 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 Alright, thank you. I'll stop bumping this thread now, as it's just getting annoying. Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1071717 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2010 Share Posted June 14, 2010 Is the following an accurate sequence of events (because it is simply impossible to design and write code or troubleshoot code if you have not defined what it is supposed to accomplish) - 1) $_GET['id'] is first received from the index.php page where a review is selected to be edited (and apparently a passcode is generated, saved in the corresponding table row, and displayed so that it can be entered on this page (edit.php.)) 2) This page (edit.php) displays a form to input the passcode (the id is passed through as a hidden field.) 3) When the passcode form is submitted, if the passcode matches the value in the table for the passed id, the edit form will be displayed. The id and passcode are passed through as hidden fields. 4) When the edit form is submitted, the data is validated and the the correct row (using the passed id and passcode) will be updated. And I recommend rewriting your logic so that it contains a section of code to perform each of those specific tasks (including checking which submit button has been pressed.) Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1071719 Share on other sites More sharing options...
mrMarcus Posted June 14, 2010 Share Posted June 14, 2010 It just appears that your logic is out of whack. <?php if (!$design2 || !$designt2 || !$grammar || !$grammart2 || !$layout2 || !$layoutt2 || !$moderation2 || !$moderationt2 || !$activity2 || !$activityt2 || !$overall2 || !$overallt2) { echo "<div id='signuptop'>Success</div><div id='signup'>You have successfully edited the review!</div>"; } elseif($passcode==$dpasscode) { To get a success message, any of those variables must NOT be true/set? Else the passcode's must match? Just think about your logic. Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1071872 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2010 Share Posted June 14, 2010 For some logic that does do what you seem to be attempting, read this - <html> <head> <title>Review Tracks</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <center> <div class="holder"> <?php //connect to database mysql_connect("$mysql_host","$mysql_user","$mysql_password"); mysql_select_db("$mysql_database"); $id = isset($_GET['id']) ? $_GET['id'] : ''; // get the actual value or a default value // check for an id if(empty($id)){ // there is no id echo '<div id="signuptop">Error</div><div id="signup">Sorry, you must select a review to edit. Go back and select a review! <a href="index.php">Home</a></div>'; } else { // an id has been supplied (you would probably want to do additional validation here...) //passcode processing code $errors = array(); if(!empty($_GET['passcode'])){ // not empty, validate the length if(strlen($_GET['passcode']) == 6){ // length is correct, do any other validation here... // get the row matching the current $id $id = mysql_real_escape_string($id); $extract = mysql_query("SELECT * FROM reviews WHERE id='$id'"); $row = mysql_fetch_assoc($extract); // check if the passcode matches the table if($_GET['passcode'] != $row['passcode']){ // no match $errors[] = '<div id="signuptop">Error</div><div id="signup">Incorrect pass-code! Please try again!</div>'; } } else { // wrong length $errors[] = 'The entered passcode was not 6 characters'; } } else { // no passcode entered $errors[] = 'No passcode was entered'; } // set the passcode if no validation errors if(empty($errors)){ $passcode = $_GET['passcode']; } // display the form and any errors if(empty($passcode) || !empty($errors)){ if(!empty($errors)){ echo "Please correct the following error(s)-<br />"; foreach($errors as $error){ echo "$error<br />"; } } // output the passcode form echo '<div id="signuptop">Error</div><div id="signup">Please enter in the Pass-code to edit this review:<br/><br/> <form action="" method="GET"> <input type="hidden" name="id" value="'. $id .'"> <input type="text" name="passcode" maxlength="6"> <input type="submit" value="Enter"></form><br/><br/></div>'; } // the 'edit form' form processing code $errors = array(); if(isset($_POST['edit_submit'])){ $design2 = mysql_real_escape_string($_POST['design']); $designt2 = mysql_real_escape_string($_POST['designtext']); $grammar2 = mysql_real_escape_string($_POST['grammar']); $grammart2 = mysql_real_escape_string($_POST['grammartext']); $layout2 = mysql_real_escape_string($_POST['layout']); $layoutt2 = mysql_real_escape_string($_POST['layouttext']); $moderation2 = mysql_real_escape_string($_POST['moderation']); $moderationt2 = mysql_real_escape_string($_POST['moderationtext']); $activity2 = mysql_real_escape_string($_POST['activity']); $activityt2 = mysql_real_escape_string($_POST['activitytext']); $overall2 = mysql_real_escape_string($_POST['overall']); $overallt2 = mysql_real_escape_string($_POST['overalltext']); $ip = $_SERVER['REMOTE_ADDR']; // put your code to validate data and set elements in $errors[] = 'error messages'; ... // process the form data if no validation errors if(empty($errors)){ // put your code to UPDATE the row in the table here... echo "<div id='signuptop'>Success</div><div id='signup'>You have successfully edited the review!</div>"; } } // end of 'edit form' form processing code // display the form and any errors if((!empty($passcode) && !isset($_POST['edit_submit'])) || !empty($errors)){ // the $row data was fetched above when the passcode value was checked against the database $name = $row['name']; $site = $row['url']; $design = $row['design']; $designt = $row['designt']; $grammar = $row['grammar']; $grammart = $row['grammart']; $layout = $row['layout']; $layoutt = $row['layoutt']; $moderation = $row['moderation']; $moderationt = $row['moderationt']; $activity = $row['activity']; $activityt = $row['activityt']; $overall = $row['overall']; $overallt = $row['overallt']; $total = $row['total']; $views = $row['views']; $status = $row['status']; // output any validation errors if(!empty($errors)){ echo "Please correct the following error(s)-<br />"; foreach($errors as $error){ echo "$error<br />"; } } // output the form echo '<div id="signuptop">Edit a Review</div><div id="signup"><form action="'. "?id=$id&passcode=$passcode" .'" method="POST"><br/> Appearance: <select name="design"> <option value="'. $design .'">'. $design .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br/> <textarea name="designtext" cols="30" rows="13" maxlength="450">'. $designt .'</textarea><br/> <br/><br/>Grammar Usage <select name="grammar"> <option value="'. $grammar .'">'. $grammar .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br /> <textarea name="grammartext" cols="30" rows="13" maxlength="450">'. $grammart .'</textarea><br/> <br/><br/>Layout <select name="layout"> <option value="'. $layout .'">'. $layout .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br /> <textarea name="layouttext" cols="30" rows="13" maxlength="450">'. $layoutt .'</textarea><br/> <br/><br/>Moderation <select name="moderation"> <option value="'. $moderation .'">'. $moderation .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br /> <textarea name="moderationtext" cols="30" rows="13" maxlength="450">'. $moderationt .'</textarea><br/> <br/><br/>User Activity <select name="activity"> <option value="'. $activity .'">'. $activity .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br /> <textarea name="activitytext" cols="30" rows="13" maxlength="450">'. $activityt .'</textarea><br/> <br/><br/>Overall Score <select name="overall"> <option value="'. $overall .'">'. $overall .'</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> /10<br /> <textarea name="overalltext" cols="30" rows="13" maxlength="450">'. $overallt .'</textarea><br/> <input type="hidden" name="checker" value="1"> <br/><br/><br/> <input type="submit" name="edit_submit" value="Edit Review"></form></div>'; }// end of edit form code } // end 'there is an id' ?> </div> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1071906 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 Wow, thanks guys. I've learned a lot of stuff now. And your code worked PFMaBiSmAd. I appreciate it a lot! Mark solved....finally Edit: How did you get it to keep the ID and Passcode in the URL? Because on my code, if you submitted the passcode, it would lose the data in the URL. Quote Link to comment https://forums.phpfreaks.com/topic/204538-displaying-the-wrong-message/page/2/#findComment-1072035 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.