Jump to content

Scooby08

Members
  • Posts

    244
  • Joined

  • Last visited

Everything posted by Scooby08

  1. Trying to add a class to the links in this printf.. I need to get this: <?=($current=='%s')?'class="current"':'';?> into this <?php printf('<a href="%s?letter=%s">%s</a>', $PHP_SELF, chr($i), chr($i)); ?> This is the closest I can get and it is still a bit off <?php printf('<a href="%s?letter=%s" ('.$current.'==%s)?'class="current"':''>%s</a>', $PHP_SELF, chr($i), chr($i), chr($i)); ?>
  2. Ha!! It was the double == This code must be for an older version of php possibly?? Anyways, Thanks you guys for the input!!
  3. I found a simple snipplet online for a database A to Z search by name and am having troubles understanding what's going on with the do/while section.. Here is the code I'm using: <?php $sort = $_REQUEST['letter']; if($sort = "") { $query = "SELECT * FROM dw_customers ORDER BY customer_bride ASC" ; } else { $query = "SELECT * FROM dw_customers WHERE customer_bride LIKE '$sort%' ORDER BY customer_bride ASC" ; } $result = mysql_query($query) or die(mysql_error()); for ($i = 65; $i < 91; $i++) { printf('<a href = "%s?letter=%s">%s</a> | ', $PHP_SELF, chr($i), chr($i)); } echo "</p>" ; if (mysql_num_rows($result) > 0) { do { echo "<p>" .$row['customer_bride']. "</p>" ; } while ($row = mysql_fetch_assoc($result)); } else { echo "<p>No customer found.</p>" ; } ?> Everything seems to work fine except for when I click a letter that is not in my database, I cannot seem to get to the else { echo "<p>No customer found.</p>"; } Can somebody help me to understand why I cannot get that to echo??
  4. Here's what I got working properly.. <?php $item_id = array_keys($_POST['item_qty_aai']); $item_descr_aai = $_POST['item_descr_aai']; $item_qty_aai = array_values($_POST['item_qty_aai']); $item_price_aai = $_POST['item_price_aai']; for($i = 0; $i < count($item_descr_aai); $i++){ $query_order_items_aai = "INSERT INTO dw_order_items (item_id, item_descr, item_qty, item_price) "; $query_order_items_aai .= "VALUES ('{$item_id[$i]}','{$item_descr_aai[$i]}','{$item_qty_aai[$i]}','{$item_price_aai[$i]}')"; mysql_query($query_order_items_aai) or die(mysql_error()); } ?>
  5. I'm sorry.. I don't understand how that value gets entered into the database under item_id field?? $query_order_items_aai = "INSERT INTO dw_order_items (item_id, item_descr, item_qty, item_price) "; $query_order_items_aai .= "VALUES ('{$item_descr_aai[$i]}','".$item_qty_aai['add_item_'.($i+1)]."','{$item_price_aai[$i]}')"; see here: INSERT INTO dw_order_items (item_id it needs to be that value.. Is the way you just told me able to do that and Im just missing the point? It looks as if this ['add_item_'.($i+1)] is supposed to equal add_item_1 and just add 1 for each loop.. The thing is that this form is created as the user clicks to add an item and I already add 1 to it then..
  6. I ran that code and here is what it outputs: Array ( [add_item_1] => 3 [add_item_2] => 4 [add_item_3] => 5 ) I added 3 items then submitted
  7. Ahh nice!! It's echoing all info but one.. the qty.. But I forgot to mention something about that one.. In the field input name I also have a value assigned to the array name.. Here is what the qty input is like: <input type="text" name="qty[item_1]" value="" /> if the user wants to add another item then it would be like so (along with the rest of the form): <input type="text" name="qty[item_1]" value="" /> <input type="text" name="qty[item_2]" value="" /> item_1 and item_2 is what I'm using as the id for that specific item.. How do I get that into this equation?? I need to enter item_1, item_2 into the database as well like so.. <?php $query_order_items_aai = "INSERT INTO dw_order_items (item_id, item_descr, item_qty, item_price) "; $query_order_items_aai .= "VALUES ('{$item_id[$i]}','{$item_descr_aai[$i]}','{$item_qty_aai[$i]}','{$item_price_aai[$i]}')"; ?>
  8. Thanks for the replies guys.. I tried ProjectFear's solution and came up with this.. <?php $item_descr_aai = $_POST['item_descr_aai']; $item_qty_aai = $_POST['item_qty_aai']; $item_price_aai = $_POST['item_price_aai']; for($i = 0; $i < count($item_descr_aai); $i++){ $query_order_items_aai = "INSERT INTO dw_order_items (item_descr, item_qty, item_price) "; $query_order_items_aai .= "VALUES ($item_descr_aai, '$item_qty_aai', '$item_price_aai') "; echo $query_order_items_aai; } ?> This is what it echo's: And for Xurion's solution how would that foreach collect all the info and place it in order in the database?
  9. Say I have a form like so: <fieldset> <label>Description</label><br /> <input type="text" name="description[]" value="" /><br /> <label>Qty</label><br /> <input type="text" name="qty[]" value="" /><br /> <label>Price</label><br /> <input type="text" name="price[]" value="" /><br /> </fieldset> The user can click to add as many new items as they wish.. How do I collect all that information so that each item is inserted into a new row in the database?? It's simple to do this when only one item is added at a time, but in this case they can add multiple items at once and that's where I'm stumped.. Can anybody point me in the right direction??
  10. It definitely works.. I was just curios if anybody saw any problems with doing it like that.. I'm just working on my first database project so I'm just trying to take in as much input as possible from all you pro's out there.. haha Thanks a bunch!!
  11. Hey thanks.. I think I found a solution.. Do you see any problems with this?? <?php $query = "SELECT * "; $query .= "FROM dw_company "; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $hello = htmlentities($row['hello']); } echo $hello; ?>
  12. here is my select.. <?php $query = "SELECT * "; $query .= "FROM dw_company "; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $hello = $row['hello']; } echo $hello; ?> should be selecting and displaying this text: hello "Kyle" This is what I see in my field: hello \
  13. I know this is pretty elementary, but I cannot find a straight answer as to how to retrieve data from that database that has double quotes.. This line is in my table: hello "Kyle" I can insert into the database, but cannot retrieve it?? What am I missing??
  14. I have been searching for a last logged in script and have only found scripts that used cookies to do this.. Is there possibly a way to do this without cookies?? Also would you need to set cookies for a remember me feature as well, or is there a way of doing that without cookies? Basically I'm trying to stay away from cookies.. But if cookies are the only way to go then alrighty then.. Actually what do you guys think about the remember me feature on a login form?? Is it worth having?? Thanks..
  15. because when they fill out the form they get variables to compare.. Anyways, I think I got it good enough.. I just ran another query for the error if's and it seems to be working..
  16. This section doesnt read $user_name and $user_password.. Maybe because it's inside the if statement? Not sure, but I thought if I set $user_name = "admin"; at the top of the script, I would then be able to use it throughout.. <?php //echo $user_name; // doesnt even echo the username from the database while loop above //$user_name = "admin"; // works if I just set it manually //$user_password = "admin"; //validate your input if ($_POST['txt_user_name'] != "" && $_POST['txt_user_name'] != $user_name) { ?>
  17. I found a little login code snipplet online and was playing around with it a bit.. I'm adding an error detection array to it.. The error detection works perfectly. The problem I'm having is with matching the username and passwords from the database in the error if statements.. Here is the code: <?php // we must never forget to start the session session_start(); include 'include/config.inc.php'; if (isset($_POST['txt_user_name']) && isset($_POST['txt_user_password'])) { include 'include/database.inc.php'; // post form variables $txt_user_name = $_POST['txt_user_name']; $txt_user_password = $_POST['txt_user_password']; // check if the user id and password combination exist in database $query = "SELECT user_name "; $query .= "FROM dw_users "; $query .= "WHERE user_name = '$txt_user_name' "; $query .= "AND user_password = PASSWORD('$txt_user_password') "; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $user_name = $row['user_name']; $user_password = $row['user_password']; } if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: '.SCRIPT_URL.'accounts.php'); exit(); } else { //array & variable declaration $errorarray = array(); //used to store error messages //echo $user_name; // doesnt even echo the username from the database while loop above //$user_name = "admin"; // works if I just set it manually //$user_password = "admin"; //validate your input if ($_POST['txt_user_name'] != "" && $_POST['txt_user_name'] != $user_name) { // using post for same page and request for page to page.. Just testing $_SESSION['errorstate'] = 1; $errorarray[] = "ERROR: Invalid username!"; } elseif ($_POST['txt_user_name'] == "") { $_SESSION['errorstate'] = 1; $errorarray[] = "ERROR: The username field is empty!"; } else { // display nothing if correct } if ($_POST['txt_user_password'] != "" && $_POST['txt_user_password'] != $user_password) { $_SESSION['errorstate'] = 1; $errorarray[] = "ERROR: Invalid password!"; } elseif ($_POST['txt_user_password'] == "") { $_SESSION['errorstate'] = 1; $errorarray[] = "ERROR: The password field is empty!"; } else { // display nothing if correct } //check for errors if ($_SESSION['errorstate'] == 1) { // if error $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session } } // Close databse connection mysql_close(); } ?> The query pulls out the info just fine, but I can't figure out why it won't let me use $user_name, and $user_password in the if statements..
  18. it sure is because thats the same line its on in my file, and if I take it out the page works fine.. I have 740 lines in that doc. This is really funky to me.. Everything is specified correctly, but yet no go.. Well I just tried your unset($_SESSION['errorstate']); idea and that seems to work now.. I guess they just weren't clearing.. Thanks for all who helped..
  19. Thank you for all your patience, but that does not seem to fix it.. This code below works, but is still displaying that error on page enter.. I have added an echo of the errorstate just before the code to see what is running through the if statement and this doesnt make sense to me... <?php echo $_SESSION['errorstate']; // displays nothing on page enter, 0 if valid, and 1 if error if ($_SESSION['errorstate'] == 0 || $_SESSION['errorstate'] == 1) { //check for the sessions and if there is an error if( $_SESSION['errorstate'] < 1 ) $class = 'fade_valid'; else $class = 'fade_error'; echo "<div id='message' class='$class'>"; foreach($_SESSION['errormessage'] as $key => $value){ //print the errors echo $value.'<br />'; } echo "</div>"; //clear the errors $_SESSION['errorstate'] = ""; $_SESSION['errormessage'] = ""; } ?> If my echo statement is correct, then the if statement shouldn't process until there is a value?? correct??
  20. The first way seems to work, but the session seems to store the errorstate, and when entering that page there is an error displayed immediately.. It seems to say the errorstate is set immediately.. Otherwise it works perfectly! Warning: Invalid argument supplied for foreach() in /home/content/.../add.php on line 231
  21. I did it exactly like you said and it validates for errors, but when there is success it displays nothing at all This is the process if statement: <?php //check for errors if ($_SESSION['errorstate'] == 1) { // if error $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session header("Location: ".SCRIPT_ADD.""); } elseif ($_SESSION['errorstate'] == 0) { // if no error $_SESSION['errorstate'] = 0; $errorarray[] = "You have successfully added a new customer!"; $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session header("Location: ".SCRIPT_ADD.""); } ?> And did the first way.. Why would it not recognize the success??
  22. Heh.. Im still not getting this to work.. Here is what I have tried: <?php // I left the errorstate at 0 if success in process.php if(!empty($_SESSION['errorstate'])) { //check for the sessions and if there is an error if( $_SESSION['errorstate'] < 1 ) $class = 'fade_valid'; else $class = 'fade_error'; echo "<div id='message' class='$class'>"; foreach($_SESSION['errormessage'] as $key => $value){ //print the errors echo $value.'<br />'; } echo "</div>"; //clear the errors $_SESSION['errorstate'] = ""; $_SESSION['errormessage'] = ""; } ?> and also this: <?php if((isset($_SESSION['errorstate'])) && ($_SESSION['errorstate'] == 1)) { //check for the sessions and if there is an error echo "<div id='message' class='fade_error'>"; foreach($_SESSION['errormessage'] as $key => $value){ //print the errors echo $value.'<br />'; } echo "</div>"; } elseif(!empty($_SESSION['errorstate'])) { //check for the sessions and if there is an error echo "<div id='message' class='fade_valid'>"; foreach($_SESSION['errormessage'] as $key => $value){ //print the errors echo $value.'<br />'; } echo "</div>"; //clear the errors $_SESSION['errorstate'] = ""; $_SESSION['errormessage'] = ""; } ?>
  23. yes it does.. This header("Location: ".SCRIPT_ADD.""); == header("Location: index.php");
  24. I have a short form error checking code that I need to make an addition to, but nothing I have done is working.. Maybe somebody here knows an alternative.. Here is process.php <?php //array & variable declaration $errorarray = array(); //used to store error messages //validate your input if (trim($_REQUEST['firstname']) == "" ) { $_SESSION['errorstate'] = 1; $errorarray[] = "Please enter firstname!"; } if (trim($_REQUEST['lastname']) == "" ) { $_SESSION['errorstate'] = 1; $errorarray[] = "Please enter lastname !"; } //check for errors if ($_SESSION['errorstate'] == 1) { // if error $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session header("Location: ".SCRIPT_ADD.""); } elseif ($_SESSION['errorstate'] == 0) { // if no error $_SESSION['errorstate'] = 1; $errorarray[] = "You have successfully added a new customer!"; $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session header("Location: ".SCRIPT_ADD.""); } ?> Then next I have the code back on the form page: <?php if((isset($_SESSION['errorstate'])) && ($_SESSION['errorstate'] == 1)) { //check for the sessions and if there is an error echo "<div id='message' class='fade_error'>"; foreach($_SESSION['errormessage'] as $key => $value){ //print the errors echo $value.'<br />'; } echo "</div>"; //clear the errors $_SESSION['errorstate'] = ""; $_SESSION['errormessage'] = ""; } ?> Im trying to figure out how to toggle the class on this line from this: echo "<div id='message' class='fade_error'>"; // is error to this: echo "<div id='message' class='fade_valid'>"; // is no error What would I need to do here?
  25. Now I'm trying to add an if success message.. Here's what I have, but I'm not getting it.. <?php //check for errors if ($_SESSION['errorstate'] == 1) { // if error $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session //header('location: page.php'); //redirect accordingly header("Location: ".SCRIPT_ADD.""); } elseif ($_SESSION['errorstate'] == 0) { // if no error $errorarray[] = "You have successfully added a new customer!"; $_SESSION['errormessage'] = $errorarray; //store the errorarray in a session //header('location: page.php'); //redirect accordingly header("Location: ".SCRIPT_ADD.""); } ?>
×
×
  • 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.