Jump to content

elmas156

Members
  • Posts

    276
  • Joined

  • Last visited

Everything posted by elmas156

  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>
  15. Just as a guess, to limit the search to 5 results, would I use the LIIMIT clause in this manner? I'm not near my computer with my code right now, so I can't test it for myself... $resultcomm = mysql_query("SELECT `name`,`comment` FROM comments ORDER BY `index` DESC LIMIT 5") or die (mysql_error()); Thanks again for your help.
  16. Hello, I'm creating a "comments" section for my website, and I want to display a few of my most recent comments posted by users. I know how I would display ALL of the comments posted, but not sure how I would display only a few... say 4 or 5 comments. Anyone have any suggestions or ideas? Here's my current code: <?php $resultcomm = mysql_query("SELECT `name`,`comment` FROM comments ORDER BY `index` DESC") or die (mysql_error()); while ($rowcomm = mysql_fetch_row($resultcomm)) { $name = $rowcomm[0]; $comment = $rowcomm[1]; echo "<p class='p14'>$comment<br />"; echo "<div class='p15'>- $name</div></p>"; echo "<hr width='200' />"; } ?> Thanks for any help!
  17. Thanks so much for your help and the time you both took to reply. I have gained some great knowledge here, and I feel like I have the information that I need to accomplish my goals... the time consuming part is actually doing what I need to do. Thanks again!
  18. Hello everyone, I'm not sure if this is in the correct forum, so please forgive me if it's not. Just FYI, the web domains that I use in this example are ficticious and I am just using them as an example instead of using my actual web address. Here's my situation: I'm working on getting recognized on the web through search engines. My website url is the name of my business, say, "www.coolairdesigns.com," and my business is creating aircraft paint designs. I know that if I have text and keywords that match what people search for in Google, for example "aircraft paint in Dallas," I have a better chance of being found in the search listings. However, if someone searches "cool air designs" in Google, my site is the first that comes up in organic listings, making it very easy to be found. The problem with this is that someone would already have to know that I exist, and be searching specifically for my website for this to happen. I'm looking at purchasing domains such as "aircraftpaintdallas.com," and "aircraftdallaspaint" so that when someone uses "aircraft," "paint," and "dallas" in their search, my domains would have a better shot at comming up near the top of the organic listings. What I would do is have some generic text and key words on the pages of those additional domains that would pertain to the searches where people might be looking for a business such as mine. When someone clicks on my domain, which would come up on the search, instead of seeing the generic text, that ultimately is only there to help with search rankings, they would be instantly redirected to my main site, "www.coolairdesigns.com," using php header(Location:...). Here are my questions: Does this sound pheasible? Would it work for what I'm looking for? Would search engines regocnize this and consider it "cheating" and somehow block my domain from being shown in their listings? Any help and/or advice would be greatly appreciated.
  19. Thanks... this helps a lot.
  20. Hello everyone, I have a general question that I really couldn't find a direct answer to on the web anywhere else. My question is this: If I have a page on my site that is strictly php code, such as an include file with database connection code, is that information visible to anyone else out there via the web, or would they actually need to have the php file on their computer and view it in a code editor? I know that if I use a browser to go to my db_connect.inc.php file, it is simply a blank page with no page source. Thanks for any help.
  21. I contacted my hosting provider tech support and they told me that pdf support was actually listed under "SPL," and that it was enabled. Not sure what SPL is, but that's what I was told. Anyone know anything about this. Just FYI, my hosting provider is Web Hosting Hub.
  22. Hello everyone, I found a tutorial on creating a pdf with php and I just tried to create a basic pdf to see if it worked and modify it from there. Here is the link to the tutorial: http://www.astahost.com/info/tfclt-create-pdf-php-create-fly-pdf-web-server.html Well, after uploading the following php file to the server and testing it, I got this error: Fatal error: Call to undefined function pdf_new() in /home/caresa6/public_html/BubblyBounce.com/admin/pdftest.php on line 2 Here's the code that produced the error: <?php $mypdf = PDF_new(); PDF_open_file($mypdf, ""); PDF_begin_page($mypdf, 595, 842); $myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0); PDF_setfont($mypdf, $myfont, 10); PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750); PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730); PDF_end_page($mypdf); PDF_close($mypdf); $mybuf = PDF_get_buffer($mypdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=gen01.pdf"); print $mybuf; PDF_delete($mypdf); ?> Can anyone help me figure out what to do from here? I have some PHP knowledge, but I'm treading in uncharted waters with this, so I am totally lost. Thanks in advance.
  23. Hello everyone, I've already posted a question trying to resolve my problem, but I've changed my code so much, I figured it may be best just to post a new thread with a better explanation of what I'm trying to do. Anyway, here's what I've got: I have a database with 2 tables: products and reservations. I have 3 products for now, that can be reserved for any date. I'm trying to create a page that will display all of the available products for a specific date. The user selects the date they want to check, and then the code should check their selected date and compare it with the database to display everything that is available on that date. The database looks like this: Products Table: prodid prodname 01 item 1 02 item 2 03 item 3 Reservations Table: prodid resdate 01 02/22/2012 01 02/23/2012 03 02/22/2012 Here is the code that I have now: <?php $resultres = mysql_query("SELECT `prodid` FROM reservations WHERE `resdate` = '$resdate'") or die (mysql_error()); while ($rowres = mysql_fetch_row($resultres)) { $resprodid = $rowres[0]; $resultavail = mysql_query("SELECT `prodid` FROM products WHERE `prodid` != '$resprodid'") or die (mysql_error()); while ($rowavail = mysql_fetch_row($resultavail)) { $prodid = $rowavail[0]; echo $prodid; echo $proname; } } ?> When I select 02/21/2012, I get no results, where I should get all three products as a result, because none of them are reserved on this date. When I select 02/22/2012, I get a result of these products, in this order: 02, 03, 01, 02. I should get a result of ONLY 02, because this is the only product that isn't reserved for this date. When I select 02/23/2012, I get a result of 02 and 03, which in this case would be the correct return, because 01 is the only one reserved for this date. Any idea what I'm doing wrong here and how to fix it? Any help is GREATLY appreciated!
×
×
  • 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.