Jump to content

elmas156

Members
  • Posts

    276
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    Dallas, TX

elmas156's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Which is better, option 1 or option 2? Option 1: $updated = "n"; if ($v1 == "y") { Do something with $v1; $udpated = "y"; } if ($v2 == "y") { Do something with $v2; $updated = "y" } OR Option 2: if ($v1 == "y" && $v2 == "y") { Do something with $v1 and $v2; $updated = "y"; } elseif ($v1 == "y" && $v2 == "n") { Do something with $v1, but not $v2; $updated = "y"; } elseif ($v1 == "n" && $v2 == "y") { Do something with $v2, but not $v1; $updated = "y"; } elseif ($v1 == "n" && $v2 == "n") { Don't do anything with $v1 or $v2; $updated = "n"; } I've used both methods, and they both work, but I'm not sure which one is the best to use. Does if even really matter? Thanks for your opinion.
  2. Thanks so much! It finally works. I would have been working on this for days. Thanks again!
  3. Hey everyone, I have a page that I created for users to select certain products to reserve. Each product is listed and a form is created using a while loop. For some of the products, the user selects to use it wet or dry using a drop down menu. I also have a javascript function that validates the forms that give the option to select to use the product wet or dry, so that if the user does not select one of these options, a popup will apear prompting them to do so. The problem that I'm having is that ON ALL EXCEPT THE FIRST FORM/PRODUCT PRODUCED FROM THE WHILE LOOP, the form validation produces a popup prompting the user to select the wet or dry option even if the option is selected. THE FIRST FORM VALIDATION ON THE PAGE WORKS AS IT SHOULD. I'm obviously doing something wrong, but I have no idea what. I've worked on it for two days so now I'm asking for help. My code is listed below. Thanks in advance. PHP code: <?php $resultprod = mysql_query("SELECT `inservice`,`prodid`,`prodname` FROM products ORDER BY `order` ASC") or die (mysql_error()); while ($rowprod = mysql_fetch_row($resultprod)) { $inservice = $rowprod[0]; $prodid = $rowprod[1]; $prodname = $rowprod[2]; $resultres = mysql_query("SELECT * FROM reservations WHERE `prodid` = '$prodid' AND `resdate` = '$resdate'") or die (mysql_error()); $checkres = mysql_num_rows($resultres); if ($checkres == 0) { $smallprod = $prodid ."small"; if(substr($prodid,0,2) == 'WD') { echo "<div id='test'>"; echo "<img src='images/$smallprod.jpg' width='470' height='250' border='0' title='Reserve the $prodname now!' />"; echo "<div id='test3'>"; //this is the beginning of the form(s) that I'm having problems with validating echo "<form name='reserve' action='custform.php' method='GET' onsubmit='return validateWetDry()'>"; echo "<select style='height:20px; width:175px; font-size:13px;' name='water'>"; echo "<option value='0' selected>- Choose Wet or Dry -</option>"; echo "<option value='y'>Wet Option</option>"; echo "<option value='n'>Dry Option</option>"; echo "</select><font size='-2'><br /> <br /></font>"; echo "<input type='hidden' name='resdate' value='$resdate' />"; echo "<input type='hidden' name='prodid' value='$prodid' />"; echo "<input type='submit' style='height:30px; width:175px; font-size:14px;' name='submit' value=' Reserve This Unit Now ' />"; echo "</form>"; //this is the end of the form(s) that I'm having problems with validating echo "</div>"; echo "</div>"; } else { echo "<div id='test'>"; echo "<img src='images/$smallprod.jpg' width='470' height='250' border='0' title='Reserve the $prodname now!' />"; echo "<div id='test2'>"; echo "<form name='reserve' action='custform.php' method='GET'>"; echo "<input type='hidden' name='water' value='n' />"; echo "<input type='hidden' name='resdate' value='$resdate' />"; echo "<input type='hidden' name='prodid' value='$prodid' />"; echo "<input type='submit' style='height:30px; width:175px; font-size:14px;' name='submit' value=' Reserve This Unit Now ' />"; echo "</form>"; echo "</div>"; echo "</div>"; } } else { $smallprodres = $prodid . "smallres"; echo "<img src='images/$smallprodres.jpg' width='470' height='250' border='0' title='The $prodname is not available for $resdate' />"; } ?> Javascript Code: function validateWetDry() { var water=document.forms["reserve"]["water"].value if (water==null || water=="0") { alert("Please tell us if you will need to use this unit wet or dry."); return false; } }
  4. After continuing to look at my code, I figured out that the problem was not with this snippet of code at all, it was because later in the code, I was using the $email variable to query other information to make everything work. Once I adjusted the code so that I still had the $email variable even if the user only entered a user name, everything worked perfectly. Thanks to all who read my post and attempted to help. Looks like I just didn't look far enough into my code before assuming the problem was with the new code. Thanks again!
  5. Hello everyone, I have a simple sign in system that has been operational for several months that requires the user to provide a complete email address as a user name and a password. I have had a number of requests by users to have the ability to use the first part of their email address (i.e. testemail @email.com) instead of their full email address. I'm trying to tweak the system to accomodate their requests, but I also want the system to recognize the full email address as well. I'm having some difficulty accomplishing this. Here's how the system is set up and what I've done so far: I have a database with the users' full email (`email`) and password (`pword`). This is how the system has been set up to work only with the full email: <?php $email = $_POST['email']; $pword = md5($_POST['pword']); $q = mysql_query("SELECT * FROM staff WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); if ($r == 1) { //user is signed in } ?> This is what I've tried to get the system to work with just a username OR with the full email address: <?php $email = $_POST['email']; $pword = md5($_POST['pword']); $my_uname_array = explode("@", $email); $uname = $my_uname_array[0]; $q = mysql_query("SELECT * FROM staff WHERE (email = '$email' OR email LIKE '{$uname}%') AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); if ($r == 1) { //user is signed in } ?> Using this code, the user is still signed in when entering their full email address (testemail@email.com), but not when they only enter their "user name" (testemail). Any ideas on what I might be doing wrong or what I need to do to get it to work properly? Thanks in advance.
  6. Thank you for the advice, I will find a tutorial on loops and go through it for future reference. I have used while loops, but only in basic form, but that is the extent of my experience with any sort of loop.
  7. I didn't say that I was a newbie, nor did I ask for anyone to do the work for me. If you look back to my original post, my question is this: "Any ideas on how to do this or what I should search for?" I have been dabling in php for a couple of years now, but I haven't been through any formal classes or anything of the sort. When I have a specific task that I would like to accomplish, I search google and online forums to figure out how to accomplish that task. Up until now, I haven't had the need to use a for loop to accomplish anything of this nature, and I don't have knowledge of "the very basics of loop structures," nor did I know exactly what to search for to find the answer that I needed. In this case, I searched for "php list numbers chronologicaly up to a specific value" and "php list numbers up to an assigned value." With these searches, I came up with no results that pointed me in the direction that I needed. However, had someone simply answered, "this can be accomplished using a for loop," I would have likely searched "php for loops," and found the result that leads to this page: http://www.w3schools.com/php/php_looping_for.asp, which is exactly what I was looking for. Jessica, I seriously do appreciate your help and your obvious extensive knowledge that you are willing to share with people who ask for help. I'm just saying that because someone posts a question that is trivial in your opinion, and they haven't shown any code that they've already tried, it doesn't mean that they haven't tried at all. In order to find something using a search engine or forums, you need to have some knowledge of what you're searching for. Sure, if you search "bag that a woman carries on her shoulder," you're going to get results for "shoulder bags" and "purses," but that's not always how it works for coding. Again, thank you for your help, but assuming that someone hasn't tried anything because the anwer is simple to you, only causes that person to be discouraged, and makes you look like a jerk, which, judging by your willingness to help others, I'm sure you are not. Thanks.
  8. Thank you for your help, I really appreciate the time that you and others take to help people who are learning the basics of php. I'm a little confused though, because you ask "Really?" as if this is a problem that one shouldn't have, or that even the newest of newbies should know.
  9. OK, I know the topic title doesn't say much, but what I'm trying to do is fairly simple to explain. What I'm trying to do is to have real time inventory of specific items that are listed in my database. For simplicity, I'll just say that I have a two mysql query results that are identified in variables $total, and $used. By subtracting $used from $total, I get the number of items still available ($available). What I need to do is create a dropdown box that has numbers listed up to whatever amount is available. For example, if $available = 4, I need a dropdown box that has options 1,2,3, and 4. Any ideas on how to do this or what I should search for? I have found nothing so far. Thanks in advance for your help.
  10. I did try it. Still trying to understand it, but *I'm still researching it* ;-)
  11. I understand how it's difficult to understand what I'm going for here, because it's difficult for me to explain what I'm going for here. Basically, I'm trying to edit an existing page to have more functionality without having to re-write the entire page. My php knowledge is limited, but I've always found a way to make my code work. Not saying that it's always the best way to do things, but at least it works. Just so I understand your array alternative, is this how the code would look (I don't have much experience with arrays)? <?php include("../dbconnect.inc.php"); $result = mysql_query("SELECT `prodid` FROM products") or die (mysql_error()); $products = array(); while ($row = mysql_fetch_row($result)) { $products[$row[0]] = 'n'; } foreach ($products as $key => $value) { echo "$key: $value<br>\n"; } ?>
  12. Hello everyone, This seems that it should be a fairly easy thing to do, but I'm having some difficulty. What I'm trying to query a list of items from my database, and then for each result I get, I want to make it a variable itself. Here's what I have: <?php include("../dbconnect.inc.php"); $result = mysql_query("SELECT `prodid` FROM products") or die (mysql_error()); while ($row = mysql_fetch_row($result)) { $prodid = $row[0]; // If the result of $prodid is "chair," I would like to create a variable named $chair and set its value to "n" ($chair = "n"). I // would like to do this for each result. } ?>
  13. Sorry, this was not supposed to be a duplicate post...
  14. Hello everyone, I'm creating a page that has an html form that has a couple of text areas that I can use to ad text, including special characters and html. This text is being passed to php variables and rendered on the page so that I can view it how the reader will view it. From there I have the option to submit the text to the database for the text to be stored there, or to edit the text, placing it back into text areas by passing the variables via hidden fields and echoing the variables into the "value" area of the form field (<input type="text" name="test" value="<?php echo $variable; ?>" />. The problem that I'm having is that when I enter text including special characters, mainly quotation marks, and then I click the "Edit" button to edit the text further, everything past the first qutation mark is gone. The page I'm working on is located at http://www.bubblybounce.com/test/admin/blogentry.php and the code that I have so far is attached below. Any help would be greatly appreciated. <?php include("../dbconnect.inc.php"); function safe($value){ return mysql_real_escape_string($value); } date_default_timezone_set('America/Chicago'); $cmonth = date("m"); $cday = date("d"); $cyear = date("Y"); $today = "$cmonth/$cday/$cyear"; if (isset($_POST['check'])) { $title = $_POST['title']; $maincontent = $_POST['maincontent']; $sidecontent = $_POST['sidecontent']; $title1 = nl2br($title); $maincontent1 = nl2br($maincontent); $sidecontent1 = nl2br($sidecontent); } elseif (isset($_POST['edit'])) { $title = $_POST['title']; $maincontent = $_POST['maincontent']; $sidecontent = $_POST['sidecontent']; $title1 = nl2br($title); $maincontent1 = nl2br($maincontent); $sidecontent1 = nl2br($sidecontent); } elseif (isset($_POST['done'])) { $title = $_POST['title']; $maincontent = $_POST['maincontent']; $sidecontent = $_POST['sidecontent']; $title1 = safe($title); $maincontent1 = safe($maincontent); $sidecontent1 = safe($sidecontent); $blogresult = mysql_query("SELECT * FROM blog") or die (mysql_error()); $numblog = mysql_num_rows($blogresult); $blognumber = $numblog + 1; $pagename = "blogentry_$blognumber"; copy('blogtemplate.php', '../blog/blogentry_' . $blognumber . '.php'); mysql_query("INSERT INTO `blog` (pagename,title,maincontent,sidecontent,entrydate) VALUES ('$pagename','$title1','$maincontent1','$sidecontent1','$today')") or die (mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="robots" content="noindex, follow" /> <link rel="shortcut icon" href="images/favicon.ico" /> <link href="../style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jscript.js"></script> <title>New Bubbly Bounce Blog Entry</title> </head> <body> <div id="container"> <div id="header"> <ul> </ul> </div> <!-- begin body code --> <div id="content"> <?php if (isset($_POST['check'])) { ?> <form name="checkdone" action="blogentry.php" method="POST"> <div id="blogleft"> <img src="../images/eric.png" width="120" /><br /> <font style="color: #999999; font-size: 14px; font-style: italic;">By: Eric Coulston,<br /> <?php echo $today; ?></font> </div> <div id="blogmiddle"> <h6><input type="hidden" name="title" value="<?php echo $title; ?>" /><?php echo $title1; ?></h6> <input type="hidden" name="maincontent" value="<?php echo $maincontent; ?>" /><?php echo $maincontent1; ?> <p><input type="submit" name="edit" value=" Edit... " /> <input type="submit" name="done" value=" Submit... " /></p> </div> <div id="blogright"> <input type="hidden" name="sidecontent" value="<?php echo $sidecontent; ?>" /><?php echo $sidecontent1; ?> </div> </form> <?php } elseif (isset($_POST['edit'])) { ?> <form name="check" action="blogentry.php" method="POST"> <div id="blogleft"> <img src="../images/eric.png" width="120" /><br /> <font style="color: #999999; font-size: 14px; font-style: italic;">By: Eric Coulston,<br /> <?php echo $today; ?></font> </div> <div id="blogmiddle"> <strong>Title:</strong> <input type="text" name="title" value="<?php echo $title; ?>" /> <p><strong>Main Content:</strong><br /> <textarea style="height: 330px; width: 520px;" name="maincontent"><?php echo $maincontent; ?></textarea></p> <input type="submit" name="check" value=" Check... " /> </div> <div id="blogright"> <strong>Side Content:</strong><br /> <textarea style="height: 370px; width: 260px;" name="sidecontent"><?php echo $sidecontent; ?></textarea> </div> </form> <?php } else { ?> <form name="check" action="blogentry.php" method="POST"> <div id="blogleft"> <img src="../images/eric.png" width="120" /><br /> <font style="color: #999999; font-size: 14px; font-style: italic;">By: Eric Coulston,<br /> <?php echo $today; ?></font> </div> <div id="blogmiddle"> <strong>Title:</strong> <input type="text" name="title"> <p><strong>Main Content:</strong><br /> <textarea style="height: 330px; width: 520px;" name="maincontent"></textarea></p> <input type="submit" name="check" value=" Check... " /> </div> <div id="blogright"> <strong>Side Content:</strong><br /> <textarea style="height: 370px; width: 260px;" name="sidecontent"></textarea> </div> </form> <?php } ?> <div id="footerline"> </div> </div> <!-- end body code --> <div id="footer"> Copyright © 2012 BubblyBounce.com, a division of CaresAbout, LLC. All rights reserved. </div> </div> </body> </html>
×
×
  • 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.