Jump to content

phpnewby1918

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by phpnewby1918

  1. Hello, i've been making this project in my spare time, haven't looked at it for a while. But i have some spare time so i'm going to dip my toe again. I have been using the following .htaccess rules RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^about/?$ about.php RewriteRule ^about/([A-Za-z\+\-]+)/?$ ./about.php?x=$1 Which achieves what I wanted (initially). In that I wanted to be able to make these URLs: www.example.com/about.php www.example.com/about.php?x=jonathon Become these URLs respectively: www.example.com/about www.example.com/about/jonathon Which once i'd fiddled around and achieved it, I was pretty happy with. Obviosuly this meant some changes to my relative CSS paths, which was a bit fiddly, but I couldn't see a better way around it. Though if you know any good ideas, please let me know. My scenario now is much as I enjoy that these URLs look prettier, there are 2 problems with them. 1 - if someone types www.example.com/about/ for example, the css relative paths fail. So the paages aren't styled. 2 - Also in terms of seo it looks like duplicate content Sooo, my next thought was to automatically append the trailing slash, so that ^about becomes ^about/ and ^about/jonathon becomes ^about/jonathon/ auomatically. Therefore stopping a duplicate content problem and also meaning that my css will render properly. So far reading around the many many articles and examples i've seen before i've come up with this: RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://localhost/www.example.co.uk/$1/ [L,R=301] Which works in that 'about' does indeed become 'about/' and 'about/jonathon' does becomes 'about/jonathon/' Regrettably, I always get a object not found 404 error! Which is not the desired effect, I am not particulary good, (in fact i'm not even remotely good at .htaccess) so can anyone help me out with this conundrum. I have been clearing my browser cache regulary as I tinker with it to make sure that it always using the most up to date .htaccess file. Thanks in advance Jonathon B)
  2. Thanks for your help, i'll look into it Appreciate the response
  3. That my database variable isnt defined. But it is right at the start of the script
  4. Hi, Just a quick query. I call my db connection and configuration files on every script. I also have just made a functions script where i'm storing some functions except when i call the function, my script fails because of a missing database connection. But on the page that fails, i call the configuration files including the db connection at the start of the script. But when i get to where i include the function they are all on the same script so should it fail?? The page did work fine when the function was inbedded in the script. But as i'm using the function on a few pages, i thought it would be better practise and more efficent to just include the function on each page i need, rather than just copy and paste all the php in the required pages. Or do i have to declare the db connection inside the function page as well??? Thanks
  5. Hi thanks for your reply. I went to this option, what do you think of it? I did try yours, but it didnt seem to work - sadly. mine was this: Options +FollowSymLinks RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^about/?$ about.php RewriteRule ^about/([A-Za-z\+\-]+)/?$ ./about.php?x=$1 You clearly know more about Apache than me, so be interested on your take of the code. I'm a newbie to Apache mod_rewrite. Also, can you think of a way to stop my css failing. It works fine on mysite.com/about but when i clcik my link that goes to mysite.com/about/jonathon the CSS fails. I'm running the content for the 'jonathon' variable on the same page as about and i guess the extra '/' after about is making the page think it that the CSS folder (which is in my root) is in the same 'directory' as about. But obviously the fake folder of /about/ isnt anywhere else as its still in the root. I know i could use absolute paths for CSS if all else fails. But i'd just prefer to use relative ones IF possible?? Appreciate anyones help Jonathon
  6. Yeah, I did, it does appear like i have them on. But it still wouldnt work. If i free type in my page using ' or " its fine and inserts fine. Its just when i type in Word it changes ' to some similar but differnet symbol and then it just wont go in??
  7. Looking more into it i type ' into word and it doesnt create a ' it creates a curly single quotation mark. So when i copy if from word into my upload section it treats it as a different charachter to ' adn then the query fails. but i've just gone and chantged the Word instances of the single quotation mark to my keyboard ' single quotation mark and the string inserts all the way up until the next occurance of the word single quotation mark.???? Any ideas?
  8. hi i'm trying to insert this text just "we're pleased to announce etc........ect" but I can only insert "We" i believe its because single quotation mark. I've tried using addslashes, mysqli_real_escape_string and htmlspecialchars, strp_tags and applied it to my variable $s. But what ever i seem to try and insert still results in "we" being inserted. Cant see for the life of me why??? appreciate any help if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['title'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $t = mysqli_real_escape_string($dbc, $_POST['title']); } if (empty($_POST['story'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $s = $_POST['story']; } echo $s; if(empty($errors)) { // No errors $q = "INSERT INTO news (title, story, date_added) values ('$t', '$s', NOW() )"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows == !1) { // It didnt run ok $errors[] = '<p class="error">An error occured with your upload<a href="loggedin.php"> Admin</a></p>'; } else { echo 'Your news story has been added, visit <a href="news.php">News</a>'; } //if mysqli_affected rows } else { echo '<p class="error">The following errors occured<br />'; foreach ($errors as $msg) { echo " - $msg<br>"; } echo 'Please try again'; } // end of $errors } // End of submitted This is my code i'm using :-) as you an see i'm posting the variable $s which is ($_POST['story'] with no functions and it still only inserts "we" nothing more?????
  9. Hi, I've been looking into the apache mod_rewrite for quite a few days now, but i can't seem to get it to work. I have read around a lot tyring to understand it more. I believe my server does allow the rewrite as i did: RewriteRule ^somepage.html somepage.php And that worked fine. I am trying to rewrite URL so its prettier for this page. I wanted to start of with a basic (if there is a basic one) I have a page called 'about.php' where i pass a get variable to recall a more in depth article from the introductory text on about.php. for example about.php?x=jonathon goes into more depth about 'jonathon' I would as one could imagine like to rewrite this URL so that it looks like: about/jonathon/ So i have tried this .htaccess rule: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteRule ^about/([A-Za-z\+]+)/ about.php?x=$1 [NC] </IfModule> But nothing changes in my url. I have had quite a lot of attempts at this, unfortuantely to no avail and read many articles and guides Could someone show me the error of my ways please Any help very appreciated Jonathon
  10. Thans for both of your help, some nice code you both use
  11. Thanks litebearer, I think that codes a lot cleaner than mine and i will encorporate into my future scripts.
  12. Thanks for your help, Its appreciated. I'm not sure that array_splice would give me the results I wanted though? Please correct me if i'm wrong. I'm exploding part of my content per story. So i have my title, then 90 words of content that i use to echo out as an intro so to speak and a link to view the fuller article. I had never thought to close the php tags then code php inside the html. So its been a good example or alternative, so thanks :-)
  13. Hello, I just wanted to run over some code i'm using to loop through for a page. And wanted people critique on it really. It is a bit messy i feel trying to include all the html tags inside the loop in order for me to achieve the page look i want and whilst maintaining to xhtml standards. Would any one please take a look at my code which works and tell me how they would do it or if its done badly as i'm interested to know $q = "SELECT title, content, get, link FROM content WHERE page='index'"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h2>'; // print for start of H-tag echo $row['title']; // print title inside H-tag echo '</h2><p>'; // close H-tag, line break, start of P-tag $get = $row['get']; $link = $row['link']; $content = $row['content']; $content = explode(' ', $content); $y = 90; $x = 0; while ($x < $y) { echo $content[$x].' '; // print content inside P-tag $x++; } // end of content echo '</p><a href="seo.php?x='; // close P-tag, start A-Tag print link echo "$get"; // $_GET[''] echo '">read more...&#187;&#187;</a>'; // close url start the anchor text and close off </a> } // End of while echo '</div>'; // End of left content echo '<div class="right">'; // Start of right div echo '<h2>News</h2>'; // News title I'd appreciate any feed back from more experienced users/coders Thank you in advance :-)
  14. Hello, I'm very new to working with images and headers, i've never done it at all even. But i've been trying to make a gallery its got about 150 photos in it. And i know there are much better ways than me resizeing and saving 150 thumbs. So ive tried to research and implement a code to make this so i can recall the original images url from a database and this will be the end viewable picture. And use php to create a thumbnail from the original, and then make that a link so it moves onto a lightbox viewer. this is the code i've got so far, i'm having problems with the headers. I know that they must be put first but when i move the header to the start of file it still errors. I'd really appreciate any help that people would be willing to give <!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 content="text/html; charset=utf-8" http-equiv="Content-type" /> <title></title> <link rel="alternate" type="application/rss+xml" title="" href="http://www.loukafinefinish.com/rss.xml" /> <link rel="stylesheet" type="text/css" href="css/portfolio.css" /> <link rel="stylesheet" type="text/css" href="css/portfolio_image.css" /> <script type="text/javascript" src="js/cufon-yui.js"></script> <script type="text/javascript" src="js/arial.js"></script> <script type="text/javascript" src="js/cuf_run.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/portfolio.js"></script> <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script> <link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" /> <script type="text/javascript"> $(function() { $('.thumb a').lightBox(); }); </script> <style type="text/css"> /* Reset CSS */ html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, pre, code, address, variable, form, fieldset, blockquote { padding: 0; margin: 0; font-size: 100%; font-weight: normal; } table { border-collapse: collapse; border-spacing: 0; } td, th, caption { font-weight: normal; text-align: left; } img, fieldset { border: 0; } ol { padding-left: 1.4em; list-style: decimal; } ul { padding-left: 1.4em; list-style:square; } q:before, q:after { content:''; } /* End of CSS Reset*/ </style> </head> <body> <div id="content-wrapper"> <div id="header"> <h1><a id="logo" href="index.html"><span>Carpentery</span></a></h1> </div> <div id="navigation"> <div class="menu_nav"> <ul> <li><a href="index.html">Home</a></li> <li><a href="services.htm</ul> <--header above etc--> <?php echo '<div class="container"> <ul class="thumb">'; require_once('include/connect.php'); $display = 5; // Number of results if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Determine number of pages $pages = $_GET['p']; } else { // Need to determine $q = "SELECT COUNT(id) FROM portfolio"; $r = @mysqli_query($dbc, $q); $row = @mysqli_fetch_array($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if($records > $display) { // More than 1 page $pages = ceil($records/$display); } else { $pages = 1; } } // End IF if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Query $q = "SELECT imageUrl FROM portfolio ORDER BY id LIMIT $start, $display"; $r = @mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $filename[] = $row['imageUrl']; foreach ($filename as $url) { // The file $filename = $url; // Set a maximum height and width $width = 100; $height = 100; header('Content-type: image/jpeg'); // Header is here for my example, but i have tried // placing it at the top of my page // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); echo '<li><a href=' . $row['imageUrl'] . '>' . imagejpeg($image_p, null, 100) . ' </a>'; } // End of FOR } // End while echo '</ul>'; // End of list of images mysqli_free_result($r); mysqli_close($dbc); if ($pages > 1) { // Make page links echo '<br /><p class="pagination">'; $current_page = ($start/$display) + 1; // What page script is on if($current_page != 1) { // Make previous button echo '<a href="portfolio.php?s=' . ($start - $display) . '&p=' . '">Previous</a> '; } // Make all the pages numbered for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="portfolio.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // END of FOR loop // If no last page, make net button if ($current_page != $pages) { echo '<a href="portfolio.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; } // End page links ?> <!--Footer etc--> </html> This is my overall page, but as the page had some html involved i thought it best to post some of it. I'm not convinced at all that my method for iterating through the database for the image urls allows me to then iterate this into the $filename for the image resize. If any one could help i'd appreciate it Thank you
  15. Hello, I've been following google maps with php/mysql turorial http://code.google.com/apis/maps/articles/phpsqlajax.html I've come to my phpsqlajax_genxml.php file which as the google code has it like this: <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $doc = domxml_new_doc("1.0"); $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("marker"); $newnode = $parnode->append_child($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> I started with this but was getting errors at line 1!! I looked around abit on the net and found i should change $doc = domxml_new_doc("1.0"); to this $doc = new DOMDocument('1.0'); Then i got errors abour creating the elements, i looke on php.net and it looked like i needed to change $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); $newnode->set_attribute("name", $row['name']); To this: $node = $doc->createElement('markers'); $parnode = $doc->appendChild($node); $newnode->setAttribute ('name', $row['name']); This at least got my code further down the page until the very last statment: $xmlfile = $doc->dump_mem(); Here i'm getting this error "Fatal error: Call to undefined method DOMDocument::dump_mem()" along with "Warning: Cannot modify header information - headers already sent" I havent even looked at the warning i just tried to fix the fatal error. Again i looked around the web and forums and php.net and thought maybe i need to set the value to "true" but it still got a fatal error. I looked on php.net and in there examples for dump_mem() and they had the nodes set_attribute create_element and append_child. Which confused me as that was what i used originally just following the google script and that got me the error right away "Fatal error to undefined method DOMDocument::create" Can anybody point out whats going wrong? This is my script that I am using <?php require('connect.php'); ?> <!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 content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>phpsqlajax_genxml.php</title> </head> <body> <?php // Start XML file, create parent node $doc = new DOMDocument('1.0'); $node = $doc->createElement('markers'); $parnode = $doc->appendChild($node); // Select all rows in markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die ('Invalid query: ' . mysql_error()); } header('Content-type: text/xml'); // Iterate through the rows, addind xml nodes for each while ($row = mysql_fetch_assoc($result)) { // Add to XML document node $node = $doc->createElement('marker'); $newnode = $parnode->appendChild($node); $newnode->setAttribute ('name', $row['name']); $newnode->setAttribute ('address', $row['address']); $newnode->setAttribute ('lat', $row['lat']); $newnode->setAttribute ('lng', $row['lng']); $newnode->setAttribute ('type', $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> </body> </html> And the google code is on the link in posted in the messge also but this is theres both of which fail for Fatal errors either on the dump_mem() or new DOMDocument respecitvaley : <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $doc = domxml_new_doc("1.0"); $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("marker"); $newnode = $parnode->append_child($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> Thanks to anybody who can help me out
  16. Thanks for your idea Vistar86 i tried it as you said and I thought it had worked. I needed to remove the mysql_close statement first because i was getting warning messages. It worked fine when the dates matched and there was no need to update... but... However, when the dates don't match and i need to update the database it updates it with TWO identical rows now. (I do appreciate your effort though) I can still run the "Hello" underneath it which i suppose it something.
  17. Hi I'm firstly sorry about this because i literally don't know what i've done to stop my php working past a point on my xampp. I have been just fiddling around and now i cant get it to even echo out 'Hello' any more (After i've executed a piece of code) I know its something in the script above because when i '/*' it out it ran my code below it, which was just recalling mysql db info, it worked fine. I've since removed this lower peice of code as i wasnt sure if it was a problem with calling to the database or php itself. But it seems to be php itself as you'll be able to see i've just asked it to echo out hello and the won't even do that. I'm sure its really simple but one of those things where you cant see the woods for the trees. Here is my code: <?php require("connect.php"); ?> <?php $extract = mysql_query ("SELECT * FROM rss"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $dbto = $row['to']; $from = $row['from']; $heading = $row['heading']; $body = $row['body']; $dbdate = $row['date']; } $columns = array(); $data = array(); $xml = simplexml_load_file("test.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; $columns[] = $child->getName(); $data[] = (string)$child; } $col = '`'. implode('`,`',$columns) .'`'; $val = "'". implode("','",$data)."'"; if ($data[4]==$dbdate&&$dbto==$data[0]) die ("No need to update this record"); else { $query = "INSERT INTO rss ($col) VALUES ($val)"; mysql_query($query); echo "Record updated"; } ?> <?php echo "Hello"; ?> </p> </body> and this is what is outputted: I'd be very greatful of anyhelp.
  18. Wow, Thank you very much. I don't think i'd ever have been able to come to that soultion on my own. But i'm really greatful for you showing me how. Thanks
  19. HI i've been looking over this for a few days and its blagging my head in adn wondered if anyone could help me. I've been using this xml from w3schools: <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Dont forget me this weekend!</body> </note> and used this script to display the data: <?php $xml = simplexml_load_file("test.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } ?> This is all very good and i follow it fine. But the trouble i'm having is how to put this data into my mysql db. I've set up a mysql table with these columns: id (Auto increment) to from heading body Unfortunately all i've managed to do so far is get each $child put into every column 4 times aka id to from heading body 1 Tove Tove Tove Tove etc etc etc etc etc I've read actually quite alot around it but i couldnt find anything that i could pick up particulary easily, including php.net. So i wondered if someone may be able to show me how i can insert that simple xml file into my database. I was hoping to get this in my database: id to from heading body 1 Tove Jani Reminder Dont forget me this weekend! I realise this may be a silly question, but i have really tried to do it for like 5 days now and i keep making a mess of it. Thanks in Advance
  20. Hi, I'm trying to broaden my scope with RSS feeds. Basically I want to be able to pull data from an RSS feed from either somewhere big like BBC or even a friends site but then be able to input this data into a mysql database. I do know there is a program RSS2MYSQL (I think) But i'd like to learn the script behind it. If i take the this script from w3schools shown below: XML FILE: <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> And then use this code to echo the data out (Shown below): <?php $xml = simplexml_load_file("test.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } ?> Obviosuly this works great but i'm then unsure how i'd be able to add this data into my database. Could anybody help me out with how i'd go about doing this please? Thanks
×
×
  • 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.