Line 30:
Code: Select all
case 'add':DELETE FORUMNotice: Undefined variable: id in index2.php on line 30
Code: Select all
if (!isset($_POST["submit"])) {
$query = "SELECT * FROM thecars ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
echo ("<div id=\"DivEdit\">");
echo ("<form action=\"index2.php?id=delete \" method=\"post\">");
echo ("<table align=\"center\">");
while($row = mysql_fetch_array($result)){
echo ("<tr>");
echo ("<td align=\"right\">". $row['year'] . " " . $row['make'] . " " . $row['model'] ."</td>");
echo ("<td align=\"right\"> <input type=\"checkbox\" name=\"id\" value=\"". $row['id'] ."\" /> </td>");
echo ("</tr>");
}
echo ("<tr>");
echo ("<td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Delete\" />");
echo ("</table>");
echo ("</form>");
echo ("</div>");
} else if (isset($_POST["submit"])) {
$query = "SELECT * FROM thecars WHERE id='".$_POST['id']."'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
echo "Deleted a ". $year ." ". $make ." ". $model ." from the database. ";
mysql_query("DELETE FROM thecars WHERE id='".$_POST['id']."'") or die(mysql_error());
}Problems: Goes back to default switch... no record deletion or erros.
Edit Forum
Code: Select all
case 'edit':
$query = "SELECT * FROM thecars ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
echo ("<div id=\"DivEdit\">");
echo ("<table align=\"center\">");
while($row = mysql_fetch_array($result)){
$id=$row['id'];
echo ("<tr>");
echo ("<td align=\"right\"><a href='execute/edit.php?cmd=edit&id=$id'>". $row['year'] . " " . $row['make'] . " " . $row['model'] ."</a></td>");
echo ("</tr>");
}
echo ("</table>");
echo ("</div>");
break;Problems:None.
edit.php
Code: Select all
<?php
error_reporting(E_ALL);
mysql_connect("xxxx", "xxx", "xxx")or die(mysql_error());
mysql_select_db("xx")or die(mysql_error());
$id = $_GET["id"];
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$result = mysql_query("SELECT * FROM thecars WHERE id=$id") or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<div id="DivEdit">
<form action="edit.php" method="post">
<input type="hidden" name="cmd" value="edit">
<input type=hidden name="id" value="<?php print ((isset($row['id']))? $row['id'] : "") ?>">
<table align="center">
<tr>
<td align="right">Year</td>
<td align="left"><input type="text" name="year" id="year" maxlength="4" value="<?php echo $row['year']; ?>" /></td>
</tr>
<tr>
<td align="right">Make</td>
<td align="left"><input type="text" name="make" id="make" value="<?php echo $row['make']; ?>"/></td>
</tr>
<tr>
<td align="right">Model</td>
<td align="left"><input type="text" name="model" id="model" value="<?php echo $row['model']; ?>"/></td>
</tr>
<tr>
<td align="right">Short Description of work</td>
<td align="left"><textarea cols="25" rows="3" name="shortdesc" id="shortdesc"><?php echo $row['shortdesc']; ?></textarea>
</tr>
<tr>
<td align="right">Note worthy items: </td>
<td align="left">
<input type="text" id="note1" name="note1" maxlength="35" value="<?php echo $row['note1']; ?>" /><br />
<input type="text" id="note2" name="note2" maxlength="35" value="<?php echo $row['note2']; ?>"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<?php
}
else if ($_POST["$submit"])
{
$year = $_POST["year"];
$make = $_POST["make"];
$model = $_POST["model"];
$shortdesc = $_POST["shortdesc"];
$note1 = $_POST["note1"];
$note2 = $_POST["note2"];
$sql = "UPDATE thecars SET year=$year,make=$make,model=$model,shortdesc=$shortdesc,note1=$note1,note2=$note2 WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql) or die(mysql_error()) ;
echo "Car updated";
}
}
?>Problems before submission:None
Errors after submission:
-Line 5: $id = $_GET["id"];Notice: Undefined index: id in execute\edit.php on line 5
Notice: Undefined index: cmd in execute\edit.php on line 7
Notice: Undefined index: Submit in execute\edit.php on line 54
-Line 7: if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
-Line 54: else if ($_POST["$submit"])
Problems after submission: Doesn't update the record
I know this is a lot but I have been headaching over this for about 2hours now and cant figure out whats wrong.. I have error reporting for all and each mysql query/connection with no errors except whats posted above. Thanks for the help