Jump to content

spacepoet

Members
  • Posts

    320
  • Joined

  • Last visited

Everything posted by spacepoet

  1. Thanks as well! Yes, very helpful. Question: Does anyone know if there is an online Mobile Device simulator like this one: http://www.opera.com/mobile/demo/ Only for iPhones, Blackberry, Droid, etc.. I am sure I used on in an old job but can not remember what site it was!
  2. Hi Everyone: Can anyone show me or direct me to a PHP PHP Mobile Device Detection & Redirection Script. I use to use this when doing ASP: <% Dim user_agent, mobile_browser, Regex, match, mobile_agents, mobile_ua, i, size user_agent = Request.ServerVariables("HTTP_USER_AGENT") mobile_browser = 0 Set Regex = New RegExp With Regex .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)" .IgnoreCase = True .Global = True End With match = Regex.Test(user_agent) If match Then mobile_browser = mobile_browser+1 If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/vnd.wap.xhtml+xml") Or Not IsEmpty(Request.ServerVariables("HTTP_X_PROFILE")) Or Not IsEmpty(Request.ServerVariables("HTTP_PROFILE")) Then mobile_browser = mobile_browser+1 end If mobile_agents = Array("w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-") size = Ubound(mobile_agents) mobile_ua = LCase(Left(user_agent, 4)) For i=0 To size If mobile_agents(i) = mobile_ua Then mobile_browser = mobile_browser+1 Exit For End If Next If mobile_browser>0 Then Response.Redirect("http://www.sp.com/SPMOBI/MOBI.asp") End If %> Is there a PHP equivalent of this? As always, I appreciate to wisdom of the board. Thanks!
  3. Hello: I have this bit of code to create a new table: CREATE TABLE `stores` ( `zip_id` INT(11) NOT NULL, `store_id` INT(11) unsigned NOT NULL AUTO_INCREMENT, `store_name` VARCHAR(50) NOT NULL, `address` VARCHAR(50) NOT NULL, `city` VARCHAR(25) NOT NULL, `full_state` VARCHAR(50) NOT NULL, `abbr_state` VARCHAR(50) NOT NULL, `zip` VARCHAR(5) NOT NULL, `phone` VARCHAR(20) DEFAULT NULL, `hours` VARCHAR(100) DEFAULT NULL, `islistingactive` VARCHAR(25) NOT NULL, `fulllisting` VARCHAR(25) NOT NULL, PRIMARY KEY (`store_id`), KEY `zip` (`zip`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*Data for the table `stores` */ INSERT INTO `stores`(`zip_id`,`store_id`,`store_name`,`address`,`city`,`full_state`,`abbr_state`,`zip`,`phone`,`hours`,`islistingactive`,`fulllisting`) VALUES (7768, 1,'Main Shop','123 Church Street.','Malvern','Pennsylvania','PA','19355','(212) 992-3399','Mon-Fri: 9-5, Sat: 8-6, Sun: Closed','Yes','Yes'), (7768, 2,'Ms Place','48 South Street.','Malvern','Pennsylvania','PA','19355','(212) 992-3399','Mon-Fri: 9-5, Sat: 8-6, Sun: Closed','Yes','Yes'); I want to also add 3 - 6 fields to allow a user to uploaded photos of each restaurant. What is the correct snytax/SQL to add to allow this?
  4. Hello: Thanks for the input. You said some good and useful things here. I think you mean I should be doing: zip_id = $my_zip_id" to keep the "php variable names different from your table fields and table names." Note taken about the KEYs as well. Thanks!
  5. Hi: Thanks. Should I be able to integrate the code on that link into my existing form code I posted? I would think I need to add a "filename" type of field as well to store that in the database.
  6. Hello: I would like to know how I can add the option to upload JPGs and/or PDFs to the form I have. I believe I will need to allow 3 uploads once the whole form is done, but I'm trying to keep it small as I learn this. Currently, the form saves the data to the database, and emails the results to a contact. This is fine - just what I need to do most of the time. However, what I'm interesting in doing for this form is to allow the end user to upload/attached JPGs and/or PDFs and save then to the database (and I believe I will need to save the files in a folder on the server, I have one called "EmailedImages"), and then email the results to the contact, including links that will allow the contact to click and download the attached JPGs and/or PDFs. I haven't done this before, so can someone point me in the direction of how to do this, or should an example with the code I use: <?php $error = NULL; $myDate = NULL; $FullName = NULL; $Email = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $FullName = $_POST['FullName']; $Email = $_POST['Email']; if(empty($FullName)) { $error .= '-- Enter your Full Name. <br />'; } if(empty($Email)) { $error .= '-- Enter your Email. <br />'; } if($error == NULL) { $sql = sprintf("INSERT INTO myContactData(myDate,FullName,Email) VALUES ('%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($FullName), mysql_real_escape_string($Email); if(mysql_query($sql)) { $error .= 'Thank you for contacting us.'; mail( "email@mywebsite.com", "Contact Request", "Date Sent: $myDate\n Full Name: $FullName\n Email: $Email\n", "From: $Email" ); } else { $error .= 'There was an error in our Database, please Try again!'; } } } echo '<span class="textError">' . $error . '</span>'; ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> Full Name: <input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" /> Email: <input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> Any help would be greatly appreciated!
  7. Hi Keith: Thanks for thr reply. I'm trying to get my brain around this .. I think I have the theory correct .. little uncertain how to impliment it. Would I not need to also (somehow) pull in the data from the "zip_code" table as well? Like: SELECT zip FROM zip_code WHERE zip_id = "$zip_id I think this would work .. my example code probably isn't the best. It's going to be a form that will have fields for Store Name, Address, City, State, Zip (and probably a few photo uploads). My idea is to pre-populate the City, State, And Zip with the data from the "zip_codes" table, since it already exists, and the allow the user to add the Store name and address, then submit the form into the "stores" table. Does that make sense what I'm trying to do? So, I should probably change the "postal" to be "zip" and add a new field for "zip_id" in the "stores" table? BTW - I don't know how to make a FOREIGN key! Is that something I set in the mySQL admin panel, or the SQL itself? I will not add it if it's not needed, but it would be good to know. Thanks.
  8. Hi all: Thanks for all the input. I'm going to try the Capitalize FUNCTION and see how that goes. Looks like it makes sense. Thanks!
  9. OK, I appreciate this ... This is the entire front end code for the locator - is this what you need to see?? <?php // Create page variables $r = NULL; $z = NULL; $stores = NULL; $Errors = NULL; // Establish DB connection //$dbc = mysql_connect ('localhost', 'username', 'password'); //mysql_select_db ('store_locator', $dbc); include('include/myConn.php'); // Declare page functions function Dist ($lat_A, $long_A, $lat_B, $long_B) { $distance = sin(deg2rad($lat_A)) * sin(deg2rad($lat_B)) + cos(deg2rad($lat_A)) * cos(deg2rad($lat_B)) * cos(deg2rad($long_A - $long_B)); $distance = (rad2deg(acos($distance))) * 69.09; return $distance; } ### Handle form if submitted if (isset ($_POST['submitted'])) { // Validate Zip code field if (!empty ($_POST['zip']) && is_numeric ($_POST['zip'])) { $z = (int)$_POST['zip']; // Verify zip code exists $query = "SELECT lat, lon FROM zip_codes WHERE zip = '$z'"; $result = mysql_query ($query); if (mysql_num_rows ($result) == 1) { $zip = mysql_fetch_assoc ($result); } else { $Errors = '<p>The zip code you entered was not found!</p>'; } } // Validate radius field if (isset ($_POST['radius']) && is_numeric ($_POST['radius'])) { $r = (int)$_POST['radius']; } // Proceed if no errors were found if ($r && $z) { // Retrieve coordinates of the stores $stores = array(); $query = "SELECT name, address, town, state, postal, phone, hours, lat, lon FROM stores INNER JOIN zip_codes ON stores.postal = zip_codes.zip"; $result = mysql_query ($query); // Go through and check all stores while ($row = mysql_fetch_assoc ($result)) { // Separate closest stores $distance = Dist ($row['lat'], $row['lon'], $zip['lat'], $zip['lon']); // Check if store is in radius if ($distance <= $r) { $stores[] = array ( 'name' => $row['name'], 'address' => $row['address'], 'state' => $row['state'], 'town' => $row['town'], 'postal' => $row['postal'], 'phone' => $row['phone'], 'hours' => $row['hours'] ); } } } else { $Errors = ($Errors) ? $Errors : '<p>Errors were found please try again!</p>'; } } ?><html> <head> <title>Store Locator</title> </head> <body> <form action="" method="post"> <p>Enter your zip code below to find locations near you.</p> <?php echo ($Errors) ? $Errors : ''; ?> <div> <label>Zip:</label> <input name="zip" type="text" size="10" maxlength="5" /> </div> <!-- <div> <label>Search Area:</label> <select name="radius" id="radius"> <option value="5">5 mi.</option> <option value="10">10 mi.</option> <option value="15">15 mi.</option> <option value="20">20 mi.</option> </select> </div> //--> <div> <label>Search Area:</label> <input name="radius" id="radius" type="text" size="10" maxlength="5" /> </div> <div> <input type="hidden" name="submitted" value="submitted" /> <input type="submit" value="Submit" /> </div> </form> <?php if (isset ($stores)) { if (!empty ($stores)) { echo '<p><strong>' . count ($stores) . ' results were found.</strong></p>'; foreach ($stores as $value) { echo '<p><strong>' . $value['name'] . '</strong><br />'; echo $value['address'] . '<br />'; echo $value['town'] . ', ' . $value['state'] . ' ' . $value['postal']; echo ' <a target="_blank" href="http://maps.google.com/maps?q=', $value['address'], ' ', $value['town'], ', ', $value['state'], ' ', $value['postal'], '">Map this location</a><br />'; echo 'Phone: ' . $value['phone'] . '<br />'; echo 'Hours: ' . $value['hours']; echo '</p>'; } } else { echo '<p><strong>No results found</strong></p>'; } } ?> </body> </html> Thanks, I'm working on another issue, that I just posted about, if you have any insight into that as well.
  10. Hello: I want to JOIN (I think) 2 tables together so they can work together. I have this little page to select all the stores in a "stores" table that are assigned to a zip code from the "zip_codes" table: <a href=\"Stores.php?zip_id=".$row['zip_id']." \"> ... <?php include('include/myConn.php'); include('include/myCodeLib.php'); $zip_id = $_REQUEST['zip_id']; ?> <?php $query=mysql_query("SELECT store_id,name FROM stores WHERE $zip_id = $zip_id") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $store_id=$result['store_id']; $name=$result['name']; } ?> <html> <head> <title></title> </head> <body> <?php echo $name; ?> | <?php echo $store_id ?> </body> </html> It is currenty not complete or working becasue I a stuck on how to make the two tables talk to each other. This is the "stores" table: CREATE TABLE `stores` ( `store_id` INT(11) unsigned NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL, `address` VARCHAR(50) NOT NULL, `town` VARCHAR(25) NOT NULL, `state` VARCHAR(50) NOT NULL, `postal` VARCHAR(5) NOT NULL, `phone` VARCHAR(20) DEFAULT NULL, `hours` VARCHAR(100) DEFAULT NULL, PRIMARY KEY (`store_id`), KEY `postal` (`postal`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*Data for the table `stores` */ INSERT INTO `stores`(`store_id`,`name`,`address`,`town`,`state`,`postal`,`phone`,`hours`) VALUES (1,'Main Shop','123 Church Street.','New York','New York','10007','(212) 992-3399','Mon-Fri: 9-5, Sat: 8-6, Sun: Closed'); ETC.... This is the "zip_code" table: CREATE TABLE `zip_codes` ( `zip_id` INT(11) NOT NULL AUTO_INCREMENT, `zip` VARCHAR(5) NOT NULL DEFAULT '', `lat` VARCHAR(10) NOT NULL DEFAULT '', `lon` VARCHAR(10) NOT NULL DEFAULT '', `city` VARCHAR(50) DEFAULT NULL, `full_state` VARCHAR(50) DEFAULT NULL, `abbr_state` char(2) NOT NULL DEFAULT '', PRIMARY KEY (`zip_id`), UNIQUE KEY `zip` (`zip`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `zip_codes` (`zip`, `abbr_state`, `lat`, `lon`, `city`, `full_state`) VALUES ('00501', 'NY', 40.92233, -72.63708, 'HOLTSVILLE', 'NEW YORK'); ETC.... I basically want to be able to assign stores to each zip code based on the "zip_id", edit the stores based on the "zip_id", delete the stores based on the "zip_id" ... If I have to change one of the two tables, it would be easier to change the "stores" table. Do I need to make "postal" become "zip" in the stores table? And somehow create a FOREIGN KEY in stores for "zip_id" How might I be able to get this working properly?? I think I'm on the right track in my thinking, but not sure how to create the logic. Thanks.
  11. Hi: I'm kinda stuck using what I have now ... I'll look into it, though. I just know this will become an issue, so trying to develop a solution while I'm still developing this system.
  12. Hi: Not sure if this is where to ask this (maybe it's a mySQL Issue)?? I am working on a zip code locator. The field/column "zip" (which holds the zip codes) is set as a UNIQUE Key in the database. Problem is: I want to allow people to enter a new city if there is one they want to add. The only way I can do this is to remove the UNIQUE Key from the column, or I get an error. Some cities - like Malvern, PA and Frazer, PA - have the same zip code: 19355 This works fine, but the issue that now happens is the zip locator on the frontend will no longer find that zip code. Does anyone know what a solution might be? I can post the zip locator code, and maybe there's a chunk of code I can remove or alter to fix this? Not sure how to address this one.
  13. Hi: Thanks, but not sure if I follow you. Is it a SQL Query that I would run in mySQL? Like: TO CAPITALIZE in zip_codes WHERE Column = towns Something like that?
  14. Hello: Is there a feature or function (SQL Query) that can be used to change all UPPERCASE to just Capitalize the first letter of each word? I have a zipcode database and all the town names and state names are UPPERCASE, which is a bit unsightly and harder for the user to read. Anyway to do this?
  15. Hi: Well the print_r($_POST); did not return any data, but I was able to get it to work doing in this way: <?php $abbr_state = $_REQUEST['abbr_state']; $full_state = $_REQUEST['full_state']; ?> ... <a href="CityList.php?abbr_state=WY&full_state=Wyoming">Wyoming</a> ... <a href="NewCity.php?abbr_state=<?php echo $abbr_state; ?>&full_state=<?php echo $full_state; ?>">Insert New City</a> Then on the next page: $abbr_state = $_REQUEST['abbr_state']; $full_state = $_REQUEST['full_state']; ... State Name: <input type="text" name="full_state" value="<?php echo $_GET['full_state'] ?>" readonly /><br /> State Abbreviation: <input type="text" name="abbr_state" value="<?php echo $_GET['abbr_state'] ?>" readonly /><br /> Still would like to know why the original way didn't work, but at least I can proceed with this project. Thanks for the pointers! One thing: print_r($_POST); basically used to print errors?
  16. Hi: I'm flying a bit blind on this, but I know it's all working fine .. just this one little issue I can't figure out. Would you try print_r($_POST); and see if it returns any value for "Full_State"? I will add it, but I'm honestly not sure where or how - I'm still pretty new with the PHP syntax and such, which is why some of this is a bit maddening to figure out.
  17. OK, but why then does this field: State Abbreviation: <input type="text" name="abbr_state" value="<?php echo $_GET['abbr_state'] ?>" readonly /><br /> Get the proper data (state abbreviation) filled in? Maybe I should try to pull the full_state in this way as well. Didn't think this was going to be so hard .. lol ..
  18. Hi: It pulls the value from a database on the first page like this: <?php include('include/myConn.php'); $result = mysql_query("SELECT city,abbr_state,zip FROM zip_codes WHERE abbr_state = '" . mysql_real_escape_string ( $_GET['abbr_state'] ) . "' ORDER BY `city` ASC"); while($row = mysql_fetch_array($result)){ echo $row['city']. " - ". $row['zip']. " - ". $row['abbr_state'] ; echo "<br />"; } ?> ...... <a href="CityList.php?abbr_state=AL">Alabama</a><br /> <a href="CityList.php?abbr_state=AK">Alaska</a><br /> <a href="CityList.php?abbr_state=AZ">Arizona</a><br /> etc... ...... <a href="NewCity.php?abbr_state=<?php echo $abbr_state ?>">Insert New City</a> And yes, it is assigning the the correct value for each state. Maybe I should pull the full_state from here and send it over this way (I am currently not SELECTING it, but I obviously can)? How would I adjust the link, if that's the route I take? Thanks for the help.
  19. Hi: I mean the field is empty: State Name: <input type="text" name="full_state" value="<?php echo $full_state; ?>" /><br /> I'm trying to auto-populate that field with the full state name. I'm not getting any errors, which is why I'm a bit baffled. This is the link used to get to the page: <a href="NewCity.php?abbr_state=<?php echo $abbr_state ?>">Insert New City</a> Maybe I should try carrying-over the "abbr_state" AND the "full_state" from that link??
  20. Hi: Thanks, but that didn't work either. . . This is the full page I'm working with (now including your code): <?php include('include/myConn.php'); include('include/myCodeLib.php'); $abbr_state = $_REQUEST['abbr_state']; $error = NULL; $lat = NULL; $lat = NULL; $city = NULL; $full_state = NULL; $abbr_state = NULL; $zip = NULL; if(isset($_POST['submit'])) { $lat = $_POST['lat']; $lon = $_POST['lon']; $city = $_POST['city']; $full_state = $_POST['full_state']; $abbr_state = $_POST['abbr_state']; $zip = $_POST['zip']; if(empty($city)) { $error .= ' Enter your City '; } if($error == NULL) { $sql = sprintf("INSERT INTO zip_codes(lat,lon,city,full_state,abbr_state,zip) VALUES ('%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($lat), mysql_real_escape_string($lon), mysql_real_escape_string($city), mysql_real_escape_string($full_state), mysql_real_escape_string($abbr_state), mysql_real_escape_string($zip)); if(mysql_query($sql)) { $lat = $_REQUEST['lat']; $lon = $_REQUEST['lon']; $city = $_REQUEST['city']; $full_state = $_REQUEST['full_state']; $abbr_state = $_REQUEST['abbr_state']; $zip = $_REQUEST['zip']; header("Location: CityList.php?abbr_state=$abbr_state"); } else { $error .= 'There was an error in our database, please try again!'; } } } ?> <html> <body> <?php $abbr_state = mysql_real_escape_string($_POST['abbr_state']); $query = "SELECT full_state FROM zip_codes WHERE abbr_state = '$abbr_state'"; if( !$result = mysql_query($query) ) { echo "<br>Query: $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $array = mysql_fetch_assoc($result); $full_state=$array['full_state']; } ?> <?php echo '<p><span class="textError">' . $error . '</span></p>';?> <form name="myForm" action="" method="post"> Latitude: <input type="text" name="lat" value="<?php echo $lat; ?>" /><br /> Longitude: <input type="text" name="lon" value="<?php echo $lon; ?>" /><br /> City Name: <input type="text" name="city" value="<?php echo $city; ?>" /><br /> State Name: <input type="text" name="full_state" value="<?php echo $full_state; ?>" /><br /> State Abbreviation: <input type="text" name="abbr_state" value="<?php echo $_GET['abbr_state'] ?>" readonly /><br /> Zip Code: <input type="text" name="zip" value="<?php echo $zip; ?>" /><br /> <input type="submit" name="submit" value="Submit New City" /> </form> </body> </html> Can you see what I'm missing?
  21. Hi .. tried it but it didn't work ... Could the issue be in here: State Name: <input type="text" name="full_state" value="<?php echo $full_state; ?>" /><br /> Maybe I'm not calling it properly (I don't know an am getting no errors, so it's hard to troubleshoot). ??
  22. Hi: I have another small issue like the one I just posted about. I am trying to get the full state name based upon the state abbreviation. Like this: <?php $query=mysql_query("SELECT full_state FROM zip_codes WHERE abbr_state = abbr_state") or die("Could not get data from db: ".mysql_error()); $full_state=$result['full_state']; ?> ... State Name: <input type="text" name="full_state" value="<?php echo $full_state; ?>" /><br /> [code] No errors, but also no "full_state" appears. (It is pulling in the correct "abbr_state") What am I missing here?
  23. Ahhh ... yes. I got it: State: <input type="text" name="abbr_state" value="<?php echo $_GET['abbr_state'] ?>" readonly /><br /> Thanks for the direction!
  24. Hi: I am trying to pass/request a Variable/QueryString from one page to another, but it isn't working. Seems like it would be simple, so maybe I am overlooking the obvious. I have the 1st page: <a href="NewCity.php?abbr_state=<?php echo $abbr_state ?>">Insert New City</a> Writes the URL properly - CityList.php?abbr_state=CT The 2nd page: <?php $abbr_state = $_REQUEST['abbr_state']; ?> <form> State: <input type="text" name="abbr_state" value="<?php echo $abbr_state; ?>" readonly=""/><br /> </form> But it does not get the variable/QueryString for "CT" and add it to the form field (it's not the "readonly" causing it). Why? What did I miss?
×
×
  • 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.