You are here: PHP/MySQL Question « PHP SQL « IT news, forums, messages
PHP/MySQL Question

Posted by mpar612 on 08/08/06 17:53

Hello,

I'm sorry to keep posting and to put my long code at the bottom of my
posts, but I'm under a lot pressure to get this done quickly. I am
trying to add delete/update buttons to my page. I could not figure out
how to do it all in the existing page, so I added a link to my main
page that links to a delete page (code for both pages is below). When
a user clicks on the delete button and screen loads (the delete page
code) with the isbn number for that particular row added to the url
(e.g. delete_record.php?isbn=\'%20.%20987654321%20.%20\'). On the
delete page, I cannot retrieve any of the information from the row that
the user selected delete from on the main page. I have made several
attempts and spent several hours on this and can't seem to get it. I
hope this makes sense.

If I can get this working, I should be able to run a delete query on
the delete page that deletes the record from the database.

Thanks in advance!

My main page:
<?php

// Load PEAR DB
require 'DB.php';

// Connect to the database
$db =
DB::connect('mysql://mikepar8_hockey:testing@216.246.48.250/mikepar8_mikeparkermusiccom');
if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); }

// Set up automatic error handling
$db->setErrorHandling(PEAR_ERROR_DIE);

// Set up fetch mode: rows as objects
$db->setFetchMode(DB_FETCHMODE_ASSOC);

// Jump out of PHP mode to make displaying all the HTML tags easier
?>

<?php

print "<table align=\"center\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" bordercolor=\"#000000\">";

// Send the query to the database program and get all the rows back
$rows = $db->getAll('SELECT isbn, artist_name, album_title,
date_format(release_date, \'%M %d, %Y\') as release_date,
date_format(add_date, \'%M %d, %Y\') as add_date, description, price
FROM lounge');
foreach ($rows as $row) {
print "<tr><td>ISBN:</td><td>$row[isbn]</td></tr>
<tr><td>Artist Name:</td><td>$row[artist_name]</td></tr>
<tr><td>Album Title:</td><td>$row[album_title]</td></tr>
<tr><td>Release Date:</td><td>$row[release_date]</td></tr>
<tr><td>Add Date:</td><td>$row[add_date]</td></tr>
<tr><td>Description:</td><td>$row[description]</td></tr>
<tr><td>Price:</td><td>$row[price]</td></tr></tr>
<tr><td><a href=\"delete_record.php?isbn=\' . $row[isbn] .
\'\">Delete</a></td><td>Update</td></tr>
<tr><td colspan=\"2\"><hr></td></tr>";
}

?>


My delete page:
<?php

// Load PEAR DB
require 'DB.php';

// Load the form helper functions.
require 'formhelpers.php';

// Connect to the database
$db =
DB::connect('mysql://mikepar8_hockey:testing@216.246.48.250/mikepar8_mikeparkermusiccom');
if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); }

// Set up automatic error handling
$db->setErrorHandling(PEAR_ERROR_DIE);

// Set up fetch mode: rows as objects
$db->setFetchMode(DB_FETCHMODE_ASSOC);

// Jump out of PHP mode to make displaying all the HTML tags easier
?>

<?php
// Send the query to the database program and get all the rows back

if ( (isset($_GET['isbn'])) && (is_numeric($_GET['isbn'])) ) {
$isbn = $_GET['isbn'];
} elseif ( (isset($_POST['isbn'])) && (is_numeric($_POST['isbn'])) )
{
$isbn = $_POST['isbn'];
} else {
echo '<h1>This page has been reached in error</h1>';
exit();
}

print "<table align=\"center\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" bordercolor=\"#000000\">";

$rows = $db->getAll('SELECT isbn, artist_name, album_title,
date_format(release_date, \'%M %d, %Y\') as release_date,
date_format(add_date, \'%M %d, %Y\') as add_date, description, price
FROM lounge WHERE isbn=$isbn');
foreach ($rows as $row) {
print "<tr><td>ISBN:</td><td>$row[isbn]</td></tr>
<tr><td>Artist Name:</td><td>$row[artist_name]</td></tr>
<tr><td>Album Title:</td><td>$row[album_title]</td></tr>
<tr><td>Release Date:</td><td>$row[release_date]</td></tr>
<tr><td>Add Date:</td><td>$row[add_date]</td></tr>
<tr><td>Description:</td><td>$row[description]</td></tr>
<tr><td>Price:</td><td>$row[price]</td></tr></tr>";
}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация