Jump to content

JavaScript Beginners


AndyB

Recommended Posts

Would you have any advice on how:

-I could make the sites suitable to show at an interview

-A web agency will critique the work and what they are looking for in an applicant's work to decide if he/she may be a suitable candidate.

Probably your first step is to do some research -- find some job postings for the type of job you are looking for, and see what they are expecting. Perhaps even calling them up and asking directly would be a good option.

 

I'm assuming at the least they will be expecting a solid understanding of HTML and CSS, and probably a bit of Javascript would be helpful. What you'll be asked to do really depends on the job... but I'm assuming they would want to see clean, valid, easy to understand code that shows your expertise with HTML/CSS. Modifying existing HTML/CSS templates probably isn't going to cut it -- if they are hiring you to code websites, they'll expect you to understand how to do that from scratch. I'd also guess that you'd need to have an understanding of how to deal with inconsistencies between browsers.

Link to comment
Share on other sites

Hello Ben,

 

 

I hope you're OK and that your work is going well too.

I have a couple of queries I was hoping you might be able to help with.

 

I use Just Host as my Web Host and wamp as my local web server.

1)Have you come across the xamp or mamp local web servers and how would they compare to wamp?

 

2)How would you rate Expression Engine as a CMS in comparison to WordPress or Drupal?

 

Many thanks in advance for your insights Ben,

Regards,

Andrew.

 

Link to comment
Share on other sites

1 - MAMP is basically the same thing as WAMP, but for the Mac ("M") rather than Windows ("W"). At least in my view, WAMP and XAMPP do basically the same thing and work about the same way, so I wouldn't really say that one is better than the other.

 

2 - I haven't personally worked with Expression Engine yet, but I've heard a lot of good things about it. In most cases, the cost has discouraged me from using it in the past. A lot of web designers/developers use it exclusively, and it's supposed to be very customizable and has a pretty good support community.

Link to comment
Share on other sites

Hello Ben,

 

Thanks for your reply to my last post and making the WAMP/MAMP/XAMPP distinction clearer.

My query today is about backing up files.

I've come across the SVN(Subversion?) system to maintain files and source code while looking into backing up my own files.

1) Is SVN the software that maintains the source code for a Word Press site?

2) What is the difference between SVN and GIT?

 

Many thanks in advance for your reply Ben,

Regards,

Andrew.

Link to comment
Share on other sites

Yes, Wordpress uses Subversion for version control. http://codex.wordpress.org/Using_Subversion

 

Ultimately, SVN and Git do about the same thing -- keep records of file changes, and allow users to save/edit/delete those changes. It's useful when multiple people are working on the same files, since it can merge changes together and sort out confilts, and it's also pretty useful when working on a large project, since you can easily roll back changes to previous versions. At the moment, SVN is out of style/considered old by many people, and Git (and the free GitHub service) is increasing in popularity.

 

The main difference between Git and SVN is that Git is considered to be "distributed version control" whereas SVN is "centralized version control." See http://thinkvitamin.com/code/why-you-should-switch-from-subversion-to-git/ and I'm sure you can find other resources online with a little Google searching.

Link to comment
Share on other sites

Hello Ben,

 

Thanks for your reply to my last post about PHP files.

I've spent a little time fixing my new template so here it is at:

 

www.spintheclock.com

 

I previously had a WP template which I changed to Woo Themes.

In so doing, many of my settings have been changed.

There's that tab that says:"No Categories" .

Previously,it was named "Stories" and had content .

At the top, "Home", "About" and "Contact/Links " are correct .

However,the remainder of the entries were hyperlinks in a drop down list as they were stories.

And the drop down list was in the tab that now says "No Categories."

My query today is:

How can I write code to put the stories back into a list of hyperlinks in that tab that now says "No categories"?

 

Many thanks in advance for your help Ben,

Regards,

Andrew.

 

 

 

Link to comment
Share on other sites

Hello Ben,

 

For further clarification, this is the code that I had in my "Stories" tab,which was a page in "Editor" mode, prior to the template change.

 

<?php

global $post;

$myposts = get_posts( 'offset=4&post_type=page&order=asc' );

?>

 

<ul>

<?php foreach( $myposts as $post ) : setup_postdata($post); ?>

<?php $url = substr_replace(get_permalink(), '#', strrpos(get_permalink(), '/')+1, 0); ?>

<li><a href="<?php echo $url; ?>"><?php the_title(); ?></a></li>

<?php endforeach; ?>

</ul>

 

But now as you can see, when you click on the hyperlinks, they only invariably display the "Home" page.

Also, the "Comments" and "Posts" links don't display the correct content.

 

To sum it up:

1) How can I get the stories to display from the "Stories" tab only and not be on the top menu?

2) How can I remove the extra "Home" link?

3) How can I remove the "No Categories" tab?

4) How can I re-enable the "Posts" and "Comments" links?

 

Your help would be greatly appreciated yet again Ben,

With thanks,

Andrew.

Link to comment
Share on other sites

1) I believe the items in the top menu are simply listing all pages within the site. You probably can't fix this without changes to the theme itself -- probably changes to the header.php file. I'd suggest looking at Wordpress's navigation element, which allows you to customize what pages are shown. http://codex.wordpress.org/Function_Reference/wp_nav_menu

 

2) I'm not sure... It really depends how you have Wordpress set up. If the theme uses a navigation menu that can be controlled via Appearance > Menus, you should be able to remove the second home menu using the Wordpress interface. If it doesn't use a wordpress menu, and simply lists all pages, then you may need to modify the header.php file.

 

3) Again, this would require editing your header.php file.

 

4) Those links point to the RSS feeds for recent posts and comments. They are displaying the way they are supposed to.

 

In regards to the code that you posted... I'm not sure what that code was used for originally... However, this line:

 

<?php $url = substr_replace(get_permalink(), '#', strrpos(get_permalink(), '/')+1, 0); ?>

modifies the URL so that it points to an anchor ("#") rather than a real link. If you want those links to point to the right pages, use this:

 

<?php 
global $post;
$myposts = get_posts( 'offset=4&post_type=page&order=asc' ); 
?> 

<ul>
<?php foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

I can't test this, but I believe this should work to change the links to link to the correct pages rather than the "#" version that links back to the home page.

Link to comment
Share on other sites

Hello Ben,

Thanks a lot for your reply to my last post.

Honestly, your insight was flawless, it was all down to re-writing the code in the header.php template.

We had my wife's cousins who are from East Stroudsberg,Pennsylvania visit us for Thanksgiving in the last couple of days.

To make a long story short, one of them, Sidney, works in Web development.

It was the strangest of coincidence but we ended up talking about design, a thing led to another and he decided to tinker away with the site code.

It was very lucky for me because I struggle a lot with PHP with which I'm not fluent at all.

Anyway,these are the changes he implemented on the basis of your code.

So thanks again for your insight Ben.

www.spintheclock.com

 

 

 

<!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 profile="http://gmpg.org/xfn/11">

 

 

 

<title><?php woo_title(); ?></title>

 

<?php woo_meta(); ?>

 

 

 

<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen" />

 

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php if ( get_option('woo_feed_url') <> "" ) { echo get_option('woo_feed_url'); } else { echo get_bloginfo_rss('rss2_url'); } ?>" />

 

<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

 

 

 

<?php wp_head(); ?>

 

<?php woo_head(); ?>

 

 

 

</head>

 

 

 

<body <?php body_class(); ?>>

 

 

 

<?php global $woo_options; ?>

 

 

 

<div id="background">

 

 

 

<div id="top">

 

<div class="col-full">

 

 

 

<?php

 

if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) {

 

wp_nav_menu( array( 'depth' => 3, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_class' => 'nav1', 'theme_location' => 'primary-menu' ) );

 

} else {

 

?>

 

<ul class="nav1">

 

<?php

 

if ( get_option('woo_custom_nav_menu') == 'true' ) {

 

if ( function_exists('woo_custom_navigation_output') )

 

woo_custom_navigation_output('name=Woo Menu 1&depth=3');

 

 

 

} else {/* ?>

 

<li <?php if ( is_home() ) { ?> class="current_page_item" <?php } ?>><a href="<?php echo get_option('home'); ?>/"><?php _e('Home', 'woothemes'); ?></a></li>

 

<?php wp_list_pages('sort_column=menu_order&title_li=&depth=3'); ?>

 

<?php*/ } ?>

 

</ul>

 

<!--/nav1-->

 

<?php } ?>

 

 

 

<div class="subscribe">

 

<?php _e('Subscribe:', 'woothemes'); ?>

 

<a class="posts" href="<?php if ( get_option('woo_feed_url') <> "" ) { echo get_option('woo_feed_url'); } else { echo get_bloginfo_rss('rss2_url'); } ?>"><?php _e('Posts', 'woothemes'); ?></a>

 

<span class="sep">|</span>

 

<a class="comments" href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments', 'woothemes'); ?></a>

 

<?php if (get_option('woo_subscribe_email') != "") { ?>

 

<span class="sep">|</span>

 

<a class="email" href="<?php echo get_option('woo_subscribe_email'); ?>" target="_blank"><?php _e('Email', 'woothemes'); ?></a>

 

<?php } ?>

 

</div>

 

 

 

<div class="fix"></div>

 

 

 

</div><!-- .col-full -->

 

</div><!-- #top -->

 

 

 

 

 

<div id="header">

 

<div class="col-full">

 

 

 

<div id="logo" >

 

<?php if (get_option('woo_texttitle') <> "true") : $logo = get_option('woo_logo'); ?>

 

<a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('description'); ?>">

 

<img class="logo" src="<?php if ($logo) echo $logo; else { bloginfo('template_directory'); ?>/images/logo.png<?php } ?>" alt="<?php bloginfo('name'); ?>" />

 

</a>

 

<?php endif; ?>

 

<?php if( is_singular() ) : ?>

 

<span class="site-title"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></span>

 

<?php else : ?>

 

<h1 class="site-title"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>

 

<?php endif; ?>

 

<span class="site-description"><?php bloginfo('description'); ?></span>

 

</div><!-- #logo -->

 

 

 

<?php if ( $woo_options['woo_ad_top'] == 'true' ) { ?>

 

 

 

<div id="topad" class="fr">

 

<?php if ($woo_options['woo_ad_top_adsense'] <> "") { echo stripslashes($woo_options['woo_ad_top_adsense']); } else { ?>

 

<a href="<?php echo $woo_options['woo_ad_top_url']; ?>"><img src="<?php echo $woo_options['woo_ad_top_image']; ?>" width="468" height="60" alt="advert" /></a>

 

<?php } ?>

 

</div><!-- /#topad -->

 

 

 

<?php } elseif ( $woo_options['woo_disable_search'] != 'true') { ?>

 

 

 

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">

 

<div id="search">

 

<input type="text" value="<?php _e('Enter search keyword', 'woothemes'); ?>" onclick="this.value='';" name="s" id="s" />

 

<input name="" type="image" src="<?php bloginfo('template_directory'); ?>/images/btn-search-trans.png" value="Go" class="btn" />

 

</div><!--/search -->

 

</form><!-- #searchform -->

 

 

 

<?php } ?>

 

 

 

<div class="fix"></div>

 

 

 

</div><!-- .col-full -->

 

</div><!-- #header -->

 

 

 

<div id="topmenu">

 

<div class="col-full">

 

<?php

 

if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) {

 

wp_nav_menu( array( 'depth' => 6, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_class' => '', 'menu_id' => 'nav', 'theme_location' => 'secondary-menu' ) );

 

} else {

 

?>

 

<ul id="nav">

 

<?php

 

if ( get_option('woo_custom_nav_menu') == 'true' ) {

 

if ( function_exists('woo_custom_navigation_output') )

 

woo_custom_navigation_output('name=Woo Menu 2');

 

 

 

} else { ?>

 

<?php //wp_list_categories('title_li=&exclude=') ?>

<ul class="sf-menu">

<li><a href="<?php echo bloginfo('url'); ?>/" >Home</a></li>

<li><a href="<?php echo bloginfo('url'); ?>/about" >About</a></li>

<li><a href="<?php echo bloginfo('url'); ?>/stories-2" >Stories</a>

<ul>

<?php

$mypages = get_pages('child_of=131&post_type=page&sort_order=asc');

//echo "<pre>"; print_r($mypages); die;

foreach($mypages as $page)

{

?>

<li><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></li>

<? } ?>

</ul>

</li>

<li><a href="<?php echo bloginfo('url'); ?>/contactlinks" >Contact</a></li>

<li><a href="<?php echo bloginfo('url'); ?>/comments" >Comment</a></li>

</ul>

 

<?php } ?>

 

<li> </li>

 

</ul>

 

<?php } ?>

 

<div id="rss" class="fr">

 

<a href="<?php if ( get_option('woo_feed_url') <> "" ) { echo get_option('woo_feed_url'); } else { echo get_bloginfo_rss('rss2_url'); } ?>"><img src="<?php bloginfo('template_directory'); ?>/images/ico-rss-trans.png" alt="RSS" /></a>

 

</div><!--/rss -->

 

 

 

</div><!-- .col-full -->

 

</div><!-- #topmenu-->

 

 

 

<div id="content" class="col-full">

 

Link to comment
Share on other sites

Hello Ben,

 

 

I hope you're OK and that work is going alright for you too.

I've just purchased the PHP for Beginners tutorial from the store.

I realise that without at least a basic understanding of PHP, it's going to be difficult to communicate with real developers.

I downloaded 4 zip files:

-PHP basics 1

-PHP basics 2

-PHP misc

-PHP object oriented programming

 

I suspect that it might not make much of a difference but in which order would you recommend I study these topics?

Would you have any general advice about a "best practice" method to use to get to grips with the material thoroughly?

 

Many thanks in advance for your advice Ben,

Regards,

Andrew.

 

 

 

 

Link to comment
Share on other sites

I suspect that it might not make much of a difference but in which order would you recommend I study these topics?

I would study them in the order you have above: 1, 2, misc and object oriented programming.

 

Would you have any general advice about a "best practice" method to use to get to grips with the material thoroughly?

I found it really helpful when I was first learning PHP to experiment -- don't just watch the videos, but actually do the coding along with the instructor. It's easy just to watch and say "yeah, that sounds easy", but there's a lot to learn that you won't pick up otherwise. I'd assume you are already doing this, but I thought I'd mention it just in case. One of the best things to learn while you are just getting started is how to debug your PHP code -- how to figure out where the errors are, what the error messages mean, and how to fix them. You can't learn that sort of stuff if you don't experiment.

Link to comment
Share on other sites

Hello Ben,

Thanks for your reply to my post last Thursday.

I started the PHP course in the order that you suggested and I've almost completed the php.basics1 folder.

I'm having though with something trivial though and I would be grateful for your insight on this matter.

 

In the video, Stefan recommends testing your PHP scripts on:

-Local servers such as WAMP or XAMPP

-Web host servers.

 

My Web server is Just Host so I decided to focus on this approach.

However, the video seems to focus more on people using local servers.

I haven't been able to pick up on instructions to test scripts on Web hosts servers.

I have written the following basic code from the video:

 

 

<!DOCTYPE HTML PUBLIC "-??W3C??DTD HTML 4.01 Transitional//EN"

 

"http://www.w3.org/TR/html4/loose.dtd">

 

<html>

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 

<title>My 1st PHP</title>

 

</head>

 

<body>

 

<?php

 

print "Hello World.";

 

?>

 

</body>

 

</html>

 

and saved it as a Notepad file with a PHP file extension.

I've tried to upload it to the public_html folder of the Web host in a folder which I called PHP Work but without success.

Could you please recommend a way to upload Notepad files to the Web host server to test the scripts?

 

Many thanks in advance for your help Ben,

Regards,

Andrew.

Link to comment
Share on other sites

Hello Ben,

Many thanks for your last e-mail and your sound advice about the Filezilla transfer.

I followed your instructions and was lucky enough to get the desired result.

 

This is the code I wrote for the 1st PHP page which is in video 7 of the PHP basics1 Folder :

 

 

<!DOCTYPE HTML PUBLIC "-??W3C??DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>1st PHP</title>

</head>

<body>

<?php

print "Hello World.";

?>

</body>

</html>

 

In the video it is recommended to use the "print" function as opposed to "echo",which I've come across before.

 

2) Is there any difference between the "print" and "echo" functions?

 

Many thanks in advance for your help Ben,

Regards,

Andrew.

Link to comment
Share on other sites

Hello Ben,

 

 

Thanks a lot for the link you sent me last week to illustrate the difference between the "echo " and "print" keywords".

I've got a query about another keyword today which I was hoping you might be able to spare some time on.

In the PHP basics 2 tutorial, there's a lesson on the "PHP includes" function.

The video demonstrates how a footer can be added to a main page by using the "include " keyword.

The tutorial says that the "include" keyword can be used with or without the"@" symbol:

-@include or,

-include

My understanding of it is that:

-if the"@" symbol is included and that it links to a non-existent file, no error message will display in the browser

-if the "@" symbol is not included and that it links to a non-existent file, an error message will display in the browser.

 

My query therefore is:

 

1) Is the"@" symbol used with the include function depending on whether or not we plan for the page to be displayed to viewers?

 

Many thanks in advance for your help with this query Ben,

With regards,

Andrew.

 

Link to comment
Share on other sites

The @ symbol is used to suppress error messages and make sure that any error messages resulting from the line of code don't get displayed to the user.

 

http://php.net/manual/en/language.operators.errorcontrol.php

 

As a general rule, it's suggested to stay away from using "@", since it will mean that the program will fail silently, meaning that you as the programmer will have a harder time debugging issues and visitors may get confused when the application doesn't work like they'd expect but they don't have any error messages that might indicate what the issue is.

Link to comment
Share on other sites

Hello Ben,

Thanks a lot for your reply to my e-mail from last Monday about the "include" keyword.

I've just completed the tutorial on arrays now and I've had a crack at both "Indexed" and "Associative" arrays.

This is the code from the tutorial on "Associative" arrays that I wrote as an exercise:

 

 

<meta http-equiv="Content-Type" content="text/html;

 

charset=iso-8859-1">

 

<title> 1st Associative Array</title>

 

</head>

 

<body>

 

<?php

 

// indexed array

 

$my_array =

 

array("Derivatives","PHP","JavaScript",40);

 

print $my_array[2];

 

print "<br><br>";

 

$prices_array = array("iPad" => "1300.00",

 

"MacBook" => "800.00", "iPhone" => "100.00", );

 

print $prices_array['iPad'];

 

?>

 

</body>

 

</html>

 

The code did work alright,displaying "JavaScript" and "1300.00" in the browser.

However,at first, I had added £ signs in the values such as "£1300.00" or "£800.00".

I had also written the names as such:"i-Pad", "i-Phone"and code wouldn't work.

 

My 1st query today is:

 

1) Was my initial name-value annotation incorrect?

 

The tutorial also shows another way of displaying the array:

 

 

$prices_array = array ("iPad" => "1300.00",

 

"MacBook" => "800.00",

"iPhone" => "100.00" );

 

print $prices_array['iPad'];

 

My 2nd query is:

 

2) Is one way of building the array preferable to the other for reading convenience ?

 

Many thanks in advance for your help with this query Ben,

Regards,

Andrew.

Link to comment
Share on other sites

Hello Ben,

I hope you had a good Christmas with friends and family.

I've just completed the PHP tutorial on arrays now and I've had a crack at both "Indexed" and "Associative" arrays.

This is the code from the tutorial on "Associative" arrays that I wrote as an exercise:

 

 

<meta http-equiv="Content-Type" content="text/html;

 

charset=iso-8859-1">

 

<title> 1st Associative Array</title>

 

</head>

 

<body>

 

<?php

 

// indexed array

 

$my_array =

 

array("Derivatives","PHP","JavaScript",40);

 

print $my_array[2];

 

print "<br><br>";

 

$prices_array = array("iPad" => "1300.00",

 

"MacBook" => "800.00", "iPhone" => "100.00", );

 

print $prices_array['iPad'];

 

?>

 

</body>

 

</html>

 

The code did work alright,displaying "JavaScript" and "1300.00" in the browser.

However,at first, I had added £ signs in the values such as "£1300.00" or "£800.00".

I had also written the names as such:"i-Pad", "i-Phone"and code wouldn't work.

 

My 1st query today is:

 

1) Was my initial name-value annotation incorrect?

 

The tutorial also shows another way of displaying the array:

 

 

$prices_array = array ("iPad" => "1300.00",

 

"MacBook" => "800.00",

"iPhone" => "100.00" );

 

print $prices_array['iPad'];

 

My 2nd query is:

 

2) Is one way of building the array preferable to the other for reading convenience ?

 

Many thanks in advance for your help with this query Ben,

Regards,

Andrew.

Link to comment
Share on other sites

  • 4 weeks later...

Hello Ben,

I've been working on the "CRUD with PHP and my SQL" course for a couple of weeks now.

The material is very interesting and I am really looking forward to building my first app.

However,I'm having difficulty with displaying the view.php file in my browser, I must say that I use my web host for this purpose.

This is the error message that I get:

 

Parse error: syntax error, unexpected '>' in /home/spinthe3/public_html/PHPWork/view.php on line 35

I must have made an error with the code and would be grateful for your insight Ben.

Many thansk in advance for your time,

Regards,

Andrew.

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

 

<html>

 

<head>

 

<title>View Records</title>

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

 

</head>

 

<body>

 

<h1>View Records</h1>

 

<?php

 

include('connect-db.php');

 

if ($result = $mysqli->query("SELECT * FROM players ORDER BY id"));

 

{

 

if ($result->num_rows > 0)

 

{

echo "<table border='1' cellpadding='10'>";

 

echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>";"

 

while($row = $result->fetch_object())

{

 

echo "<tr>";

echo "<td>" . $row->id . "</td>";

echo "<td>" . $row->firstname . "</td>";

echo "<td>" . $row->lastname . "</td>";

echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a>"</td>";

echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a>"</td>";

echo "</tr>";

 

}

 

echo "</table>";

}

 

else

 

{

 

echo "No results to display!";

 

}

 

}

 

else

 

{

 

echo "Error: " . $mysqli->error;

 

}

 

$mysqli->close();

 

?>

 

<a href="records.php">Add New Record</a>

 

</body>

 

</html>

Link to comment
Share on other sites

I think the issue is here:

 

echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a>"</td>";

echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a>"</td>";

 

I'm pretty sure the quote you have between </a> and </td> is unnecessary in both of those lines.

 

This line also has an issue:

 

echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>";"

 

The last quote at the end of the line is unnecessary.

Link to comment
Share on other sites

Hello Ben,

 

 

Thanks for your help with those faulty lines.

I've made the necessary changes but now I get this error message:

 

 

Parse error: syntax error, unexpected T_ELSE in /home/spinthe3/public_html/PHPWork/view.php on line 58

I don't know why that would come up,here's my updated code and thanks again for your help with this matter Ben.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

 

<html>

 

<head>

 

<title>View Records</title>

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

 

</head>

 

<body>

 

<h1>View Records</h1>

 

<?php

 

include('connect-db.php');

 

if ($result = $mysqli->query("SELECT * FROM players ORDER BY id"));

 

{

 

if ($result->num_rows > 0)

 

{

echo "<table border='1' cellpadding='10'>";

 

echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>";

 

while($row = $result->fetch_object())

{

 

echo "<tr>";

echo "<td>" . $row->id . "</td>";

echo "<td>" . $row->firstname . "</td>";

echo "<td>" . $row->lastname . "</td>";

echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";

echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";

echo "</tr>";

 

}

 

echo "</table>";

}

 

else

 

{

 

echo "No results to display!";

 

}

 

}

 

else

 

{

 

echo "Error: " . $mysqli->error;

 

}

 

$mysqli->close();

 

?>

 

<a href="records.php">Add New Record</a>

 

</body>

 

</html>

Link to comment
Share on other sites

Hello Ben,

Thanks a lot for the corrections you suggested and which I actually implemented with the help of a post from yesterday by another user.

I think that the user went back to a post of yours with a thorough breakdown of all the pages for the CRUD/PHP/MySQL videos.

I don't know if it was intentional but it was quite helpful, I tried to look her name up but there have been many posts since so I couldn't find her to say thanks.

Anyway I used the code that you had written with the commented lines that explain clearly what each section does.

 

I have unfortunately come up with some new error messages which I looked up on the Net because they seem to be quite generic.

I think they're called mysqli "prepared statements".

 

Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1044): Access denied for user 'spinthe3_andrewb'@'localhost' to database 'spinthe3_records2' in/home/spinthe3/public_html/PHPWork/connect-db.php on line 8

 

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in /home/spinthe3/public_html/PHPWork/view.php on line 18

 

Warning: main() [function.main]: Couldn't fetch mysqli in /home/spinthe3/public_html/PHPWork/view.php on line 52

Error:

Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/spinthe3/public_html/PHPWork/view.php on line 56

 

 

Could it mean that my sql password might be invalid?

It's strange because the error messages seem to all be related to a syntax error with "mysqli" somehow.

WHy couldn't the server "fetch mysqli"?

 

Many thanks in advance for your insight on this matter Ben,

Regards,

Andrew.

Link to comment
Share on other sites

Hello Ben,

I just wanted to thank you for your help with the username and password errors I was facing.

It's only a little database but it's quite tricky when you do it from the Web Host.

I had to figure out how to create the user name, password and database on the Web Host by myself, which was a lot of trial and error, though of course, it is quite trivial for an experienced programmer.

I'm quite happy to start the "Prepared Statements in MySQL" video now.

This is a link to my database, I've still got to write the code to edit and add records to it, but I think that comes up in videos 5 and 6.

http://www.spintheclock.com/PHPWork/view.php

 

Many thanks for your help Ben,

With regards,

Andrew.

 

Link to comment
Share on other sites

Hello Ben,

 

Would it be possible at all to get a link to that post of yours from late 2010 in which you wrote down and commented on the code for the "Edit","Delete" and "Update" php pages for the" CRUD with PHP and MySQL"?

I'm a bit concerned with making unnecessary errors when writing the code, I thought that if I have your work, I can self-correct if I get error messages.

 

Many thanks in advance for your help Ben,

With regards,

Andrew.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...