Insert Update in one page Errors . Help Me

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
jroxy
Forum Newbie
Posts: 1
Joined: Sun Feb 26, 2017 10:52 am

Insert Update in one page Errors . Help Me

Post by jroxy »

I am Getting these errors ..
HELP ME PLEASE

[text]Notice: Undefined variable: submit in C:\xampp\htdocs\job\demo1.php on line 9
Notice: Undefined variable: delete in C:\xampp\htdocs\job\demo1.php on line 30
Notice: Undefined variable: id in C:\xampp\htdocs\job\demo1.php on line 37
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\job\demo1.php on line 40
Notice: Undefined variable: id in C:\xampp\htdocs\job\demo1.php on line 51[/text]

Code: Select all

<html>
<body>
<?php
$db = mysql_connect("localhost","root","");
mysql_select_db("core",$db);

if ($submit) // Line 9
 {
// here if no ID then adding else we're editing


if ($id)
 {
$sql = "UPDATE job SET Title='$Title',Description='$Description',Link='$Link',Category='$Category' WHERE id=$id";
 }

 else
  {
$sql = "INSERT INTO job (Title,Description,Link,Category) VALUES ('$Title','$Description','$Link','$Category')";
  }
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";


} 


elseif ($delete) { // Line 30
// delete a record
$sql = "DELETE FROM Downloads WHERE id=$id";	
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) { // Line 37
// print the list if there is not editing
$result = mysql_query("SELECT * FROM Downloads",$db);
while ($myrow = mysql_fetch_array($result)) { // Line 40
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["id"], $myrow["Title"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A DOWNLOAD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) { // Line 51
// editing so select a record
$sql = "SELECT * FROM job WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$Title = $myrow["Title"];
$Description = $myrow["Description"];
$Link = $myrow["Link"];
$Category = $myrow["Category"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
Title:
<textarea name="Title" cols="50" rows="1"><?php echo $Title ?></textarea>
<br>
Description:
<textarea name="Description" cols="50" rows="5"><?php echo $Description ?></textarea>
<br>
Link:
<textarea name="Link" cols="50" rows="1"><?php echo $Link ?></textarea>
<br>
Category:
<textarea name="Category" cols="50" rows="1"><?php echo $Category ?></textarea>
<br>

<input type="Submit" name="submit" value="Enter">
</form>
<?php
}
?>
</body>
</html>
Last edited by Celauran on Sun Feb 26, 2017 6:54 pm, edited 1 time in total.
Reason: Please wrap your code in syntax tags to help keep things legible.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Insert Update in one page Errors . Help Me

Post by Celauran »

Whatever tutorial you're following that's telling you to use mysql_ functions, you need to stop listening to that. That aside, the error specifically say the variable has not been defined. There's no $id = "some value". Ditto for submit and delete. mysql_fetch_array returning a boolean means $result is false, which means your query is no good.
Post Reply