I am coding an add,edit,delete page to administer records in a table.
The add and view sections are alive to date, but I am having trouble passing the values to the edit and delete cases.
As you can see in the code below, upon loading the page goes into the case statement and switches based on the value of action.
That part works, but within a case, if I try $_GET['servID'] I get an error similar to this:
Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING' in /home/goodnew/public_html/admin/ad_services.php on line 127
Which I get anyway when I try to output the value of a row by its columnname. My first guess is syntax, but I can't pin it down.
Also, no matter what "action" is the default view is always processed.. How do i eliminate that?
<? include "../inc/conn.php"; ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/gn.css">
</head>
<body>
<?
switch ($_GET['action'])
{
case "delete":
$connDel = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$dbDel = mysql_select_db($database,$connDel)
or die("couldn't select database");
$del = "DELETE * FROM catService WHERE catServID = $servID";
if(!mysql_query($del)) {
echo "Deletion of Record $servID failed.";
echo "<p>";
echo mysql_error();
} else {
echo "Deletion of Record $servID was successful.";
}
case "addsave":
$servName = addslashes($servName);
$servCost = addslashes($servCost);
$servNotes = addslashes($servNotes);
$connAdd = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$dbAdd = mysql_select_db($database,$connAdd)
or die("couldn't select database");
$add = "INSERT INTO `catService` (`catServName`,`catServCost`,`catServNotes`) VALUES ('$servName','$servCost','$servNotes')";
if(!mysql_query($add)) {
echo "Insertion into database failed.";
echo "<p>";
echo mysql_error();
} else {
echo "Insertion into database was successful.";
}
case "add":
?>
<div class="left-body-container">
<div class="left-body-main">
<h3> Add a New Service </h3>
<!-- Add Form -->
<form method="post" action="$PHP_SELF?action=addsave" name="addForm" enctype="multipart/form-data">
<!-- Form Container Table -->
<table width="500">
<tr><td>
<!-- Form Body -->
<table>
<tr>
<td><input type="text" name="servName" size="20" maxlength="20" class="" value=""></td>
<td>$ <input type="text" name="servCost" size="20" maxlength="6" class="" value=""></td>
</tr>
<tr><td><small><em><b>Service Name</b></em></small></td></tr>
<tr><td><small><em><b>Cost<br>(enter 1.11 if service if according to weight)</b></em></small></td></tr>
</table>
<p>Service Notes: Use this section to describe what the service includes, or give a brief description of what the service is</p>
<p><textarea name="servNotes" cols="60" rows="2" class=""></textarea><p>
<!-- End Form Body -->
<p align="right"><input type="submit" value="Add Record"></p>
</td></tr>
</table>
<!-- End Form Container Table -->
</form>
<!-- End Add Form -->
</div>
<!-- END BODY DIV -->
<? default:
$connView = mysql_connect($host,$user,$password);
mysql_select_db($database,$connView);
$view = "SELECT catServID as 'ID', catServName as Service Name, catServCost as Cost FROM catService ORDER BY catServName ";
$result = mysql_query($view);
if ($result == 0)
echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
elseif (@mysql_num_rows($result) == 0)
echo("<b>No Services Listed At this time</b><br>");
else
echo "<table width='500'>
<thead>
<tr>
<td class='admin-table-c'><b>ID</b></td>
<td class='admin-table-l'><b>Service Name</b></td>
<td class='admin-table-c'><b>Cost</b></td>
<td class='admin-table-c'> </td>
<td class='admin-table-c'> </td>
</tr>
</thead>
<tbody>";
while($row = mysql_fetch_array($result)) {
extract($row);
echo "<tr>";
echo "<td class='admin-table-c-sm' width='10%'>$row['catServID']</td><td class='admin-table-l-sm' width='50%'>$row['catServName']</td><td class='admin-table-r-sm' width='5%'>$ $row['catServCost']</td>";
echo "<td class='admin-table-c-sm' width='15%'><a href='$PHP_SELF?action=edit&servID=$row[0]'>Edit</td><td class='admin-table-c-sm' width='15%'><a href='$PHP_SELF?action=delete&servID=$row[0]'>Delete</a></td>";
echo "</tr>";
}
echo "<tr><td class='admin-table-r' colspan='5'><a href='$PHP_SELF?action=add'>Add A New Service</a></tr></tbody>";
} ?>