Jump to content

midjam

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by midjam

  1. either that or the url parameter is not being passed
  2. Let me explain the problem a little clearer. I have a database setup with lng, lat and have all pins displayed correctly on the front page. I have a link for each record which goes to the location details page and passes the record ID in the url ?location= I`m trying to filter the map to only show that location, the file that creates the XML works fine if I preview it in the browser and change the ?location= number so, I think it`s a problem with the javascript specifically this line: for (var i = 0; i < markers.length; i++) { As it looks like it is trying to add more than one pin. If anyone could shine some light on this, it would be great
  3. I`m guessing it`s because i`m using java to create an xml and $_GET needs to be in html/php to work, am i on the right track?
  4. Hi guys, i`m a noob with javascript and php so, please go easy I have been following this tutorial: http://code.google.com/apis/maps/articles/phpsqlajax_v3.html#createmap All has been going great until i try to filter the results with a url parameter(location), i can`t set $locations to $_GET['locations'] which will filter what records to show. At the moment it just defaults to record 98. Hope this is clear Have been searching for the reason why for 5 hours now hence my question here. Heres my code: <?php require("connections/dbconnect.php"); $location = 98; if (isset($_GET['location'])) { $location = $_GET['location']; } function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",'&#39;',$xmlStr); $xmlStr=str_replace("&",'&',$xmlStr); return $xmlStr; } // Select all the rows in the markers table $query = "SELECT * FROM locations WHERE locations.id_location = '$location'"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Start XML file, echo parent node echo '<markers>'; // Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo '<marker '; echo 'id="' . $row['id_location'] . '" '; echo 'name="' . parseToXML($row['name']) . '" '; echo 'info="' . parseToXML($row['info']) . '" '; echo 'lat="' . $row['lat'] . '" '; echo 'lng="' . $row['lng'] . '" '; echo 'county="' . $row['county'] . '" '; echo 'type="' . $row['type'] . '" '; echo '/>'; } // End XML file echo '</markers>'; ?> The javascript // JavaScript Document var customIcons = { River: { icon: 'http://localhost/fishfinder/images/river-map-icon.png', shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' }, Lake: { icon: 'http://localhost/fishfinder/images/lake-map-icon.png', shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' }, Sea: { icon: 'http://localhost/fishfinder/images/sea-map-icon.png', shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' } }; function load() { var map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(53.252069, -3.427734), zoom: 6, mapTypeId: 'satellite' }); var infoWindow = new google.maps.InfoWindow(); // Change this depending on the name of your PHP file downloadUrl("process-markers-location-details-xml.php", function(data) { var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var id = markers[i].getAttribute("id"); var name = markers[i].getAttribute("name"); var info = markers[i].getAttribute("info"); var county = markers[i].getAttribute("county"); var type = markers[i].getAttribute("type"); var point = new google.maps.LatLng( parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var html = "<table cellpadding='3' cellspacing='3' valign='top'>" + "<tr bgcolor='#4F649D'><td colspan='2'><h2 style='color:#FFF; margin-left:15px;'>Location Details</h2></td></tr>" + " <tr bgcolor='#4F649D'><td colspan='2'></td></tr>" + "<tr>" + " <td width='1' align='left' valign='top' bgcolor='#F2F2F2'><strong> Name: </strong><a href='location-details.php?location=" + id + "&" + name + "'></a></td>" + "<td width='277' align='left' valign='top' bgcolor='#FFFFFF'><a href='location-details.php?location=" + id + "&" + name + "'>" + name + "</a></td>" + " </tr>" + " <tr>" + " <td colspan='2' align='center' valign='top'><img src='images/default-location-image.jpg' width='320' height='120' alt='' border='0'/></td>" + " </tr>" + "<tr>" + " <td align='left' valign='top' bgcolor='#F2F2F2'><strong style='font-size:14px;'> info:</strong></td>" + " <td width='277' align='left' valign='top' bgcolor='#FFFFFF'>" + info + "</td>" + " </tr>" + "<tr>" + " <td align='left' valign='top' bgcolor='#F2F2F2'><strong style='font-size:14px;'> area:</strong></td>" + " <td width='277' align='left' valign='top' bgcolor='#FFFFFF'>" + county + "</td>" + " </tr>" + "<tr>" + " <td align='left' valign='top' bgcolor='#F2F2F2'><strong style='font-size:14px;'> type:</strong></td>" + " <td width='277' align='left' valign='top' bgcolor='#FFFFFF'>" + type + "</td>" + " </tr>" + "</table>"; var icon = customIcons[type] || {}; var marker = new google.maps.Marker({ map: map, position: point, icon: icon.icon, shadow: icon.shadow }); bindInfoWindow(marker, map, infoWindow, html); } }); } function bindInfoWindow(marker, map, infoWindow, html) { google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); }); } function downloadUrl(url, callback) { var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest; request.onreadystatechange = function() { if (request.readyState == 4) { request.onreadystatechange = doNothing; callback(request, request.status); } }; request.open('GET', url, true); request.send(null); } function doNothing() {}
  5. Thanks for your reply. Have always used dreamweaver to do this kinda thing but, wanted to try and code it myself to get a better understanding of how PHP & mysql works. Maybe I should just use the bloated DW code for now.
  6. ok thanks, done that and got this: resource(5) of type (mysql result)
  7. Thanks guys for your replies I`m still fairly new to PHP and do not know how to check, tried echo $sql; and it displayed the SELECT. The funny thing is, the form seems to work fine.
  8. Hi guys, need some help with a registeration page i`m creating. I was following and all seems to work fine however, i`m getting the following error message: Here is my code: <!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=utf-8" /> <title>Untitled Document</title> </head> <body> <?php include("connections/connection.php"); $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $passwordconfirm = $_POST['passwordconfirm']; // Prevent SQL Injections $username = mysql_real_escape_string(stripslashes($username)); $email = mysql_real_escape_string(stripslashes($email)); $password = mysql_real_escape_string(stripslashes($password)); $passwordconfirm = mysql_real_escape_string(stripslashes($passwordconfirm)); // Get all users from database. $sql = "SELECT * FROM user"; $resultCount = mysql_query($sql, $cn) or die(mysql_error($cn)); // Check how many users were returned from query above. $num_users = mysql_num_rows($resultCount); // Check each username to see if in use. $row_count = -1; while ($row_count < $num_users) { $data = mysql_fetch_object($resultCount); $row_count++; if ($data->username == $username) { echo '<p>The username "' . $username . '" is not available.</p>'; $row_count = $num_users; } else if ($row_count == $num_users) { echo '<p>The username "' . $username . '" has been selected.</p>'; if ($password != $passwordconfirm) { echo '<p>Passwords do not match.</p>'; echo '<p><strong>New user has not been created.</strong></p>'; } else { echo '<p>Passwords match.</p>'; $datejoined = time(); $sql = "INSERT INTO user (username, email, password, datejoined, userlevel, active) VALUES ('" . $username . "', '" . $email . "', '" . $password . "', '" . $datejoined . "', '1', '1')"; $result = mysql_query($sql, $cn) or die(mysql_error($cn)); echo "<p><strong>The username '" . $username . "' has been created. Please login <a href='login.php'>here</a>.</strong></p>"; } } } ?> </body> </html> Any help would be great, as i`m exhausted looking for a solution. Thanks
  9. not sure how to impliment that, if you have the time an example would be great
  10. Have tried to do this myself all day now and i`m getting a little frustrated now. I have a contact form with a select box which can have multiple options selected, i`m using formmail.php to process the info. Problem is I have forgot how to list the values within the array and format them within the email body. $licences is the multiple select box any help would be gratefully received!! <?php $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $town=addslashes($_POST['town']); $phone=addslashes($_POST['phone']); $licences=addslashes($_POST['licences']); $message=addslashes($_POST['message']); // you can specify which email you want your contact form to be emailed to here $toemail = "admin@mysite.com"; $subject = "Question : mysite.com"; $headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n"; $body = "Name: ".$name."<br>\n" ."Email: ".$email."<br>\n" ."Town/City: ".$town."<br>\n" ."Phone: ".$phone."<br>\n" ."Interested in Licence/s: ".$licences."<br>\n" ."Message:<br>\n" .$message; if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) { echo "That is not a valid email address. Please return to the" ." previous page and try again."; exit; } mail($toemail, $subject, $body, $headers); echo "Thanks for submitting your message."; ?>
  11. Been playing with the code again and so far, it checks if the checkbox is checked and if so inserts the records, but it's only inserting the FIRST extraName, extraPrice and extraFree record into each row. ///////////////////////////////////////////////////// // Submit to Order Form ///////////////////////////// if (isset($_POST["addtoorderButton"])) { mysql_query("INSERT INTO cart(cookieID, customerID, fooditemID, foodItemName, foodItemPrice) VALUES('$cookieID', '$customerID', '$fooditemID', '$foodItemName', '$foodItemPrice' ) ") or die(mysql_error()); if ($_POST['checkbox'] != NULL) { $cart_id = mysql_insert_id(); echo "Checkboxes: "; print_r ($_POST['checkbox']); foreach($_POST['hextraFree'] as $key2) { $extraFree = $key2; echo "extra free : "; echo $extraFree; echo "<br />"; break; } foreach($_POST['hextraName'] as $key3 => $value3) { $extraName = $value3; echo "extra name : "; echo $extraName; echo "<br />"; } foreach($_POST['hextraPrice'] as $key4 => $value4) { $extraPrice = $value4; echo "extra price : "; echo $extraPrice; echo "<br />"; } foreach($_POST['checkbox'] as $key => $value) { //echo $key; mysql_query("INSERT INTO cartextras(cartID, cookieID, extraName, extraID, extraPrice, extraFree) VALUES('$cart_id', '$cookieID', '$extraName', '$key', '$extraPrice', '$extraFree') ") or die(mysql_error()); } } } ///////////////////////// The output is now: Checkboxes: Array ( [1] => on [6] => on ) extra free : 0 extra name : Bacon extra name : Lettice extra price : 0.80 extra price : 0.10 but it still shows all extras if checked or not. heres the repeat region if it helps. <table width="100%" border="0" cellspacing="6" cellpadding="6"> <tr> <td width="6%"><img src="../images/foodimages/<?php echo $row_rs_fooditem['foodItemImage']; ?>" width="250" height="150" /></td> <td width="94%"><?php do { ?> <table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input <?php if (!(strcmp($row_rs_addedextras['extraFree'],true))) {echo "checked=\"checked\"";} ?> type="checkbox" name="checkbox[<?php echo $row_rs_addedextras['idextra']; ?>]" id="checkbox" /> <label for="checkbox[]"></label></td> <td><?php echo $row_rs_addedextras['extraName'];?></td> <td>£ <?php echo $row_rs_addedextras['extraPrice']; ?></td> </tr> <tr> <td colspan="3"> <input name="hextraName[<?php echo $row_rs_addedextras['extraName']; ?>]" type="text" id="hextraName[]" value="<?php echo $row_rs_addedextras['extraName']; ?>" /> <label for="hextraPrice[]"></label> <input name="hextraPrice[<?php echo $row_rs_addedextras['extraPrice']; ?>]" type="text" id="hextraPrice[]" value="<?php echo $row_rs_addedextras['extraPrice']; ?>" /> <input name="hextraFree[<?php echo $row_rs_addedextras['extraFree']; ?>]" type="text" id="hextraFree[]" value="<?php echo $row_rs_addedextras['extraFree']; ?>" /></td> </tr> </table> <?php } while ($row_rs_addedextras = mysql_fetch_assoc($rs_addedextras)); ?> </td> </tr> </table>
  12. Thanks for your reply, yes its looping around whether or not the checkbox is checked or not. I have been playing around with the code and have nearly got it. I'm trying to filter whether the checkbox has been checked and if so record the extra name, extra price and whether the extra is free or not. Heres what I have, but it's not quite there. ///////////////////////////////////////////////////// // Submit to Order Form ///////////////////////////// if (isset($_POST["addtoorderButton"])) { mysql_query("INSERT INTO cart(cookieID, customerID, fooditemID, foodItemName, foodItemPrice) VALUES('$cookieID', '$customerID', '$fooditemID', '$foodItemName', '$foodItemPrice' ) ") or die(mysql_error()); if ($_POST['checkbox'] != NULL) { $cart_id = mysql_insert_id(); echo "Checkboxes: "; print_r ($_POST['checkbox']); foreach($_POST['hextraFree'] as $key2) { $extraFree = $key2; echo "extra free : "; echo $extraFree; echo "<br />"; foreach($_POST['hextraName'] as $key3 => $value3) { $extraName = $value3; echo "extra name : "; echo $extraName; echo "<br />"; foreach($_POST['hextraPrice'] as $key4 => $value4) { $extraPrice = $value4; echo "extra price : "; echo $extraPrice; echo "<br />"; foreach($_POST['checkbox'] as $key => $value) { //echo $key; mysql_query("INSERT INTO cartextras(cartID, cookieID, extraName, extraID, extraPrice, extraFree) VALUES('$cart_id', '$cookieID', '$extraName', '$key', '$extraPrice', '$extraFree') ") or die(mysql_error()); } } } } } } This is the output, it does insert to the database fine, just too many. Checkboxes: Array ( [1] => on [6] => on ) extra free : 0 extra name : Bacon extra price : 0.80 extra price : 0.10 extra name : Lettice extra price : 0.80 extra price : 0.10 extra free : 1 extra name : Bacon extra price : 0.80 extra price : 0.10 extra name : Lettice extra price : 0.80 extra price : 0.10 I can't figure out how to get it too record extraName, extraPrice, extraFree then insert into database if the checkbox is checked. Hope this makes sense
  13. couldn't edit my post :-\ posted the wrong code sorry here is my updated one. // Submit to Order Form ///////////////////////////// if (isset($_POST["addtoorderButton"])) { mysql_query("INSERT INTO cart(cookieID, customerID, fooditemID, foodItemName, foodItemPrice) VALUES('$cookieID', '$customerID', '$fooditemID', '$foodItemName', '$foodItemPrice' ) ") or die(mysql_error()); if ($_POST['checkbox'] != NULL) { $cart_id = mysql_insert_id(); foreach($_POST['checkbox'] as $key => $value) { //echo $key; mysql_query("INSERT INTO cartextras(cartID, cookieID, extraName, extraID, extraPrice, extraFree) VALUES('$cart_id', '$cookieID', '".$row_rs_addedextras['extraName']."', '$key', '".$extraPrice = $row_rs_addedextras['extraPrice']."', '".$row_rs_addedextras['extraFree']."') ") or die(mysql_error()); } } } I know it has something to do with the checkboxes and how the foreach loops through each of them, but i'm too inexperienced to work it out myself.
  14. Hi guys, forum noob here. I'm very new to php and i'm trying to build a simple food order shopping cart. I'm using DW as a crutch at the moment just to get a feeling of how php works. I have a page where a user can select food extras to add to thier food item using checkboxes. heres the recordset for getting extras. $colname_rs_addedextras = "1"; if (isset($_GET['idfooditem'])) { $colname_rs_addedextras = $_GET['idfooditem']; } mysql_select_db($database_dbconnect, $dbconnect); $query_rs_addedextras = sprintf("SELECT extra.idextra, extra.extraName, extra.extraPrice, addedextras.extraFree FROM addedextras, extra WHERE fooditemID = %s AND addedextras.extraID = extra.idextra", GetSQLValueString($colname_rs_addedextras, "int")); $rs_addedextras = mysql_query($query_rs_addedextras, $dbconnect) or die(mysql_error()); $row_rs_addedextras = mysql_fetch_assoc($rs_addedextras); $totalRows_rs_addedextras = mysql_num_rows($rs_addedextras); Here is the code i'm strugling with. // Submit to Order Form ///////////////////////////// if (isset($_POST["addtoorderButton"])) { mysql_query("INSERT INTO cart(cookieID, customerID, fooditemID, foodItemName, foodItemPrice) VALUES('$cookieID', '$customerID', '$fooditemID', '$foodItemName', '$foodItemPrice' ) ") or die(mysql_error()); if ($_POST['checkbox'] != NULL) { $cart_id = mysql_insert_id(); foreach($_POST['checkbox'] as $key => $value) { $extraName = $row_rs_addedextras['extraName']; $extraPrice = $row_rs_addedextras['extraPrice']; $extraFree = $row_rs_addedextras['extraFree']; //echo $key; mysql_query("INSERT INTO cartextras(cartID, cookieID, extraName, extraID, extraPrice, extraFree) VALUES('$cart_id', '$cookieID', '$extraName', '$key', '$extraPrice', '$extraFree') ") or die(mysql_error()); } } } The code kinda works, I just can't figure out how to add the extraPrice and extraFree also. Any kind of guidence would be very apprieated as I have been trying to figure this out for a couple of days now, wanted to figure it out by myself because I think to learn faster that way.
×
×
  • 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.