PHP Developers Network
http://forums.devnetwork.net/

Insert Update in one page Errors . Help Me
http://forums.devnetwork.net/viewtopic.php?f=6&t=143402
Page 1 of 1

Author:  jroxy [ Sun Feb 26, 2017 12:02 pm ]
Post subject:  Insert Update in one page Errors . Help Me

I am Getting these errors ..
HELP ME PLEASE

Syntax: [ Download ] [ Hide ]
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


Syntax: [ Download ] [ Hide ]
<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>

Author:  Celauran [ Sun Feb 26, 2017 7:49 pm ]
Post subject:  Re: Insert Update in one page Errors . Help Me

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/