Everything posted by gadgetgirl
-
custom function causes use of undefined constant
Have you tried testing your mysql query in something like mysql workbench or phpmyadmin? I have a feeling you don't need the single quotes around the $arg variables in the query statement.
-
guestbook for my webpage
If you want something quick your best bet is to google around for something pre built to slot in. The question is actually how much you want to learn and put into learning and how much you are already know. If you know about programming you can skip the initial chapters and start with the ones on MySQL. You can try diving straight into one of the example chapters and then go back to the chapters that cover any bits you don't understand. The good thing about this book is every chapter teaches you new concepts and techniques and new php functions.
-
guestbook for my webpage
To create a guestbook which stores the data in a database you will need to learn a database design, a database language such as MySQL and a server side language such as PHP. There are loads of online tutorials as well as books to teach you what you need to know and many have associated forums. I second what D4YO said about being careful of which ones you follow. Look for newer ones that use the newer mysqli extension or PDO class as older ones use functions that are deprecated and soon to be removed from the support list. I've found Larry Ulllman's books very good - you could probably start with PHP and MySQL for Dynamic Websites. At the end of that book you will definitely be able to build what you want and a whole lot more.
-
What is Key and value pair in web programming
In what context? In an array, the key is the name or index of the element and the value is what is stored in that element. You use the key to access the value. For example using a numerically indexed array $days = array(1=>'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); echo '<p>the 6th day of the week is ' . $days[6] . '</p>'; and for an associative array $person=array('fname'=> 'John', 'lname'=>'Smith', 'email'=>'johnsmith@aol.com', 'nationality'=>'American'); echo $person['fname'] . ' is ' . $person['nationality'];
-
Open Link In New Window
In your a tag, you could include the target="blank" parameter.
-
Convert Date (String) to new Date Format
mysql has a date_format function which converts the date directly, I'm not sure if mssql has a similar function. PHP has a bunch of date/time functions - you can look them up in the php manual. I think you'll need to convert the date to a unix timestamp and then convert it to your required format. Assuming $date is the date you've retrieved, you could do something like $formatted = strftime('%Y-%m-%d %H:%M:%S', strtotime($date));
-
PHP to echo out files as files
The reason you're not getting the error on line 116 anymore is because I fixed your code but you haven't sorted the single/double quotes. Single quotes displays everything literally, double quotes substitutes the value in place of the variable. echo '$thumbs'; will output $thumbs echo "$thumbs"; will output thumbnails Use the code I supplied, run it in your browser and look at the source code. If the images don't appear its because your file structure is in error. Do you really need the paragraphs because there's alot wrong with that bit of code. If you do need it, learn about arrays and offsets and how to access individual elements in an array.
-
PHP to echo out files as files
Which is line 116? The line below has the single and double quotes mixed up and some syntax errors: echo ' <div class=\"galleryItem\"> \"<a class=\"fancybox\" rel=\"group\" href=\"images/$base/$file\"><img src=\"$base/$thumbs/$file\" alt=\"\"/></a>"; </div>' try changing it to echo " <div class=\"galleryItem\"> <a class=\"fancybox\" rel=\"group\" href=\"images/$base/$file\"><img src=\"$base/$thumbs/$file\" alt=\"\"/></a> </div>"; Is $paragraph defined as an array earlier on? otherwise this line will fail if ($paragraph[$i]) See if the above helps, otherwise could you be more specific about the error you're getting.
-
Create pages for users when they register
You will need to add a mod_rewrite rule to your .htaccess file. It looks more complicated than it actually is. There are various online tutorials which will explain the concept and technique.
-
Help with Php Signup Form!?
The tutorial referenced is a decent starting place to give you an overview of what is required to process a form, validate the data, insert to a d/b and send an email but it is nearly 4 years old and using deprecated functions. First and foremost - don't use the mysql functions, PHP 5.5 is now out and soon mysql functions will not be supported. Learn the mysqli extension or even better learn the PDO class. Since you're new to this, you might as well learn techniques which have a future. Secondly, look up PHP's filter functions for validation. They are more secure and make validation easy, particularly email addresses and urls. You can find these functions and a lot more in the php manual. If you have any specific questions on any of these functions, post them here.
-
PHP - News article page info grab from template?
You need a way to programmatically let news.php know which article to display. One way is to append the id of the particular article in the url e.g. news.php?id=1. news.php can access the id via $_GET. How/where will your site do this? Setting up and accessing a database is not difficult but will require a little learning. If you data is complicated designing the d/b can be challenging but if you just require a table for your articles, it is straightforward. The alternative is to learn the php functions to get and retrieve data from another file. Finally if you want nice urls like news.php/article1 as opposed to urls like news.php?id=1, you will need to include some mod_rewrite rules in your .htaccess file. Again this is not too difficult but will require some more learning.
-
PHP - News article page info grab from template?
if I understand what you are trying to do, you basically need to code up your own template and insert the article. Will you be storing your articles in a database? Your news.php script will be structured something like this <?php include('header.html'); include('sidebar.html'); //get article from database // display article include('footer.html'); ?> If you have a list of article titles on another page and you want to link to the full article, your a tag should reference the above page along with the id of the article. <h2>Recent Articles</h2> <ul> <li><a href="news.php?id=1">Title of Article 1</a></li> <li><a href="news.php?id=2">Title of Article 2</a></li> <li><a href="news.php?id=3">Title of Article 3</a></li> </ul> At the top of news.php you will access the id of the article using the $_GET global. $id = (isset($_GET['id']) && ctype_digit($_GET['id'])) ? $_GET['id'] : false; This is a ternary statement which is a succinct if else statement made up of the following 3 parts: (isset($_GET['id']) && ctype_digit($_GET['id'])) says if $_GET['id'] exists and is of type integer; ? $_GET['id'] says if the if statement is true set $id equal to $_GET['id']; : false - is the else part of the if statement - if the if statement is false set $id equal to false; news.php can then check if $id is false and do some error processing otherwise get the article from the database using $id
-
baseURL - php include code from seperate document
One way is to have a config file (config.inc.php) that is included by all scripts that will define all your helper functions and site constants. In that file define your base url and base uri constants define ('BASE_URI', '/home/example/'); //remote path to root folder define ('BASE_URL', 'http://www.example.com/'); //live url //define ('BASE_URI', '/Applications/MAMP/htdocs/example/'); //local path to root folder //define ('BASE_URL', 'localhost/example/');//local url Then your include can be something like include(BASE_URI . 'assets/subbar.php'); Be sure to comment / uncomment out the 2 lines depending on whether you're working locally or remotely
-
Contact form php script build.. help?
You really want to do some validation on the form data. Look up php's filter_var - it makes validating email addresses easy. You will also want to ensure that your required fields are filled in, do some anti-spam processing and display helpful error messages. Look up htmlspecialchars() and strip_tags(). As coded, you won't get the expected results because you've used $_POST['email'] and $_POST['email_address']. $_POST['email'] will never exist the way you've coded your form. One other thing, its bad form to use uppercase for variables.
- NEED HELP! Contact From PHP
-
php html template called to page - navbar query
Sorry got distracted - I'm not completely sure I understand what you are trying to achieve but I think the easiest solution is to add in the classes manually echo '<ul>'; $nav_items = array('index'=>'Home', 'where'=>'Where?', 'appeals'=>'Current Appeals', 'news'=>'Latest News', 'events'=>'Events', 'dontate'=>'Dontate'); $default_subnav = '<a href="/where" class="dropdown-toggle disabled" data-toggle = "dropdown">where?<b class="caret"></b></a>' . "\n". '<ul class="dropdown-menu"><li class="nav-header"> SUBNAV HEADER </li><li class="divider"></li>'; $sub_nav = array( 'africa'=>'Africa', 'bangladesh'=>'Bangladesh', 'gaza'=>'Palestine/Gaza', 'kashmir'=>'Kashmir', 'pakistan'=>'Pakistan', 'uk'=>'United Kingdom' ); foreach ($nav_items as $nav_href=>$nav_title) { if ($nav_href != 'where') { if ($page == $nav_href) { echo '<li class="active"><a href="'. $nav_href . '">' . $nav_title . '</a></li>' . "\n"; } else { echo '<li><a href="'. $nav_href . '">' . $nav_title . '</a></li>' . "\n"; } } else { if ($page == $nav_href) { echo '<li class="active dropdown">' . $default_subnav . "\n"; } else { echo '<li class = "dropdown">' . $default_subnav . "\n"; } foreach ($sub_nav as $sub_item=>$value) { echo '<li><a href="../where/' . $sub_item . '">' . $value . '</a></li>' . "\n"; } echo '</ul></li>'; } } echo '</ul>'; Sorry if I've misunderstood what you are trying to do. btw I think you may have a typo in 'dontate'?
- php html template called to page - navbar query
- NEED HELP! Contact From PHP
- NEED HELP! Contact From PHP
-
php html template called to page - navbar query
You need some nested if statements and another foreach loop. It's not pretty but off the top of my head this should work. The nice thing is if you need to add another menu item, you just add it once to the appropriate array. echo '<ul>'; $nav_items = array('index'=>'Home', 'where'=>'Where?', 'appeals'=>'Current Appeals', 'news'=>'Latest News', 'events'=>'Events', 'dontate'=>'Dontate'); $sub_nav = array( 'africa'=>'Africa', 'bangladesh'=>'Bangladesh', 'gaza'=>'Palestine/Gaza', 'kashmir'=>'Kashmir', 'pakistan'=>'Pakistan', 'uk'=>'United Kingdom' ); foreach ($nav_items as $nav_href=>$nav_title) { if ($nav_href == 'where') { if ($page == $nav_href) { echo '<li class="active">' . $nav_title . '<ul class="dropdown active">'; } else { echo '<li>' . $nav_title . '<ul class="dropdown">'; } foreach ($sub_nav as $sub_item=>$value) { echo '<li><a href="../where/' . $sub_item . '">' . $value . '</a></li>'; } echo '</ul>'; } else { if ($page == $nav_href) { echo '<li class="active">' . $nav_title . '</li>'; } else { echo '<li>' . $nav_title . '</li>'; } } } echo '</ul>'; ?> When you get a chance, spend some time working with arrays and multi-dimensional arrays. Once you get your head round them, they enable you to do some fairly tricky processing with not a lot of coding.
-
Help with code..
Since you haven't used curly braces, php will only execute the first statement. Try this $files = glob("images/assets/*.{png,jpg,jpeg}", GLOB_BRACE); $i = 1; foreach ($files as $file) { echo "<li id:\"S-$i\"><img class=\"zuper\" src=\"$file\" /></li>"; $i++; }
-
php html template called to page - navbar query
Before you start coding you might want to mark up on a piece of paper the aspects of the page that are common to every page, for example Header, Footer and Sidebar. Create 3 files called header.html, footer.html and sidebar.html and insert the relevant code. In each page file you include the template file with the include function: include('views/header.html'); I usually put these files in a different folder so be sure to specify the full path. Your full page will look something like this <?php $page = 'index'; include ('views/header.html'); ?> <div class="some_class"> blah blah blah <p>ipsem lorem</p> </div> <?php include ('views/sidebar.html'); ?> <div class="another_class"> blah blah blah <p>more text</p> </div> <?php include ('views/footer.html'); ?> You can switch between php and html by using the php tags when you want to do some php coding. You will notice that I included a $page variable in the header file. This is to answer your second question. Set that variable in every page before you include the file that displays the navigation. Then when displaying the aspect that you want to have an 'active' class, check the variable first. One way to do navigation is to create an array of nav items and then loop through the array. $nav_items = array('index'=>'Home', 'events'=>'Events' ); foreach ($nav_items as $nav_href=>$nav_title) { if ($page == $nav_href) { echo '<li class="active">' . $nav_title . '</li>'; } else { echo '<li>' . $nav_title . '</li>'; } } Because you have a submenu you will need to have an if statement to cater for that. You should be able to fit that into the above skeleton code. Also with the above, be sure to get your use of single and double quotes correct. There are other ways to achieve the active class situation you're after including setting an id on each page's body tag but I find the above easy.
-
how to customize the search results ?
Your original question was about customising the search results generated by a php script that performed the search. To use CSS to style your page, there are a number of ways to select elements: by type, by class or id, by descendant type, by a combination of the the above. Strictly speaking you do not need to insert any of the classes but doing so makes it easier to target that area, particularly for positioning. h2.search_results will not work in the above example as it is targeting an h2 tag with a class of search_results and in my example I set the h2 to a class of search_title. So you could use h2. search_title or even just .search_title. There could be a number of reasons why your background-image is not appearing, but I would need to know more about the site and file structure. Try some debugging - in the source code, locate the link to the css file and click on it, is it found? You could also try firebug or just right click on the element in firefox to 'inspect the element'. This thread has become more about css than php so you may want to post in the appropriate forum. You may also want to read up a bit more on styling with css - be careful about incorrectly quoting w3schools to someone who has answered your question. btw w3schools doesn't have the best reputation for accuracy and being up to date.
-
how to customize the search results ?
Works for me. Are you using double or single quotes? Which is line 41?
-
how to customize the search results ?
echo " <a href='$url'><h2 class="search_title">$title</h2></a> //use a heading tag instead of b tag, its better markup <p class="search_desc">$desc</p> //p tag instead of br, same as above <a href='$url'>$url</a> //removed what looks like a stray p tag "; In the original code, there was an incorrect use of quotes and I forgot to escape the double quotes. Sorry about that. Change the above to echo " <a href=\"$url\"><h2 class=\"search_title\">$title</h2></a> <p class=\"search_desc\">$desc</p> <a href=\"$url\">$url</a> ";