Subscribe to PHP Freaks RSS

PHP Basic Database Handling

Print
by Crayon Violent on Jun 20, 2008 2:06:06 PM - 188,212 views

"Handling a database with PHP" can be a bit misleading. PHP is not the one responsible for doing anything to your database. All it does is send the query string to your database and your database executes the query.

PHP's job is to build that query string. This can be done statically or dynamically. Static means not changing. Dynamic means changing. A static query string would look something like this:

SELECT somecol FROM table WHERE id = 1

id is assigned the value of 1. It's hardcoded into the script, no changing that whatsoever, unless for instance you use a variable in place of the value, like this:

SELECT somecol FROM table WHERE id = $id

Using variables is one of the most basic ways of dynamically building a query string. You can also use variables in place of the column name, or even use conditions to dynamically add pieces to the query string. Your query string is just that - a string - so you can use any string manipulation technique, function, construct, etc.. out there on your query string, as long as the end result produces a valid query for your database.

In our script, we are going to execute a few database queries by using some basic methods of dynamic query string creation. There are, of course, a million and one better ways to do what we want to do in this script, but in my experience, elegant coding does not usually make an elegant tutorial example.

The Setup

For this tutorial, we are using MySQL as the database. You need to create a table called "info" with 2 columns: "id" type int auto_increment and "name" type varchar(20).

CREATE TABLE `info` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`id`)
)

For your convenience I have include a query string to make it. Go to your phpmyadmin or whatever and run it. If you are scratching your head wondering what all this means, then this tutorial isn't really for you. Go read up on how to mess around with your database directly (or at least through something like phpmyadmin) and then come back.

The Goods

Okay, okay! Here's the whole script! Step away from the google button!

Anyways, the script will display the names from the database. You can edit the names, delete names, add a new name, and sort by the name or id. The code is divided into two parts: "Dealing with the database" and "List everything out."

<?php
/**** Dealing with the database ****/
// connect to db
$conn = mysql_connect('localhost','dbusername','dbpassword') or trigger_error("SQL", E_USER_ERROR); 
$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR); 

// INSERT: if we have a name to add...
if($_POST['name']) {
   // little bit of cleaning...
   $name = mysql_real_escape_string($_POST['name']);
   // insert new name into table
   $sql = "INSERT INTO info (id, name) VALUES ('','$name')";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

// UPDATE: if we have name(s) to change...
if($_POST['cname']) {
   // for each name to change...
   foreach($_POST['cname'] as $cid => $cname) {
      // little bit of cleaning...
      $id = mysql_real_escape_string($cid);
      $name = mysql_real_escape_string($cname);
      // update name in the table  
      $sql = "UPDATE info SET name = '$name' WHERE id = '$id'";
      $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
   } // end foreach
} // end if
	 
// DELETE: if we have a name to delete...
if($_GET['name']) {
   // little bit of cleaning...
   $name = mysql_real_escape_string($_GET['name']);
   // delete name from table
   $sql = "DELETE FROM info WHERE name = '$name'";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

// ORDERBY: if one of the links was clicked..
if ($_GET['orderby']) {
   // make an aray of allowed names
   $allowed = array('id','name');
   // bit of cleaning...
   $order = mysql_real_escape_string($_GET['orderby']);
   // is it a valid column name? yes: use it. no: default to 'id'
   $order = (in_array($order, $allowed))? $order : "id";
// if no link clicked, default to 'id'
} else {
   $order = "id";
} // end else

// SELECT: get the list of names from database
$sql = "SELECT id, name FROM info ORDER BY $order";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
/**** end deal with the database ****/

/**** list everything out ****/
// list columns
echo <<<LISTCOLS
<form action = '{$_SERVER['PHP_SELF']}' method = 'post'>
<table border = '1'>
   <tr>
      <td><a href = '{$_SERVER['PHP_SELF']}?orderby=id'>id</td>
      <td><a href = '{$_SERVER['PHP_SELF']}?orderby=name'>name</td>
      <td>delete</td>
   </tr>
LISTCOLS;

// loop through list of names 
while ($list = mysql_fetch_assoc($result)) {
echo <<<LISTINFO
   <tr>
      <td>{$list['id']}</td>
      <td><input type = 'text' name = 'cname[{$list['id']}]' value = '{$list['name']}'>
      <td><a href = '{$_SERVER['PHP_SELF']}?name={$list['name']}'>delete</a></td>
   </tr>
LISTINFO;
} // end while

// list input box for adding new entry
echo <<<NEWENTRY
   <tr>
      <td bgcolor = 'gray'></td>
      <td><input type = 'text' name = 'name'></td>
      <td bgcolor = 'gray'></td>
   </tr><tr>
      <td></td>
      <td align = 'center'><input type = 'submit' value = 'submit'></td>
      <td></td>
   </tr>
</table>
</form>	 
NEWENTRY;
/**** end list everything out ****/

?>

Dealing With The Database

The first half of the code we will handle all database interaction. We want to do this first, because we want all changes to be reflected on the list after we hit the submit button, when the page gets displayed again.

In order to do something with your database using PHP, you must first establish a connection to your database. That's just a really fancy way of saying you have to login to the database.

// connect to db
$conn = mysql_connect('localhost','dbusername','dbpassword') or trigger_error("SQL", E_USER_ERROR); 
$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR);

These first two lines are what we use to connect to and select your database. The mysql_connect function is what connects to the database. It takes 3 arguments: the host, the username for the database, and the password for the database.

Usually if you are running the script on the same server and you don't have weird access restrictions (like if you use one of those crappy "free" hosting services), simply putting 'localhost' as the host should work. A lot of server configurations add prefixes to your database username and database name, like phpfreak_crayonviolent for username and phpfreak_testdb for a database name (note: this name and dbname do not exist so don't bother trying to exploit, lol).

Your host should have some kind of documentation about whether prefixes are added to your stuff, or whether you have to use a specific host name instead of localhost. Talk to them if you need help.

mysql_select_db selects the database you want to use. You want to pick the one your table is in. It requires one argument: the database name. It optionally accepts a second argument, where you can specify the connection stream. I like to specify the connection stream, mostly out of habit.

The database connection (ideally) lasts as long as the script runs. I say "ideally" because hiccups happen. You can also tell PHP to close the connection with mysql_close($conn);. You do not have to supply an argument for it. If you do not supply a connection stream, it will close the last one opened (yes, that does mean you can have multiple connections opened at once). But again, PHP does automatically close the connection after the script finishes executing anyways, so to be honest, I usually don't bother with mysql_close($conn);.

Dealing With The Database: INSERT

In this first chunk of code, we will add a new name to the table, if applicable.

// INSERT: if we have a name to add...
if($_POST['name']) {
   // little bit of cleaning...
   $name = mysql_real_escape_string($_POST['name']);
   // insert new name into table
   $sql = "INSERT INTO info (id, name) VALUES ('','$name')";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

02. We first check our post array to see if the user entered a name.

04. If he did, we use mysql_real_escape_string as a measure to prevent sql injection attacks (good idea to read up on how to prevent sql injection attacks, since you're learning how to work with databases now).

06. The next thing we do is make our query string. The string looks just like how you would put it directly into your database, except you have " "'s wrapped around and you're assigning it to a variable.

07. The last thing we do is send the query string to the database. We do this with the mysql_query function. mysql_query only requires one argument: the query string. You don't even have to give it as a variable. You can use the string itself as the argument (wrapped in quotes). I like to keep the string separated from the mysql_query because it's easier to debug if things go wrong.

As with many mysql related functions, mysql_query accepts an optional 2nd argument to specify the connection stream.

You don't technically need to assign mysql_query to a variable. When PHP executes mysql_query, it will either will return a result source if you're expecting some kind of data to be returned, a boolean value "true" (represented by "1") if the query was a success but no data is being returned, or a boolean value "false" (represented by "0") if for some reason the query failed.

Since you will usually always want to know how the query went (like, you're expecting data, or need to know if it failed or not), you need to assign that to a variable. Ideally you will want to setup some kind of error event trapping in case something goes wrong, or check if it's a success so you can tell the user or something, but to keep it simple, I haven't really done anything like that in this script, so I technically didn't need to have that "$result = " part. But it's a habit of mine to do it anyway.

Dealing With The Database: UPDATE

In this chunk of code, we will update names in the database, if applicable.

// UPDATE: if we have name(s) to change...
if ($_POST['cname']) {
   // for each name to change...
   foreach($_POST['cname'] as $cid => $cname) {
      // little bit of cleaning...
      $id = mysql_real_escape_string($cid);
      $name = mysql_real_escape_string($cname);
      // update name in the table  
      $sql = "UPDATE info SET name = '$name' WHERE id = '$id'";
      $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
   } // end foreach
} // end if

02. First we check to see if there are any names to update. If there are, then proceed to the next line of code.

04. The next thing we do is make a foreach loop, to cycle through each name. Down in our form, we made the name's id the key, so that we could pass both id and name at the same time without having to get all fancy about it. So, for each iteration of the foreach loop, $cid will be the current id and $cname will be the current name.

06. & 07. We go ahead and sanitize the variables just like we did before.

09. Here is our update query. We use $name and $id in place of a hard coded name/id, because it will change each iteration of the foreach loop.

10. We send off the query string to be executed, just like before. Again, in this instance, we don't really need to assign it to a variable, since we aren't doing anything with the result anyway.

The foreach loop will cycle through all the current names in the list, updating them in the database one at a time. Now, this isn't very efficient, as there's no reason for us to update something that doesn't need updating. Ideally you should write your script to only update it if it's actually changed. But again, writing efficient code isn't necessarily the goal of this tutorial.

Dealing With The Database: DELETE

In this block of code, we will delete a name from the table.

// DELETE: if we have a name to delete...
if($_GET['name']) {
   // little bit of cleaning...
   $name = mysql_real_escape_string($_GET['name']);
   // delete name from table
   $sql = "DELETE FROM info WHERE name = '$name'";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

02. Our form is setup to have a "delete" link next to each name. You simply click on the link and the name is deleted. Since it's a link, we pass the name through the url via the GET method. So the first thing we do is check to see if that variable exists. If it does...

04. Once again we sanitize the variable.

06. We build the query string, inserting the name in the string with $name.

07. We send the string off to the database to be executed. Again, no reason to really assign the result to $result in this example.

Dealing With The Database: ORDER BY

In this block of code, we are going to decide how to order our list.

// ORDER BY: if one of the links was clicked..
if ($_GET['orderby']) {
   // make an aray of allowed names
   $allowed = array('id','name');
   // bit of cleaning...
   $order = mysql_real_escape_string($_GET['orderby']);
   // is it a valid column name? yes: use it. no: default to 'id'
   $order = (in_array($order, $allowed))? $order : "id";
// if no link clicked, default to 'id'
} else {
   $order = "id";
} // end else

02. When we display the list, We make the column titles into links. The user can click on that column title to reorder the list by that title. Like the "delete" links, we pass how the user wants to sort the list through the url, using the GET method. So the first thing we do is check to see if that variable exists. If it does...

04. Remember when we talked about preventing sql injection? Another method to restrict what is being sent to your database, is to specify what is allowed. This is called making a white list. It's just like in the real world when something is black listed or white listed. If it's in the array, it's allowed. Everything else is not. Making a white list is generally more secure than making a black list. So anyways, this is our array of allowed column names to sort. If the $_GET['orderby'] is not one of those columns, we assign a default column.

06. Since we are making a white list of columns, using mysql_real_escape_string is technically pointless. If someone tried to use escape quotes or other such things, it wouldn't be on our list anyways. I don't really have a logical reason for doing it, other than it somehow makes me feel like it's more secure.

08. Here is where we check to see if the value being passed to us is a valid column. We're going to assign something to $order no matter what, but depending on whether it's valid or not, we will either keep it as is or assign a default. We use a ternary operator to do this. The condition is evaluated inside the ( )'s. If it is true, we assign what's on the left of the : if it's false, we assign what's on the right.

11. The else statement is to assign a default column if a column title was not clicked. The default will usually be assigned from this else statement if the user is going to the page for the first time, or if the user clicked on something other than the column title (like a delete link or the form submit button).

Dealing With The Database: SELECT

This is where we actually get the info from the table for us to display to the user. There are no conditions wrapped around it, because we want the information to be displayed every page load. We have this query after the other queries, because we want the updated information in the table to be shown, if the user makes changes.

// SELECT: get the list of names from database
$sql = "SELECT id, name FROM info ORDER BY $order";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
/**** end deal with the database ****/

02. Just a simple select query to get our from the table, except we want to order the information by whatever $order is, be it a user selected order, or the default.

03. Here we execute this query just like all the other query executions so far. The main difference between this one and all the other ones, is that this time we really do want to save the results in a variable, so we can list them.

List Everything Out

In this section, our code is all about displaying the information to the user, as well as providing him a means to alter that information, with a form. This is the user's interface, where all of our previous code gets the data it needs to do what it's got to do. We are going to build an html table to tabulate the information in a half-assed decent format.

/**** list everything out ****/
// list columns
echo <<<LISTCOLS
<form action = '{$_SERVER['PHP_SELF']}' method = 'post'>
<table border = '1'>
   <tr>
      <td><a href = '{$_SERVER['PHP_SELF']}?orderby=id'>id</td>
      <td><a href = '{$_SERVER['PHP_SELF']}?orderby=name'>name</td>
      <td>delete</td>
   </tr>
LISTCOLS;

In this chunk of code, we start out with our form opening tag. The action targets the same script that's executing, using the post method. We then open our table up, and on the first row, we list the column names. We make them links for the user to click on to order the results by, as described in the "ORDER BY" section, earlier. The last html table column is labeled "delete" because that's the column our delete links will go, for each row.

List Everything Out

// loop through list of names 
while ($list = mysql_fetch_assoc($result)) {
echo <<<LISTINFO
   <tr>
      <td>{$list['id']}</td>
      <td><input type = 'text' name = 'cname[{$list['id']}]' value = '{$list['name']}'>
      <td><a href = '{$_SERVER['PHP_SELF']}?name={$list['name']}'>delete</a></td>
   </tr>
LISTINFO;
} // end while

This is the part of our script where we list out the current info in our database table. We start out with a while loop. Why? Okay, remember earlier, the last thing we did before listing stuff out, was select all the info from the database table, and stored it in $result? Okay, that information is called a result source. Think of $result as a magician's hat. PHP provides several functions for us to reach inside that hat and pull out what we need. What we pull out depends on which one of those functions we use.

Somewhere in that black hat is our list of information, and there's a rabbit somewhere in that hat and he has that information, and when we reach inside the hat, he gives us what we need, one row at a time. When he hands us that row, he picks up the next row and waits for us to reach in again.

The row he hands us is stored in an array. What kind of array depends on what function we use. We used mysql_fetch_assoc which returns an associative array. We used an associative array because the keys to the array are labeled the same as our database table columns, which makes it a lot easier for me to keep my head wrapped around my code when trying to type it and read it.

So basically, our array will look like this: ('id' => 1, 'name' => 'Josh') instead of this: (0 => 1, 1 => 'Josh). If numerical indexes float your boat, you can use mysql_fetch_row instead. If for some reason you want both returned, you can use mysql_fetch_array. Be warned though, mysql_fetch_array merges row and assoc together, giving you an array twice as long in the end. As if that weren't enough overkill, mysql_fetch_array can have an optional 2nd argument to return only one or the other (numerical or associative), making it function the exact same as _assoc or _row.

Since we don't know how many rows there are at any given time, we use a while loop. Basically the loop says this: while the rabbit still has rows to hand us, assign the current row he gives us to $list (making it an associative array of our data), and use $list to display the information to our user.

Inside the loop we echo out the id in the first column. We do not make this editable, because MySQL assigns that automatically. It's the row's fingerprint. We then echo out an input text field. We assign a array name to it so we can cycle through it as a list, back up in that UPDATE code block. We assign the row's id number as the array position, so that we can pass the id value with the form, as described in that same previous code block. The value is the name in the database row, so that it shows as the "default" in the text field. The user can edit it, and the UPDATE code block will update it.

Last of all, we make a "delete" link in the last column of our html table. The link will pass the name so that it can be retrieved with the GET method up in the "DELETE" code block.

List Everything Out

// list input box for adding new entry
echo <<<NEWENTRY
   <tr>
      <td bgcolor = 'gray'></td>
      <td><input type = 'text' name = 'name'></td>
      <td bgcolor = 'gray'></td>
   </tr><tr>
      <td></td>
      <td align = 'center'><input type = 'submit' value = 'submit'></td>
      <td></td>
   </tr>
</table>
</form>	 
NEWENTRY;
/**** end list everything out ****/

?>

This last piece of code we simply add an empty textbox for the user to add a name, as well as a submit button. The value of the text field is used by the INSERT code block. The submit button is linked to any updates/inserts made. Close out the table, close out the form, and we're done!

Summary

Hopefully you have gained a better understanding about how to mess around with your database through php. If not, then I'm sorry, I tried! Please post any questions you may have in the comments section or on our help forums, and I or someone else will try to help out.

Until then, Happy Coding!

Crayon Violent

Comments

fearlex Jun 27, 2008 3:54:27 PM

This is an incredible tutorial, i knew how to handle databases but it was so goood to recap, plus a few little things that i learned, and you have a nice way to explain. I had a great time reading it. Thanks :D

Peter Schulte Jul 23, 2008 6:36:06 PM

We're using ODBC-connect, ODBC_exec, etc. How do I create a new record using ODBC? I don't imagine I can do it with mysql commands?

Crayon Violent Jul 26, 2008 3:02:30 PM

Well I don't really know anything about ODBC but they do have their own database handling functions in PHP that are very similar to all of the mysql_xxx counterparts. Here is a link to the functions php offers for ODBC: PHP ODBC functions

A kind of skimmed over the functions and it looks like all you really need to do is switch out the mysql_xxx functions with their ODBC_xxx counterparts.

All the code for the form and receiving info from the user etc.. would not need to be altered.

deepshah Aug 11, 2008 2:05:41 AM

I knew that how to handle the database through PHP, but after reading this tutorial i think it's more than i think. It's really good. Thanks!

ma2tt Aug 16, 2008 10:29:59 AM

I've just started to learn how to use PHP with MySQL so this tutorial has been *very* useful!

I had already put together scripts and an html form to accomplish similar things to those shown in the tutorial but with the scripts in several seperate .php files. Having everything in one file makes much more sense!

Many thanks

mahender Nov 24, 2008 4:06:02 AM

Great Job 'Crayon Violent'!

I like the way you presented the information.
Where Can I go from here to learn more things.
Please guide me!

Many Thanks!

bnther Jun 7, 2009 12:17:31 PM

Easy enough :) Thanks for the tutorial. Quick question, are the notices always on?

adamfaux Jun 12, 2009 11:46:13 AM

Awesome tutorial.. covering all the basics without any of the bad practices that seem to be circulating around. I'm wondering if anyone could help me build upon the DELETE query.

What i'm aiming to do is drag through MULTIPLE variables via the GET method and use them both as conditions in the DELETE query. Somthing along the lines of below:

<?php
include("config.php");

// DELETE: if we have a name to delete...
if($_GET['a_id'] || $_GET['question_id']) { <--------------------------------multiple get variables
// little bit of cleaning...
$a_id = mysql_real_escape_string($_GET['a_id']);
$question_id = mysql_real_escape_string($_GET['question_id']);
// delete name from table
$sql = "DELETE FROM forum_answer WHERE a_id = '$a_id' AND question_id = '$question_id'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

?>

I'm just clutching at straws with the syntax.... any help or advise would be very much aprreciated!

Thanks :)

Crayon Violent Jun 13, 2009 8:18:38 AM

Your code looks syntactically correct (assuming you spelled your variable names right), so you must be having issues with the logic of it. Can you be more specific as to what you are wanting to accomplish? Your condition checks if either one exists (so in other words, only 1 has to exist for the rest of the code to execute), but then in your query string you are deleting rows where both exist.

If you are always wanting to only delete rows where both are present, you need to change your if statement to && instead of || . Using || will allow for the query to be executed if both exist, so it will work when you want it to, but it will also execute if only one exists, so you will end up executing for instance:

..WHERE a_id = '1' AND question_id = ''

Beyond that, if you are still having issues, shed some more light on your problem.

Another thing I thought I would mention (which was not mentioned in the tutorial because it's not the scope of the tutorial to mention such things), you really should validate your data before using it in your query. mysql_real_escape_string is a good defense against injection attacks (though it does not stop ALL attacks), but it does nothing to validate format.

So for instance, if your columns are type int or something and all you are doing is escaping the data, well that doesn't stop someone from entering something other than numbers.

To make sure that the data only has numbers, you can for instance use ctype_digit

MadProfessor Jul 25, 2009 3:27:44 AM

Hey there. I am thoroughly frustrated. I have tried umpteen numbers of edit/update codes and can get none to work. What is worse, although detailed instruction is given on what each part does, everyone forgets to indicate which sections we should modify for our own use. I have tried and tried, and every time there is a problem. All I really need is a simple code to enter & display a specific data set and allow the user who created it to modify it. Not that hard really, eh?

...well you wouldn't think so, but for an idiot like me!

Could someone please help me render this code down to just a display of 2 specific data fields, requiring a validation password to enable it to be changed by the right user (remembering to indicate in colour the table and column references that need editing. This would be a great help.

Otherwise, could someone please explain why the below code does not work?
//////////////////////////////////////////////////////////////////////////////
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","username","password");

//select which database you want to edit
mysql_select_db("mydatabase");

//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from mytable order by id");

//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$Teacher=$r["Teacher"];//take out the title
$subject=$r["Subject"];//take out the title
$id=$r["id"];//take out the id

//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$Teacher, $subject - Edit?</a>";
echo "<br>";
}
}

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM mytable WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

Teacher:<INPUT TYPE="TEXT" NAME="Teacher" VALUE="<?php echo $myrow["Teacher"] ?>" SIZE=30><br>
Information:<TEXTAREA NAME="Information" ROWS=10 COLS=30><? echo $myrow["Information"] ?></TEXTAREA><br>
Year Groups:<INPUT TYPE="TEXT" NAME="Year_Groups" VALUE="<?php echo $myrow["Year_Groups"] ?>" SIZE=30><br>

<input type="hidden" name="cmd" value="edit">

<input type="submit" name="submit" value="Update">

</form>

<? }

if ($_POST["$submit"])
{
$Teacher = $_POST["Teacher"];
$Information = $_POST["Information"];
$Year_Groups = $_POST["Year_Groups"];

$query = "UPDATE mytable SET Teacher='$Teacher',Information='$Information',Year_Groups='$Year_Groups' WHERE id=$id";

$result = mysql_query ($query) or die(mysql_error());
echo "Thank you! Information updated.";
}
}
?>
/////////////////////////////////////////////////////////////////////////////////
It does everything I want it to do, including display the right fields for each entry. I can change the layout myself once I can get it to work. But when you submit, nothing happens. The code seems to stop working right at:

$query = "UPDATE Daily_Notices SET Teacher='$Teacher',Information='$Information',Year_Groups='$Year_Groups' WHERE id=$id";

as it never reaches the end code:

echo "Thank you! Information updated.";

If someone could help me get a handle on this simple edit code (and include a password verification before submit) I will polish your shoes for a year!

Sincerely,
The Mad Professor ...and getting madder by the minute!

Crayon Violent Jul 25, 2009 6:28:14 PM

Okay, this is a tutorial, not some code snippet or function or class or system. The point is to teach you how to understand a concept, not how to write something specific, or specifically integrate abc into xyz. If you are saying things like "...everyone forgets to indicate which sections we should modify for our own use.." for a tutorial, then you probably need to backup and learn some of the more basic concepts first, like syntax, program flow and logic. In short, learn to crawl before learning to walk. Or else, find something in a code repository meant to be published for distribution/integration, where you should find specific install/integration/interface instructions.

A quick glance reveals several things wrong with your script that are in fact, errors on your part, which do in fact show your lack of understanding for some of the aforementioned basic concepts. I suggest you make a post on the forums about it, as the comments section is not really the place to trouble-shoot script integration.

realcostdomains Aug 7, 2009 2:15:17 PM

Thanks - I just pimped my admin area with this - keep up the great work

Jonbuilt Mar 3, 2010 2:29:51 PM

Very cool!!

Add Comment

Login or register to post a comment.