PHP MySQL Tips

PHP back button

By Paul Cracknell - 1st August 2011

Looking for a previous page or back button this is how it is done.

@$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "Previous Page";
…

Read More

PHP & MySQL find the last entry in the database

By Paul Cracknell - 9th July 2011

So you are looking for the last entry in a table for your database that has auto increment.  Well I have this to share with you. Use the mysql_insert_id() function.

1
2
mysql_query("INSERT INTO table1 (product) values ('$somethin')");
$lastID = mysql_insert_id();

You need to combine the insert command and then use the mysql_insert_id function to create a variable that holds the …

Read More

What is Resource # – PHP MySql

By Paul Cracknell - 24th April 2011

Are your trying to print_r or echo the results of a mysql query to your database and just get resource #10 or resource #5 or something similar. I found this somewhere that may explain the problem.

When you use mysql_query(), it really returns a reference to a result resource, which is parsed by mysql_fetch_* functions. If you directly echo out the resource, PHP just gives you the resource number. You

Read More

Submit a form with PHP using a href link – php MySql

By Paul Cracknell - 21st April 2011

If you are trying to submit information from a database using a link here is a method I used in a project recently.  This may or may not be the answer to your needs but give it a go.  Just so you know it is manipulating the url like using the $_GET global.

1
2
3
4
5
6
7
8
<?php
  $query = "SELECT id, name FROM folder WHERE 

Read More

Connect to your MySql Database with PHP

By Paul Cracknell - 21st April 2011

First thing to do is to create a new php page. Call it db.php and save it this will be the way you connect to the database through this file so that you only need to write this code once.
Paste this code into your new file and save it. You will have to change the username and password as well as the yourdatabaseName. See below for details.

<?php//connect 

Read More

PHP MySQL – Joining tables in PhpMyAdmin

By Paul Cracknell - 15th April 2011

Lets suppose we have a database called Prints with several tables. The two tables we want to join are called ‘prints’ and ‘artists’. When we join the two we will create a new table which we will call ‘printdetails’.

The PRINTS table looks like this:

 

the ARTISTS table looks like this:

We want to join both tables into one by using  a combination of columns from each table.

From …

Read More

How do I create a phpinfo page?

By Paul Cracknell - 8th April 2011

Calling phpinfo is useful to give you a lot of information about your php server setup. It is very simple to do as well.

On your desktop, open a new text file with notepad or similar.

Copy and paste this:

<?php phpinfo(); ?>

Save the file as phpinfo.php (or anything else as long as the extention is .php).

Upload the file to your site at the root level and then call …

Read More

Page 1 of 212