Jump to content

rick.emmet

Members
  • Posts

    68
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

rick.emmet's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks Psycho, I haven't been able to get back to this for four days (yikes), but I'll start on it today. Cheers, Rick
  2. Hello scootstah and cyberRobot, Thank you for the replies! My service provider has been changing out their equipment and I haven't had access for several days. I may be overwriting the session somehow, didn't even occur to me to look into that and I'm not generating any errors at all. When I have a problem this messed up, it's ussually a matter of having the wrong approach, so that's why I didn't post any code. Is there a type of functionality that either of you prefer to use in this kind of situation? Thanks again! Cheers, Rick
  3. Hello All, I'm attempting to create functionality that allows users to update a sales figure by: adding one of two ad-ons (or both) and / or subtracting a promotional discount if one applies. I'm setting both of my ad-on variables, as well as the discount to zero, then I'm using plain PHP to process the math. When I first arrive on the page, from an editing page, the correct figure is displayed at the bottom of the form ($9.99), but when I click on the recalculate button (form action=”THIS_PAGE”) the base price disappears and the total at the bottom becomes “$0.” These are $_SESSION variables, so it seems to me that they should remain persistent. I've been looking at JavaScript DOM Storage shopping carts, and the use of multidimensional arrays such as $_SESSION['cart'] to solve this problem. It seems to me that this should be very straightforward, but perhaps I'm approaching this incorrectly. I would like to get input on the best approach to this problem – don't even want to bother anyone with code at this point. Do any of you have a very reliable approach or model to suggest? Thanks a bunch in advance. Cheers, Rick
  4. Hello everyone, I have a problem that is stumping me. I wrote some JS code that worked fine on two development machines and then work perfectly on the production server. I made a single change to my JS library and tested it, one of my JS function (a show / hide) stopped working. I reverted back to the original code and restested it. The showHide function is still not working. Firebug provides an error message that says "showHide( ); is not defined." I looked at the code and can't see anything wrong with it, so I went online to JSHint and validated the code. It validates. Here's the code in my JavaScript Library: (function($) { // This allows the jQuery object to be used w/o interferance // Always nice to use strict mode "use strict"; function ShowHide() { var head1 = document.getElementById("head1"); var showform = document.form1.head1.checked; head1.style.visibility = (showform) ? "visible" : "hidden"; } })(jQuery); And here is the JS code embedded in XHTML: <form name="form1" > <input type="checkbox" name="head1" onclick="ShowHide();" />Edit Content</form> Here's what JSHint says of the code: function ShowHide() { 'ShowHide' is defined but never used. I don't see any syntax error (and neither does netBeans) and if JSHint says the code is valid, then I have no idea what is wrong. Anyone have a clue? Thanks very much for you help! Cheers, Rick
  5. Hello Strider and David, Thank you both so much for your time, there were just a couple of things I wasn't getting. I used the question mark for subsequent parameters (for some reason I thought it was some combination of "&" plus "%") and that worked well. Also, I couldn't use session_name() = session_id() becuse the name will be the same for every user. I did a little experimenting and came up with this: <a href="srch_detail_autos.php?instance_id=<?php echo $row_rsautos['instance_id']; ?>&column=<?php echo $_SESSION['column']; ?>&key_word=<?php echo $_SESSION['key_word']; ?>&session_id=<?php echo session_id(); ?>" > I was able to see the parameters in the URL, so that was a good sign. But I was still failing to get a result on the second page for two lines of code "echo $_SESSION['column'];" and "echo $_SESSION['key_word'];". So I just use $_GET, and it worked like a champ. Thanks again for your help!! cheers, Rick
  6. Hi Everyone, I have a (hopefully) quick question. When I send a single piece of data in the URL to the next webpage, I get the behavior I'm expecting. I need to send two pieces of data and can not get it to work. I have session_start() at the top of both pages and session.use_trans_sid in my php.ini is set to 0 for security reasons. The PHP manual says that I can use htmlspecialchars(SID), it says: <?php session_start(); if (empty($_SESSION['count'])) { $_SESSION['count'] = 1; } else { $_SESSION['count']++; } ?> <p> Hello visitor, you have seen this page <?php echo $_SESSION['count']; ?> times. </p> <p> To continue, <a href="nextpage.php?<?php echo htmlspecialchars(SID); ?>">click here</a>. </p> OK, good enough. I need to send the SID to the next page, and I need to send the instance_id too. What I have tried to use to do is this: <a href="srch_detail_autos.php?instance_id=<?php echo $row_rsautos['instance_id']; ?>"?session_id="<?php echo htmlspecialchars(SID); ?>" ><?php echo stripslashes($row_rsautos['title']); ?></a> <a href="srch_detail_autos.php?instance_id=<?php echo $row_rsautos['instance_id']; ?>"?session_id='<?php echo htmlspecialchars(SID); ?>' ><?php echo stripslashes($row_rsautos['title']); ?></a> The difference being the use of double quotes in the first and single quotes in the second. The code looks OK in the editor, all the mark up colors look good. When I hover over the link, I can see the URL of the target page and the instance_id, but nothing beyond that. I looks as if the browser is not reading the subsequent data (SID) I'm attempting to place in the URL. I also tried the following: <a href="srch_detail_autos.php?instance_id=<?php echo $row_rsautos['instance_id']; ?>?session_id=<?php echo htmlspecialchars(SID); ?>" ><?php echo stripslashes($row_rsautos['title']); ?></a> And when I hover over the link, I can see the instance_id and “session_id=” but no SID. The browser is not reading the PHP echo statement. I also tried numerous other versions of this, but they looked completely wrong in the editor and /or throw errors. I seem to recall that there is a special character for this (to add more pieces of data to the URL), but everything I have plugged in to the code fails. Is there a simple way of writing more than one piece of data to the URL? Thanks very much for your time, I really appreciate it! Cheers, Rick
  7. Hi Everyone, I ran some code that I wrote about 11/2 years ago (it ran fine at the time) and now It will not run. I did a little research and found out that the code I used, which I found online and modified, is actually DreamWeaver generated code (no wonder that it stopped working). The code displays a thumbnail image, and if a photo has been uploaded and a user clicks on the thumbnail, a new window opens up and displays a larger image. I like the structure of this code because it allows for cases where no image was uploaded. The thumbnail image is then a default “No Photo” gif and if a user clicks on the image anyway, a large “No Photo” gif is displayed. The original code now throws and error, "JavaScript Error: Javascript:MM_openBrWindow is not defined". I made a number of attempts to get rid of the MM_openBrWindow and all failed to even allow the page the code resides on to load. The last attempt allows the page to load and when I place the cursor over the thumbnail, I can see the correct file location in the status bar. But when I click on the image, the new window does not open and I'm redirected to the "Error 404 Object Not Found!" page. I'm not sure why this is happening, it seems as if the browser knows the location of the file. Here's the code: //PHP code, DB Connection & SQL queries here // fetch the data for this record $row_rsproducts = mysql_fetch_assoc($rsproducts); // Original HTML code w/ embeded PHP - which does not run any longer <td width="132"><?php $image = 'uploads/'.$row_rsproducts['instance_id'].'a.jpg'; if (file_exists($image)) { $link = 'Javascript:MM_openBrWindow(\''.$image.'\',\'\',\'width=600,height=450\');'; } else { $link = 'Javascript:void(0)'; $image = 'images/no_Photo_Lg.gif'; } ?> <a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>" width="132" height="99" border="0"/></a></td> This throws an error "JavaScript Error: Javascript:MM_openBrWindow is not defined" And the new code is: //PHP code, DB Connection & SQL queries here // fetch the data for this record $row_rsproducts = mysql_fetch_assoc($rsproducts); // New HTML code w/ embeded PHP (no MM_openBrWindow call) <td width="132"><?php $image = 'uploads/'.$row_rsproducts['instance_id'].'a.jpg'; if (file_exists($image)) { $link = 'onclick=window.open(\''.$image.'\');'; } else { $link = 'Javascript:void(0)'; $image = 'images/no_Photo_Lg.gif'; } ?> <a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>" width="132" height="99" border="0"/></a></td> If anyone has an idea as to why this won't run, I'd love to hear it - and thank you in advance! Cheers, Rick
  8. Hi Barand, Thanks so much for your reply, this is very helpful! Cheers, Rick
  9. Hi Everyone, I'm trying to help out a classmate from a Javascript class I'm taking. He created a website with a MySQL database and had problems with foreign constraints. About 5 years ago, I had been using phpMyAdmin to do some testing of INSERT statements. I was able to insert a “user name” and other personal information into a “user” table, and then take the “user_id” (auto incremented) and insert that into a second table where there was a relationship between the two tables. As I recall, there was a built-in MySQL function that supported this. I have looked for it and all I have found is the LAST_INSERT_ID() function. It doesn't look quite right to me, and the simple insert statement I ran throws and error. Here's the SQL to create the database: -- -- Database : test -- DROP DATABASE IF EXISTS `test`; CREATE DATABASE `test`; USE test; SET FOREIGN_KEY_CHECKS=0; -- -- table structure for `clients` -- CREATE TABLE users ( user_id int NOT NULL auto_increment, email Varchar(50) NOT NULL default '', user_name Varchar(16) NOT NULL default '', password Varchar(40) NOT NULL default '', user_group Varchar(16) NOT NULL default 'User', first_name Varchar(25) NOT NULL default '', last_name Varchar(25) NOT NULL default '', street_nmb int(7) NOT NULL default '0', st_name Varchar(50) NOT NULL default '', city Varchar(50) NOT NULL default '', state ENUM ('AA','AE','AL','AK','AP','AR','AS','AZ','CA','CO','CT','DC','DE','FL','FM','GA','GU','HI','ID','IL','IN','IA','KS','KY','LA','MA','ME','MD','MH','MI','MN','MO','MP','MS','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','PR','PW','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY') NOT NULL, zipcode Mediumint(5) Unsigned NOT NULL default '00000', reg_date DateTime, last_edit DateTime NOT NULL, last_editby Varchar(20) NOT NULL default '', PRIMARY KEY (user_id) ) Engine=InnoDB; -- -- table structure for `otherTb` -- CREATE TABLE otherTb ( user_id Int NOT NULL default '0', instance_id int NOT NULL auto_increment, category_id Tinyint(2) Zerofill NOT NULL default '00', insert_date DateTime NOT NULL, PRIMARY KEY (instance_id), KEY (user_id), FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE ) Engine=InnoDB; SET FOREIGN_KEY_CHECKS=1; And here is the insert statement that is failing (the MySQL engines says that I have a syntax error on the line “VAL = LAST_INSERT_ID();” ): SET AUTOCOMMIT=0; INSERT INTO `users` (`user_id`, `email`, `user_name`, `password`, `user_group`, `first_name`, `last_name`, `street_nmb`, `st_name`, `city`, `state`, `zipcode`, `reg_date`, `last_edit`, `last_editby`) VALUES (NULL, 'henry@localhost', 'henryhill', '285d0c707f9644b75e1a87a62f25d0efb56800f0', 'Forum Type Three', 'henry', 'hill', 9876, 'adams st', 'youngstown', 'OH', 54321, NOW(), NOW(), 'henryhill'); VAL = LAST_INSERT_ID(); INSERT INTO `otherTb` (VAL, `instance_id`, `category_id`,) VALUES (NULL, NULL, 04); SET AUTOCOMMIT=1; As I recall, I used transactions for this process all those years ago, and the general structure was very much like what I have above. It may be that there was a special variable that has to be used with the LAST_INSERT_ID() function (and that would in turn be used in the following insert statement), but I couldn't find one at the MySQL site. Does anyone have an idea of what this built in function (or perhaps the special variable) I'm trying to use is called? Sorry that my query is so “nebulous” but I can't remember stuff I did that long ago! Cheers, Rick
  10. Hello Pikachu2000, That did the trick, thank you so much for the assistance!! I was expecting Terminal to behave just like cmd.exe once I got to the bin folder (I've never had to do that in the PC environment). Thanks again, Rick
  11. Hi Everyone, I just installed XAMPP for Mac OS and inserted permissions into the "user" and "db" tables of the mysql database for a type of user. This is the normal way we did this in a PHP class - the db_function that is called when a user wants to access their database has the host, the type of user, the password and the database the user has access to. This system provides the permissions to the database in question and the password a user creates (and uses to log in) is stored in said database. I tried to to create a new user for this database and got a permissions error. This has happened before in a PC environment; you can insert the user info and permissions and see all the Ys in the permission columns you want the user to have - but those privileges aren't actually granted. In the PC environment you must use the command line to issue grants to users. OK, I tried a shortcut on the Mac (might as well see if it works) and it behaves like the PC. No problem, I'll just use terminal and grant the privileges to this user. I opened terminal and attempted to change the directory to get to Applications/XAMPP/xamppfile/bin and the prompt told me I was in bin. I then input mysql -h localhost -u root -p and I get a "command not found". Looking at the directory, this looks like the correct (executable) mysql application file. And searching on the web, I also found people that were accessing the mysql application in this directory. I have turned on Apache and Mysql using the XAMPP controls interface. Can someone tell me what's going on here? Thanks much in advance! Cheers, Rick
  12. Hi Everyone, I took a PHP class that used PHP And MySQL Web Development by Welling and Thomson as our textbook and we were able to get through most of the book. We didn't have time to cover chapter 34 Building Web 2.0 Applications with AJAX though. I need to do some AJAX development and have proceeded to work with the examples in the book. The section, Adding Bookmarks the AJAX Way, has us changing a number of scripts that were used previously to make the interface more user friendly. I typed out the scripts and couldn't get them to run. I cut and pasted the code into my PHP pages and it still won't run, so I need a little help. I found several typos which I corrected but the scripts will not run; the weird thing is that nothing happens when I click on the “Add bookmark” button. A new snippet of code has been added as a button attribute that invokes a javascript function which calls a PHP script to insert the bookmark into the database. These scripts have numerous error messages (exceptions), but not a single one is displayed on the page. I have a form which allows me to add a bookmark and there is a button to click on; and when I fill out the form and click on the button, the page does not change at all. Since this is new to me, I'm having a hard time figuring out where the problem is. The PHP script requires both a bookmark and a valid user (both are input into the database). It looks as if the javascript function is only sending the bookmark, but since we really don't really leave the page, perhaps the PHP script can grab the valid user to process. I do want to learn this stuff (wish we had time to cover this in class!) and any advice would be most appreciated! Here are the scripts: THE AJAX.JS FILE function getXMLHTTPRequest() { var req = false; try { /* for Firefox */ req = new XMLHttpRequest(); } catch (err) { try { /* for some versions of IE */ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (err) { try { /* for some other versions of IE */ req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err) { req = false; } } } return req; } function addNewBookmark() { var url = "add_bms.php"; var params = "new_url=" + encodeURI(document.getElementById('new_url').value); myReq.open("POST", url, true); myReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); myReq.setRequestHeader("Content-length", params.length); myReq.setRequestHeader("Connection", "close"); myReq.onreadystatechange = addBMResponse; myReq.send(params); } function addBMResponse() { if (myReq.readyState == 4) { if(myReq.status == 200) { result = myReq.responseText; document.getElementById('displayresult').innerHTML = result; } else { alert('There was a problem with the request.'); } } } THE ADD BOOKMARKS FUNCTION FROM THE OUTPUT LIBRARY function display_add_bm_form() { // display the form for people to enter a new bookmark in ?> <script type="text/javascript"> var myReq = getXMLHTTPRequest(); </script> <form> <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc"> <tr><td>New BM:</td> <td><input type="text" id="new_url" name="new_url" value="http://" size="30" maxlength="255"/></td></tr> <tr><td colspan="2" align="center"> <input type="button" value="Add bookmark" onclick=" javascript:addNewBookmark();"/></td></tr> </table> </form> <div id="displayresult"></div> <?php } THE ADDBOOKMARKS PHP SCRIPT <?php require_once('bookmark_fns.php'); session_start(); //create short variable name $new_url = $_POST['new_url']; //check that form has been completed if (!filled_out($_POST)) { //has not echo "<p class=\"warn\">Form not completely filled out.</p>"; } else { // has; check and fix URL format if necessary if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // continue on to check URL is valid if (!(@fopen($new_url, 'r'))) { echo "<p class=\"warn\">Not a valid URL.</p>"; } else { //it is valid, so continue to add it add_bm($new_url); } } // regardless of the status of the current request // get the bookmarks this user has already saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } ?> THE ADD_BM FUNCTION FROM THE URL FUNCTION LIBRARY function add_bm($new_url) { // Add new bookmark to the database echo "Attempting to add ".htmlspecialchars($new_url)."<br />"; $valid_user = $_SESSION['valid_user']; $conn = db_connect(); // check not a repeat bookmark $result = $conn->query("select * from bookmark where username='$valid_user' and bm_URL='".$new_url."'"); if ($result && ($result->num_rows>0)) { echo "<p class=\"warn\">Bookmark already exists.</p>"; } else { //attempt to add if (!$conn->query("insert into bookmark values ('".$valid_user."', '".$new_url."')")) { echo "<p class=\"warn\">Bookmark could not be inserted.</p>"; } else { echo "<p>Bookmark added.</p>"; } } return true; } THE DB_CONNECT FUNCTION FROM THE DB FUNCTION LIBRARYf unction db_connect() { $result = new mysqli('localhost', 'bm_user', 'password', 'bookmarks'); if (!$result) { throw new Exception('Could not connect to database server'); } else { return $result; } } Looks all looks good to me, but I just started studying this so... Thanks in advance for your help, Rick
  13. Hello ChristianF, Thank you for the updated info - the last time I took a Dreamweaver class it was for CS4, but that is fairly recient and Adobe / Macromedia should not be using stone-age standards. I'll update the functionality to the most current standard. As I mentioned to Lemmin, I'm really surprised that I didn't approach the problem from a PHP perspective. I didn't have a model I liked and so was relying on the Dreamweaver "product detail page" as a model - I think my problem is that first I must wrap my head around the approach Dreamweaver uses (I can't think like those guys!). Thanks again! Hi Lemmin, The code you wrote looked pretty much perfect when I read it and so I didn't report the results (for anyone interested). There were a couple of tiny errors in the script, so I want to publish this for anyone who needs this type of functionality... <?php $image = 'uploads/'.$row_products['product_id'].'a.jpg'; if (file_exists($image)) { $link = 'Javascript:MM_openBrWindow(\''.$image.'\',\'\',\'width=600,height=450\');'; } else { $link = 'Javascript://'; $image = 'images/no_photo.gif'; } ?> <a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>" width="132" height="99"/></a> There was a double quotation mark missing and the word image was missing the S, but the script was fine otherwise. Thank you very much for the help! Cheers, Rick
  14. Hi Lemmin, Thank you for the quick reply! Using a PHP function instead of inserting PHP into the html makes a lot more sense, I don't know why I didn't try that. Usually I default to PHP (I'd rather write it than anything else). I was using a couple of pages created in a Dreamweaver class I took years ago as a model. For the most part it has the functionality I wanted, but it needs to have all kinds of crap pulled out of the code (it's full of html formatting and unneeded javaScript too). For most of the work I'm doing I've been able to use scripts from PHP and MySQL Web Development by Welling and Thomson (which is a great book), but they don't have product list and product detail pages to use as a model. Thanks again, I'll implement the PHP function! Cheers, Rick
  15. Hello Everyone, I have a javascript function in my library that allows another larger window to be opened when a user clicks on a thumbnail image. The function is as follows: function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } The javascript that calls the function has an if statement within it that displays a thumbnail (if it exists) or a generic No Photo image if the user did not upload an image. The code for this is as follows: <TD> <a href="'uploads/'.$row_products['product_id'].'a.jpg'" onClick="MM_openBrWindow('<?php echo 'uploads/'.$row_products['product_id'].'a.jpg' ?>','','width=600,height=450'); return false"> <?php if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) { ?> <img src="<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>" width="132" height="99" border="0"><?php ; } else { ?> <img src="<?php echo 'images/no_photo.gif'; ?>" width="132" height="99" border="0"><?php ; } ?> </TD> If there is a thumbnail, it will be displayed and when a user clicks on the image (which is also a link) a new window opens displaying the full size image. This works well except that when the user has not uploaded an image (and therefore the No Photo image is displayed) if they click on that image, a new window opens and the user is greeted with an Object Not Found error message. I don't think may users would click on the No Photo image, but I would like their experience to be a bit better. I have attempted several versions of the following code and can't get any of them to work. The code is: <TD> <a href="'uploads/'.$row_products['product_id'].'a.jpg'" onClick= <?php if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) { ?> "MM_openBrWindow('<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>', '', width=600,height=450'); return false"> <?php ; } else { ?> <a href="javascript:void(0);"> <?PHP // WANT TO HAVE "NO LINK" WHEN THERE IS NO PHOTO FOR THE ITEM } if (file_exists('uploads/'.$row_products['product_id'].'a.jpg')) { ?><img src="<?php echo 'uploads/'.$row_products['product_id'].'a.jpg'; ?>" width="132" height="99" border="0"><?php ; } else { ?><img src="<?php echo 'images/no_photo.gif'; ?>" width="132" height="99" border="0"><?php ; } ?> </a> </TD> Here I'm trying to use two if statements, one to display the thumbnail or No Photo image and another to either open a new window and display the full size image or in the case that the user has not uploaded a photo, a Null Link (which should not allow the user to follow the link). There is no reason a user should be able to follow a link to nowhere. What happens is that when I place the cursor over the thumbnail or the No Photo image, I can see the ...uploads/'.$row_products['product_id'].'a.jpg in the component bar (which is normal), but clicking on either type of thumbnail (real or No Photo), does not open another window. Instead, the user lands on a page displaying an Object Not Found error message in the existing window. The address bar then displays something such as http://www.siteName/uploads/'.$row_products['product_id'].'a.jpg - not the resolved address. It is as if the dynamic product_id is not passed along. This confuses me, I don't know why the product_id would not be passed, or is the problem something else entirely? Is the function unable to handle the if statement in the call to MM_openBrWindow? If someone could give me an idea of what the problem is, I'd really appreciate it! Cheers, Rick
×
×
  • 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.