Reply to Re: php/mysql syntax help

Your name:

Reply:


Posted by Steve on 02/16/07 00:09

"edward_sanders" <edward_sanders@bellsouth.net> wrote in message
news:5m5Bh.10221$m7.1060@bignews5.bellsouth.net...
| Ok Steve,
| I tried that echo statement you gave and the
| results are not what I was expecting or can make
| sense of at all. I get everything right with the code
| except for the fact that the ID is not getting passed. I
| checked the db from the mysql cmd prompt and got
| this information, which is wierd because ID is spelled
| just like it is my code. So that wasn't the problem.
| Here are the fields which I got from
| Describe jokes; :::
| ID int(11) Not Null, Pri, auto_increment
| JokeText type: text NULL
| JokeDate type: date not null
| AID type int(11) Null
| The last row was added to link with a second table
| created later to hold the joke authors/submitters.


sorry in advance for the text wrapping. this should give you a list of
jokes, allow you to sort/filter by/for joketext and aid. from the list you
can add, edit, and delete jokes. the list is not a dump of data but paged
and optionally grouped. anyway, sorry for any other syntax errors there may
be...i just searched/replaced where needed. let me know if you are
cornfused. ;^)

===========

<?
$pageTitle = 'People';
$fullHeader = false;
$securityEnabled = true;
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';

$add = isset($_REQUEST['add']);
$back = isset($_POST['back']);
$confirm = isset($_POST['confirm']);
$delete = isset($_REQUEST['delete']);
$edit = isset($_REQUEST['edit']);

$action = $add ? 'add'
: 'edit';
$method = isset($_POST['method']) ? $_POST['method']
: '';

$errors = array();

$id = isset($_REQUEST['id']) ? $_REQUEST['id']
: 0;
$jokeText = isset($_REQUEST['jokeText']) ?
$_REQUEST['jokeText'] : '';
$jokeDate = isset($_REQUEST['jokeText']) ?
$_REQUEST['jokeText'] : date('Y-m-d');
$jokeAid = isset($_REQUEST['jokeAid']) ? $_REQUEST['jokeAid']
: '';

if ($back)
{
$add = false;
$delete = false;
$edit = false;
$method = '';
}
if ($confirm)
{
$add = false;
$delete = false;
$edit = false;
$method = '';
$sql = "
DELETE
FROM jokes
WHERE Id = '" . db::prepare($id) . "'
";
db::execute($sql);
header('location:' . $_SERVER['PHP_SELF']);
exit;
}
if (!($delete || $confirm) && $method == 'put')
{
$sql = "
SELECT COUNT(*) JokeExists
FROM jokes
WHERE Id != '" .
db::prepare($id) . "'
AND LOWER(JokeText) = LOWER('" .
db::prepare($jokeText) . "')
";
unset($records);
$records = db::execute($sql);
$jokeExists = $records[0]['JOKEEXISTS'] ? true : false;
if (!$jokeText)
{
$errors['jokeText'] = 'JOKE is required and cannot be blank.';
}
if (!$jokeAid)
{
$errors['jokeAid'] = 'AID is required and cannot be blank.';
}
if ($jokeExists)
{
$errors['jokeText'] = 'This JOKE has already been told.';
}
if (!count($errors))
{
if ($action == 'add')
{
$sql = "
INSERT INTO jokes
(
JokeText ,
JokeDate ,
AID
)
VALUES
(
'" . db::prepare($jokeText) . "' ,
'" . db::prepare($jokeDate) . "' ,
'" . db::prepare($jokeAid) . "' . "'
)
";
} else {
$sql = "
UPDATE jokes
SET JokeText = '" . db::prepare($jokeText) .
"' ,
JokeDate = '" . db::prepare($jokeDate) .
"' ,
AID = '" . db::prepare($jokeAid) .
"'
WHERE Id = '" . $id . "'
";
}
db::execute($sql);
header('location:' . $_SERVER['PHP_SELF']);
exit;
}
}
require_once $site->includeDirectory . 'head.inc.php';
?>
<br>
<div class="bullet" style="background:white no-repeat url('<?=
$site->imagesDirectory ?>bullet.jpg'); color:black; font-size:12pt;
height:50px; padding-top:8px; padding-left:50px;">
<?= $pageTitle ?>
</div>
<hr>
<br>
<?
if ($add || $edit)
{
?>
<script language="javascript">
var skipValidation = false;
function validate()
{
if (skipValidation){ return true; }
var warning = new String();
var el = record.jokeText;
if (warning.length == 0 && trim(el.value) == '')
{
warning = "Please tell a JOKE before saving it.";
}
var el = record.jokeAid;
if (warning.length == 0 && trim(el.value) == '')
{
warning = "AID is required.";
}
if (warning.length)
{
alert(warning);
el.focus()
el.select();
return false;
}
return true;
}
</script>
<?
if (!count($errors))
{
$sql = "
SELECT Id ,
JokeText ,
JokeDate ,
AID
FROM jokes
WHERE id = '" . db::prepare($id) . "'
";
unset($records);
$records = db::execute($sql);
$id = $records[0]['ID'];
$jokeText = $records[0]['FIRSTNAME'];
$jokeDate = date('m/d/Y', strtotime($records[0]['MIDDLENAME']));
$jokeAid = $records[0]['LASTNAME'];
}
if (count($errors))
{
$displayedErrors = array_unique(array_values($errors));
?>
<div style="color:#660000; font-size:10pt; font-weight:bold;">
ERROR
</div>
<hr style="background-color:#660000; color:#660000;">
<ol>
<?= '<li style="color:#660000; font-size:8pt;">' . implode('<li
style="color:#660000; font-size:8pt;">' . "\r\n", $displayedErrors) ?>
</ol>
<hr style="background-color:#660000; color:#660000;">
<br>
<br>
<?
}
if ($delete)
{
?>
<div style="color:#CC0000; font-size:10pt; font-weight:500;
margin-bottom:20px;">
Are you sure you want to delete this record?
<br>
If so, click the "Confirm" button below. Otherwise, click the "Back"
button below to return.
</div>
<?
}
?>
<form name="record" method="post" onsubmit="return validate();">
<table style="width:400px;">
<tr>
<td class="label" style="width:150px;">
Joke
<span style="color:#660000; font-size:10pt;"><?=
(isset($errors['personFirstName']) ? '*' : '') ?></span>
</td>
<td colspan="2">
<textarea class="value"
name="jokeText"
cols="60"
rows="20"
maxlength="1024"
><?= $jokeText ?></textarea>
<input name="jokeDate" type="hidden" value="<?= $jokeDate ?>">
</td>
</tr>
<tr>
<td class="label" style="width:150px;">
AID
<span style="color:#660000; font-size:10pt;"><?=
(isset($errors['personMiddleName']) ? '*' : '') ?></span>
</td>
<td colspan="2">
<input class="value"
name="jokeAid"
maxlength="255"
type="text"
autocomplete="off"
value="<?= $jokeAid ?>"
>
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
</table>
<?
if ($delete)
{
?>
<input name="confirm" type="submit" style="cursor:'hand';
width:100px;" value="Confirm&nbsp;" onclick="skipValidation=true;">
<?
} else {
?>
<input name="<?= $action ?>" type="submit" style="cursor:'hand';
width:100px;" value="Save&nbsp;">
<input name="delete" type="submit" style="cursor:'hand';
width:100px;" value="Delete&nbsp;" onclick="skipValidation=true;">
<?
}
?>
<input name="back" type="submit" style="cursor:'hand';
width:100px;" value="Back&nbsp;" onclick="skipValidation=true;">
<input name="id" type="hidden" value="<?= $id ?>">
<input name="method" type="hidden" value="put">
</form>
<script language="javascript">
record.jokeText.focus();
</script>
<?
echo $sessionFooter;
exit;
}

$lastSort = isset($_REQUEST['lastSort']) ?
$_REQUEST['lastSort'] : '';
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort']
: 'LASTNAME';
$sortDirection = isset($_REQUEST['sortDirection']) ?
$_REQUEST['sortDirection'] : 'ASC';
if ($sort == $lastSort){ $sortDirection = $sortDirection == 'ASC' ? 'DESC' :
'ASC'; }
$lastSort = $sort;

$group = $_REQUEST['group'];
$page = $_REQUEST['page'];
$pages = $_REQUEST['pages'];
$recordsPerPage = $_REQUEST['recordsPerPage'];
if (!is_numeric($group)){ $group = 0; }
if (!is_numeric($page)){ $page = 1; }
if (!is_numeric($pages)){ $pages = 5; }
if (!is_numeric($recordsPerPage)){ $recordsPerPage = 10; }
$findIn = isset($_REQUEST['findIn']) ? $_REQUEST['findIn']
: '';
$find = isset($_REQUEST['find']) ? $_REQUEST['find']
: '';
$sql = "
SELECT COUNT(*) RecordCount
FROM jokes
";
if ($findIn && $find)
{
$sql .= "
WHERE UPPER(" . $findIn . ") LIKE UPPER('%" .
db::prepare($find) . "%')
";
}
unset($records);
$records = db::execute($sql);
$recordCount = $records[0]['RECORDCOUNT'];
$currentPage = $page;
$group = floor((($page - 1) * $recordsPerPage) / ($recordsPerPage *
$pages));
$navigation = array();
$page = $group * $pages + 1;
$lastPage = $page + $pages;
$maxPages = ceil($recordCount / $recordsPerPage);
$range = ($currentPage * $recordsPerPage) - $recordsPerPage;
if ($group)
{
$navigation[] = '<a class="navigation" href="??page=' . ($page - 1) .
'&sortDirection=' . $sortDirection . '&sort=' . $sort . '"
title="Previous">&lt;&lt;</a>';
}
for ($index = 0; $index < $pages; $index++)
{
$navigation[] = '<a class="navigation" href="?page=' . $page .
'&sortDirection=' . $sortDirection . '&sort=' . $sort . '" title="Page ' .
$page . '">' . $page. '</a>';
if ($page == $maxPages){ break; }
$page++;
}
if ($lastPage < $maxPages)
{
$navigation[] = '<a class="navigation" href="?page=' . $page .
'&sortDirection=' . $sortDirection . '&sort=' . $sort . '"
title="Next">&gt;&gt;</a>';
}
$navigation[] = '<span style="color:#666666; padding-left:25px;
font-size:7.25pt;">[Page ' . $currentPage . ' of ' . $maxPages . ']</span>';
?>
<div style="float:right; margin-right:5px;">
<select name="findIn" class="input">
<option value="" <?= (!$findIn ? 'selected' :
'' ) ?>></option>
<option value="JOKETEXT" <?= ($findIn == 'JOKETEXT' ? 'selected' :
'' ) ?>>Joke</option>
<option value="JOKEAID" <?= ($findIn == 'JOKEAID' ? 'selected' :
'' ) ?>>AID</option>
</select>
<input name="find" class="input" type="text" value="<?= $find ?>">
<input type="button" value="Find ..." onclick="find('findIn', 'find');">
</div>
<br clear="all">
<br>
<table style="width:730px;">
<th style="background-color:#336699; border-bottom:1px solid
lightsteelblue; padding:5px; text-align:center; width:100px;">
<a
class="menuItem"
href="<?= $_SERVER['PHP_SELF'] ?>?add=1"
style="background-color:#336699; border:none; color:white;
font-weight:600; text-decoration:underline;"
>Add Joke</a>
</th>
<th
style="border-bottom:1px solid lightsteelblue; border-right:1px solid
lightsteelblue; cursor:pointer; font-size:8pt;"
title="Click to sort"
onclick="document.location='<?= $_SERVER['PHP_SELF'] ?>?lastSort=<?=
$lastSort ?>&sortDirection=<?= $sortDirection ?>&sort=JOKETEXT'"
>Joke</th>
<th
style="border-bottom:1px solid lightsteelblue; border-right:1px solid
lightsteelblue; cursor:pointer; font-size:8pt;"
title="Click to sort"
onclick="document.location='<?= $_SERVER['PHP_SELF'] ?>?lastSort=<?=
$lastSort ?>&sortDirection=<?= $sortDirection ?>&sort=JOKEDATE'"
>Date Updated</th>
<th
style="border-bottom:1px solid lightsteelblue; border-right:1px solid
lightsteelblue; cursor:pointer; font-size:8pt;"
title="Click to sort"
onclick="document.location='<?= $_SERVER['PHP_SELF'] ?>?lastSort=<?=
$lastSort ?>&sortDirection=<?= $sortDirection ?>&sort=AID'"
>AID</th>
<?
$sql = "
SELECT Id ,
JokeText ,
JokeDate ,
AID
FROM jokes
";
if ($findIn && $find)
{
$sql .= "
WHERE UPPER(" . $findIn . ") LIKE UPPER('%" .
db::prepare($find) . "%')
";
}
$sql .= "
ORDER BY " . $sort . " " . $sortDirection . "
LIMIT " . $range . ", " . $recordsPerPage . "
";
unset($records);
$records = db::execute($sql);
foreach ($records as $record)
{
$color = $color == 'white' ? '#EEEEEE' : 'white';
$description = trim($record['JOKEDATE'] . ' - ' .
substr($record['JOKETEXT'], 0, 20));
?>
<tr>
<td style="background-color:<?= $color ?>; font-size:8pt;
text-align:right;">
<a
class="menuItem"
href="<?= $_SERVER['PHP_SELF']?>?edit=1&id=<?= $record['ID'] ?>"
style="background-color:<?= $color ?>; font-size:7.25pt;
font-weight:normal; text-decoration:underline; white-space:nowrap;"
title="EDIT [ <?= $description ?> ]"
>Edit &#9655;</a>
<br>
<a
class="menuItem"
href="<?= $_SERVER['PHP_SELF']?>?edit=1&delete=1&id=<?=
$record['ID'] ?>"
style="background-color:<?= $color ?>; font-size:7.25pt;
font-weight:normal; text-decoration:underline; white-space:nowrap;"
title="DELETE [ <?= $description ?> ]"
>Delete &#9655;</a>
</td>
<td style="background-color:<?= $color ?>; width:150px;
text-align:left;"><?= $record['JOKETEXT'] ?></td>
<td style="background-color:<?= $color ?>; font-size:8pt;
text-align:left;"><?= date('m/d/Y', strtotime($record['JOKEDATE'])) ?></td>
<td style="background-color:<?= $color ?>; font-size:8pt;
text-align:left;"><?= $record['AID'] ?></td>
</tr>
<?
}
?>
</table>
<br>
<hr>
<br>
<?
if (!count($records))
{
echo 'There are currently no records to display.';
} else {
?>
<div style="float:right; margin-right:15px;">
<?
echo implode("\r\n", $navigation);
?>
</div>
<br clear="all">
<br>
<?
}
echo $sessionFooter;
?>

[Back to original 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

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