Learning PHP, MySQL, and JavaScript

Robin Nixon

Mentioned 7

Provides information on creating Web sites using a combination PHP and MySQL and adding applications using JavaScript.

More on Amazon.com

Mentioned in questions and answers.

Possible Duplicate:
What to do after learning basic PHP?
How to increase my “advanced” knowledge of PHP further? (quickly)


I started learning PHP about this time last month and i now know how to create websites using basic php. I would like to further my knowledge but i dont know which way to turn.

I've heard of frameworks like codeigniter, zend, cakePHP but dont know what use they are for. Should they be my next step? Im currently using NetBeans.

I look at other php scripts and how their directly structure is tidy and sorted into folders whereas all my files are on the root level. How do i learn to create a script structure correctly?

I would also like to learn how to use templates, do the frameworks help with this?

Also, I learned Java at college. So should OO PHP be my next step?

Basically, what is the road map for going from a beginner to master?

I suggest reading a good book or two. Those will give you a lot more insight and knowledge than probably any resource you can find on the Web.

For example A Step-By-Step Guide to Creating Dynamic Websites and PHP and MySQL Web Development.

I am building an employee directory that has 3 simple forms. The first adds records, the second searches for records, the third searches then deletes records.I want to display all the records on the same page, and then when a search is done, just display those records that fit the search keyword.

I have built the DB and the Table correctly. The first form adds records to the DB successfully. Before I make the search and delete forms work correctly I am trying to get the records to display. They are not displaying. Sometimes I can get my html table to display, but none of the records appear. However, I know that the records exist because I can see them in MyAdmin.

I am getting this error right now, but my errors are changing by the moment as I try new things: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Employees.php on line 84

I would love some help to do the following: 1. Help me understand why I am getting this error. 2. Help me understand how to display my records (I've done this successfully before, but with a simpler task).

I know this code is unfinished. I am building it piece by piece and trying to get each individual piece to function before I add the next. Thanks!


<?php error_reporting (E_ALL ^ E_NOTICE);
$keyword = $_GET['keyword']; ?>


$con = mysql_connect("localhost", "employees", "employeepw");
if (!$con)
    die('Could not connect: ' . mysql_error());

mysql_select_db("employees", $con);

mysql_query("INSERT INTO employeeinfo (firstname, lastname, phone, email, department, position)
VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[phone]', '$_POST[email]', '$_POST[department]', '$_POST[position]')");


        function buildQuery() {

        $keyword = $_GET['keyword'];

        $sql = "SELECT * from employeeinfo WHERE
                firstname LIKE '%$keyword%'
                lastname LIKE '%$keyword%'
                phone LIKE '%$keyword%'
                email LIKE '%$keyword%'
                department LIKE '%$keyword%'
                position LIKE '%$keyword%'

        return $sql;

        } ?>

        <form action="Employees.php" method="post">
        <legend>Submit Employee Info</legend>
        Firstname: <input type="text" name="firstname" />
        Lastname: <input type="text" name="lastname" />
        Phone: <input type="text" name="phone" />
        Email: <input type="text" name="email" />
        Department: <input type="text" name="department" />
        Position: <input type="text" name="position" />
        <input type=submit name=submit value=Submit />

        <form action="Employees.php" method=get>
        <legend>Search Employee Info</legend>
        <label for="keyword">Enter Keyword</label>
        <input id="keyword" name="keyword" value="<?php echo "$keyword"; ?>" />
        <input type=submit name=submit value=Search />

        <form action="Employees.php" method=get>
        <legend>Delete Employee Info</legend>
        <label for="keyword">Enter Keyword</label>
        <input id="keyword" name="keyword" value="<?php echo "$keyword"; ?>" />
        <input type=submit name=submit value=Delete />

function getRecords()
$sql = buildQuery();

$resource = mysql_query($sql);

while($row = mysql_fetch_array($resource)) { // The error is for this row
$results[] = $row;
return $results;

$records = getRecords(); {

foreach ($records as $record) {


        <table border='1'>
        <td><?= $row['firstname']; ?></td>
        <td><?= $row['lastname']; ?></td>
        <td><?= $row['phone']; ?></td>
        <td><?= $row['email']; ?></td>
        <td><?= $row['department']; ?></td>
        <td><?= $row['position']; ?></td>
        <td><a href="Employees.php">Return to Search</a></td>

        <? } ?>


Please never do such thing:

mysql_query("INSERT INTO employeeinfo (firstname, lastname, phone, email, department, position) VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[phone]', '$_POST[email]', '$_POST[department]', '$_POST[position]')");

This will produce a HUGE hole in your site security called sql-injection. You should always check any data gained from user.

The simple example of how it should be:

$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$phone = mysql_real_escape_string($_POST['phone']);
$email = mysql_real_escape_string($_POST['email']);
$department = mysql_real_escape_string($_POST['department']);
$position = mysql_real_escape_string($_POST['position']);

mysql_query("INSERT INTO employeeinfo (firstname, lastname, phone, email, department, position)
VALUES ('{$firstname}', '{$lastname}', '{$phone}', '{$email}', '{$department}', '{$position}')");

For more info read: http://php.net/manual/en/mysqli.real-escape-string.php

I think you should find a good book for novices in PHP and read at least from time to time it. It will help you understand what you writing and how to make it better.

The first book that i googled for this purpose - http://www.amazon.com/Learning-MySQL-JavaScript-Step-Step/dp/0596157134/

i'm copying a series of examples from Robin Nixon's Learning PHP, javascript and MySql


which ultimatly unite to form a basic social networking site. All of these examples are written in php, javscript and mySql. At some point I would like to use SQLite instead of mySql. My question is, will i be able to finish the site in mysql and then simply began using SQLite, or will other steps be be needed, such as rewriting the whole thing?

First, unless you are using an abstraction layer, you will need to switch to a different API for using the completely different database.

Next, you are probably using some MySQL specific functions that will need to be worked around.

Finally, work around anything not implemented in SQLite.

I'd really be curious to know why you want want to do this anyway. Do you understand that SQLite databases really aren't meant for a lot of concurrent connections, and aren't generally considered appropriate for websites of any decently sized scale?

I'm new to web development, I know some javascript, html, css and I'm learning php. The problem is that I don't find good resource on how to put it all together.

Any recommendation will be appreciated.

Besides looking around Google (or similar) for tutorials, you can pick up a beginners book. We used Learning PHP, MySQL, and JavaScript in a class I was a TA in, it's pretty good for learning the basics of web dev.

Hi I want to start learning PHP and MySql and also polish my knowledge of Javascript witch is very limited at the moment having only use jQuery and knowing only the core sintax of the language.I choose to read Learning PHP MySQL and Javascript witch seemed to fit all my needs.

Having always had bad luck when installing something new I immediately hit a dead end with XAMPP 1.7.7.

The server runs corectly when is first installed and I can stop MySQL and Apache from running from the control panel.But if close the control panel and reopen it I get and error.

If when it was first opened I left apache and Mysql opened I get the error Apache Service not stopped [-1] the same goes for MySQL.If the services were close I get the same error that says apache service can't start same for MySQL.

I have tryed multiple instalations and the same thing happens.

I first tought I will install it and live them open so I can start working but sadly it didn't work corectly or I don't know how to run a PHP script corectly.

Here's what I did:

I opened PHPStorm and pasted this little scripped with a PHP extension :


    echo "Hello world";


After that I tried to run it but I get the error "PHP interpretor is not installed". Shouldn't it have worked if the apache server was running?

You should wait after you stopped apache or mysql to let them clean things up. If you want to force them to end their processes, you can kill httpd.exe and mysqld.exe from task manager and then try starting it from xampp control panel.

I have registration form, which is saving user info in 'tblusers' -> 'Username', but It doesn't check if the user is already existing, so at the moment users can register with identical usernames, which is a huge mess.

So I need to check MySQL database for existing 'Username' on the registration. Any idea how to do this with PHP - MySQL, even javascript.

This is code I'm executing on form submit:

    check_token ();
    $_SESSION['currency'] = $currency;
    $clientid = addclient ($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, 
        $postcode, $country, $phonenumber, $password, $securityqid, $securityqans, $sendemail);
    //print "New clientid=" . $clientid . "<br>";
    update_query ('tblclients', array ('notes' => $notes, 'status' => $status, 'credit' => $credit, 'salesOperatorId' => $salesOperatorId,
        'taxexempt' => $taxexempt, 'latefeeoveride' => $latefeeoveride, 'overideduenotices' => $overideduenotices, 'country' => 'US',
        'language' => $language, 'billingcid' => $billingcid, 'lastlogin' => '00000000000000'), array ('id' => $clientid));
    //print "New clientid now=" . $clientid . "<br>";
    savecustomfields ($clientid, $customfield);
    $result = select_query ('tblusers', 'ID', array ('ClientID' => $clientid));

    // adding user to the DB at same time as client is being added ...
    $datenowtimestamp = date("Y-m-d H:i:s");
    $table91 = 'tblusers';
    $array91 = array ('ClientID' => $clientid, 'firstname' => $userfirstname, 'lastname' => $userlastname, 'email' => $useremail,
            'username' => $username, 'password' => $password, 'searchdelivery' => 'Criminal', 'reporttiming' => 'Instant',
            'deliverymethod' => 'email', 'Created' => $datenowtimestamp,
            'phonenumber' => $phonenumber, 'orderreports' => 1, 'viewallreports' => 1, 'viewpricing' => 1,
            'restrictreportview' => 0, 'gatewayaccess' => 0);
    insert_query ($table91, $array91);

    if($data = mysql_fetch_array ($result))
        $userid = $data['ID'];
    $header = 'Location: clientsusers.php?clientid=' . $clientid;
    //print $header . "<br>";
      header ($header);
      exit ();

When the form data is accessible in whatever php script gets executed when the form is submitted in a has $_POST['username'] (or if you're using GET, $_GET['username']). From there, since you're users can register, I'll assume you connect to your DB and run queries.

Query the database for how many entries match $_POST['username']. If if greater than 0, return the error however you see fit.

The query would look something like SELECT count(*) FROM dbname WHERE username = $_POST['username']. Of course there is some prep work to do to avoid SQL injection, but that would be the basic process.

This book has everything you need to know about the basics of web programming, and was the text for my web programming class.

First of all let me just say, I have no experience with PHP whatsoever, and actually very little with any web development.

As part of a project, I need to work with php, and what I'll have to do is create a module to integrate into another part of the system. This will basically take a request, which should contain some sort of cookie (which as far as I understood, is the best way to perform operations over a secure connection), and attempt to retrieve some information from Facebook, which after some formatting, will be sent back to the original request originator.

Not sure if that small piece of information helps at all, but based on that, what would you suggest as a good tutorial to get me started?


EDIT: Oops, forgot to mention. If it has some sort of interactive component (as I've seen with some html/javascript tutorials) that would be a big plus, since I've heard debugging php isn't something trivial, as it runs on the background server and we get no access to what happening under the hood.

It sounds like you need to learn more about web development, PHP in particular, and working with the Facebook API. For the former, I'd suggest a book rather than a tutorial. O'Reilly produces a number of popular web development books; you could give this one a shot Learning PHP, MySQL, and JavaScript: A Step-By-Step Guide to Creating Dynamic Websites. See Facebook's documentation for integration details with that platform.