PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Mar 27, 2017 5:47 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Feb 26, 2017 12:02 pm 
Offline
Forum Newbie

Joined: Sun Feb 26, 2017 11:52 am
Posts: 1
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>


Last edited by Celauran on Sun Feb 26, 2017 7:54 pm, edited 1 time in total.
Please wrap your code in syntax tags to help keep things legible.


Top
 Profile  
 
PostPosted: Sun Feb 26, 2017 7:49 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6193
Location: Montreal, Canada
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.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group