Jump to content

wolfcry

Members
  • Posts

    106
  • Joined

  • Last visited

Everything posted by wolfcry

  1. <?php echo '<select name="myselectionbox">'; for($i = 1; $i <= 5; $i++){ echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</selection>'; ?> I suppose so, but it's just your average dynamic selection box. Also, just an FYI, the form is posting back to same page using POST method.
  2. Hey all, Another question for you. How does one make it so that the selections (choices) a user selects for dynamic selection boxes remain after the form is posted, which does post back to itself? I've tried JavaScript using the "name" of the selection box as the id but I must be doing something wrong because it's not working..as usual lol. The values in the selection boxes are populated dynamically so I'm not sure how to do this. Thank you.
  3. Hey all, I could have sworn I did it before but looking through my repository, as well as searching online, I cannot find an answer to this. Basically, what I'm doing is adding calculations the user inputs, however, if the calculation comes up as "0" (i.e. 4 + 4 - 8 = 0 etc.), it not only kills the script (believing it to be FALSE), but it doesn't retain as the numeric value of "0" (even though I know, mathematically zero has no numeric value). I've tried a few things, including modulus but it's not clicking for some reason. Also, I forgot to add this tidbit in the original post, but I am using eval() to perform the calculations if that helps any.
  4. Yes, you can always set the php file in a secured directory and not allow access via .htaccess.
  5. Nice, I got it to work finally. Everything needs to be stored in an array and extracted through that it seems. At least that's the only way I got it to work properly. Here's the final solution in case anyone is curious or hits this wall in the future. If you know of a way that does not require this method, please let me know. My Dynamic function that connects and queries the database: <?php function DB_Query(){ $databasefields = array(); $results = array(); @$Mconn = new mysqli(DBHOST, DBUSER, DBPWRD, DBNAME); if (!@mysqli_connect(DBHOST, DBUSER, DBPWRD, DBNAME)){ die(DBERROR); } $query = "SELECT `results`, `Success`, `Failure`, `Counter`, `Grades`, `Classes`, `Special_Id`, `SpecialCondition` FROM `Courses` INNER JOIN `Students` ON `id` = `Students_Id` JOIN `Conditions` ON `id` = `Special_Id`"; $stmt = $Mconn->prepare($query); $stmt->execute(); $meta = $stmt->result_metadata(); while($field = $meta->fetch_field()){ $databasefields[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $databasefields); while($stmt->fetch()){ $queried = array(); foreach($row as $key => $vector){ $queried[$key] = $vector; } $results[] = $queried; } return $results; } $results = DB_Query(); // placed in include file so I don't have to keep calling it on each page a query is needed. ?> And here's the code I use to actually display the data singly or in multiple blocks (YAY! lol). Just change the field name to correspond to yours. The function is dynamic and doesn't require you to hard-code any binding results so you can fetch as many fields as desired. <?php foreach($results as $row){ echo $row['grades'].'<br />'; } Hope that helps those who hit the same wall as I did
  6. Ok, so I've been trying everything I can think of, including using $stmt->close(); in the corresponding code blocks and nothing is working. There has to be a way to display multiple queried results on the same page using Prepared Statements.
  7. I hope you don't mind, but I sent you a PM. Hopefully that will help you out. Right now, I don't have the time to look into your script completely but I'll check it out once I'm free enough to do so.
  8. Seems you got quite a bit of repetitive code making your work more hard. Why not just use isset() and empty() and evaluate once to see if the submit button has been and the username and password fields aren't empty. That way if submit has NOT been set, then it will show the username and password fields to log in, if it HAS been set, it will evaluate to see if both username and password fields aren't empty and go from there. It'll also be easier to add error messages if submit was set but either the password / username are empty or wrong. Less code to write. here's an example. // Place your SQL query in a different file and call it INTO this page using include_once('url/to/mysqlquery.php') at the very top of your page just below the <?php tag. //Place this at the top of your page or beginning of your PHP form and hide $_POST globals inside to to kill any undefined errors. if(isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; if($username == $dbusername && $password == $dbpassword){ header ('url.to.your.page.php'); } else { echo "error message here with form HTML code here."; } } else { echo "form html code here and have form resubmit to self (action = "same_page_url.php")"; } Something like that will be much, much easier to write and easier to maintain.
  9. Not sure where that would be coming from unless you have more code I can't see because what I posted is only 35 lines long and that's with spaces between the <?php and ?> tags
  10. K, I see what your problem is. Here's the fixed code with notes on where I fixed it. if (!($username == " " && $password == " ")){ if ($username == $dbusername && $password == $dbpassword) { header( 'Location: http://adobetuts.netai.net/log in success.html' ) ; } } else { <===== REMOVED EXTRA } and echo statement. echo ('<div id="username"> <form action="" method="post"/> <div id="new"> <font color="red"> Wrong Username Or Password, Please Try Again </font> </div> <table><tr><td> <img src="imgs/Log In/username.png" alt=""/> </td><td> <input type="text" size="30" name="username" style="background-color:transparent;" /> </td></tr></table> <table><tr><td> <img src="imgs/Log In/password.png" alt=""/> </td><td> <input type="password" name="password" size="30" /> </td></tr></table> <form id="submitb" action=""> <input type="submit" value="Log in" /> </form> <p class="register">Not yet a member? <a href="Form.html">Register Here</a>, its Free!</p> </div>'); } UPDATE: Oops, I saw that I forgot the elses' {} braces (which I use, not completely required but keeps code nice and encapsulated which I like.)
  11. Lol, you keep beating me to the punch dang it! . Use the code I posted above and you should be fine. You can also use another redirect in that page or have the page refresh itself (which is what I do for long forms keeping all inputted values except for passwords etc.).
  12. Lol, read my previous post above your last one. It explains why. Essentially, you're telling a failed request that it's actually a positive login. Change it to something like echo "Sorry. Incorrect user login details. Please try again."; or whatever you prefer. if (!($username == " " && $password == " ")){ if ($username == $dbusername && $password == $dbpassword) { header( 'Location: http://adobetuts.netai.net/log in success.html' ) ; } else { echo "Login information incorrect. Please try again."; }
  13. I also wanted to point out, that unless the echo statement "You are now logged in, welcome to adobetuts!" is on (or referenced by a session) the page you're redirecting them too, the user won't see it because the code will immediately redirect them away from that page. I'd place that echo statement at the end in an else statement and tell the user they're NOT logged in if their username or password evaluates to false.
  14. This is how it should look. if (!($username == " " && $password == " ")){ if ($username == $dbusername && $password == $dbpassword) { header( 'Location: http://adobetuts.netai.net/log in success.html' ) ; } echo "You Are Now Logged In, Welcome To AdobeTuts!"; }
  15. As I stated in my post above yours, it's because you have one too many curly braces '}'. A dangler that's not encapsulating anything.
  16. what does the error say? From what I see, you have an extra '}' curly brace at the end.
  17. What I'd do is inside the if() here: if (!($username == " " && $password == " ")) I'd place the following if statement. if($username == $db_username && $password == $db_password){ header( 'Location: http://www.yoursite.com/new_page.html' ) ; }
  18. Hi dharmeshpat, Thank you for you your reply, I greatly appreciate it. I'm sorry, but I don't understand what you mean. Are you saying that I need to make multiple query statements (or objects) and use those instead? Shouldn't I be able to use one $stmt object considering all of the information is being stored? Here's how my connection is being set and stored. $query = "SELECT `results`, `Success`, `Failure`, `Counter`, `Grades`, `Classes`, `Special_Id`, `SpecialCondition` FROM `Courses` INNER JOIN `Students` ON `id` = `Students_Id` JOIN `Conditions` ON `id` = `Special_Id`"; $stmt = $Mconn->prepare($query); $stmt->bind_result($results, $success, $failed, $counter, $grades, $classes, $specialId, $specialcondition); $stmt->execute(); $stmt->store_result(); Are you saying I need to do the following? $query = "SELECT `results`, `Success`, `Failure`, `Counter`, `Grades`, `Classes`, `Special_Id`, `SpecialCondition` FROM `Courses` INNER JOIN `Students` ON `id` = `Students_Id` JOIN `Conditions` ON `id` = `Special_Id`"; $stmt = $Mconn->prepare($query); $stmt->bind_result($results, $success, $failed, $counter, $grades, $classes, $specialId, $specialcondition); $secondobject = $Mconn->prepare($query); $secondobject->bind_result($results, $success, $failed, $counter, $grades, $classes, $specialId, $specialcondition); $stmt->execute(); $secondobject->execute(); $stmt->store_result(); $secondobject->store_result(); That looks odd to me but then again, I'm just learning how to use Prepared Statements.
  19. Can you post some of your code so we can take a look? Does it have some sort of counter that loops (which I'm assuming it does) until reaching a maximum limit?
  20. Hey all, First off, if this is in the wrong section I apologize. I wasn't sure if it should be here or the mySQL section. What's going on is, I'm in the process of learning the Prepared Statement way of doing things and am changing / updating my code to reflect the changes. Everything was going fine until I attempted to do what I could do using old MySQL methods and that is display the queried results on the same page. I can place a query and display the results as they should be displayed if I only use one block of code. However, if I try to do any additional queries on the same page, they get killed and do not display anything even though I know the query is fine because I can test the exact same syntax below one a different page and it works. Here's a code snippet for an example: Code: <table> <tr> <td> // The below code will display a selection box containing various strings such as "hello world", "great to be here", "Wowserz", "this is mind blowing" etc. that are stored in the database. <?php echo "<select = \"SpecialConditions\">"; if($stmt->num_rows == NULL){ echo "No results found."; }else{ while($stmt->fetch()){ echo "<option value=\"$specialId\">$specialcondition</option>"; } } echo "</select>"; ?> </td> <td> // If I place another fetch query below the above fetch() query, this one will not show up. This one is supposed to display values 1 - 20 that have been stored in the DB. <?php echo "<select = \"NumberSets\">"; if($stmt->num_rows == NULL){ echo "No results found."; }else{ while($stmt->fetch()){ echo "<option value=\"".$numbers."\">".$numbers."</option>"; } } echo "</select>"; ?> </td> </tr> </table> What am I doing wrong with this? When I use regular SQL queries I can display multiple results on the same page. The results are being pulled from two separate joined tables but I don't think that's the issue.
  21. Hey Kicken, Ah, yes I was. I'm pulling the symbols from a db table using a reference id so I could use integer triggers in the actual script rather than hard coding everything. I guess what I'll do now is store the symbols in an array and pull them out based on index value, which of course will be the reference id. I'll just have to change the code up a bit. Thanks everyone for your help, I really appreciated it and all is working as it should now.
  22. Sorry, I must have quick copied and didn't get the whole thing. No, it's there thank goodness
  23. Sorry, I thought I posted the error, my bad. It is: and I'm calling the function like so: if (($ModType != 1 && $ModValue != 0) || ($OptModType != 1 && $OptModValue != 0)) { echo ModifyCalc($sum, $ModType, $ModValue, $OptModType, $OptModValue); }
×
×
  • 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.