Search
Left Quote    Black holes are where God divided by zero.
- Steven Wright    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Building a News Management System -- Edit Page Problem
  This user is offline  Denzel
  Subject: "Building a News Management System -..." Posted: @ 1:51 pm on Aug 22 2006   
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

Right so i did as recomended in the tutorial.
I have this problem:

This is the code that the tutorial says to do and then it explains what that does("the code: <a href='ed.php?id =$send->id'& gt;</a> basically calls the edit script into play, while sending the "id" variable with the link. This allows us to edit or delete the post where id=xx."

Code:
echo" $send->title - <a href='ed.php? id=$send->id '>Edit this</a> - <a href-='del.php? id=$send->id '>Delete this</a>& lt;br /><br />";

Ok i understand the idea but still something's wrong...
It should send the variable 'id' from page "list.php& quot; to "ed.php&qu ot;.. when i click in the reference to edit a notice, it appears this error:

Notice: Undefined variable: submit in c:\programas\ea syphp1-8\www\ad min\ed.php on line 15
Notice: Undefined variable: id in c:\programas\ea syphp1-8\www\ad min\ed.php on line 20
That post does not exist.

The first ('submit') i can fix by using "if (!isset($_POST[ 'submit']))&quo t; besides "if (!$submit)" ; at the very beggining. The ssecond i cant manage to correct... Any sugestions?
Ty for the help.. =)

Edited at 02:04:25 pm on 08/22/06


brunoliveirapt@
hotmail.com |     Viewed: 24,667 Times | Reply to This | To top
  This user is offline  AdRock
  Subject: "re: Building a News Management Syst..." Posted: @ 11:52 pm on Aug 22 2006    
Member #: 186
Rank: User - (31)
Since: 07/21/06
Posts: 31
From: Devon

Are you checking it locally because notices don't really mean a lot. I used to get those all the time and I disabled the notices and it worked fine.

There's probably nothing wrong with the code.

Just disable the notices in the php.ini file (if you've got php installed locally)




    Viewed: 24,647 Times | Reply to This | To top
  This user is offline  sm0ke
  Subject: "re: Building a News Management Syst..." Posted: @ 9:52 am on Aug 27 2006    

Member #: 168
Rank: User - (83)
Since: 06/05/06
Posts: 34
From: Manchester - UK

Looking at the sample you posted it contains a "-" between the second "href&qu ot; and "=" .

I may have made this mistake when writing the turorial, but copying and pasting it works fine for me, try removing this "-" see if that helps




Just because I dont care, doesnt mean I dont understand.

purepcs@hotmail
.co.uk |     Viewed: 24,630 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 11:11 am on Aug 27 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

Lol that has other mistake there that didnt make the link to delete the topic.. That was no problem too but the other one still bugs me out...

 AdRock said...

< i>Just disable the notices in the php.ini file (if you've got php installed locally)

AdRock i didnt understand well your point..




brunoliveirapt@
hotmail.com |     Viewed: 24,627 Times | Reply to This | To top
  This user is offline  sm0ke
  Subject: "re: Building a News Management Syst..." Posted: @ 11:41 am on Aug 27 2006    

Member #: 168
Rank: User - (83)
Since: 06/05/06
Posts: 34
From: Manchester - UK

I'm not sure exactly where the problem lies as I dont test / develop on winbloze environments but could you post the full code you are using for both the list and edit scripts, and also does the delete work when pressed?

I ask as if the delete function works then there must be a problem within the edit script.




Just because I dont care, doesnt mean I dont understand.

purepcs@hotmail
.co.uk |     Viewed: 24,624 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 9:28 pm on Aug 27 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

del.php code:

Code:

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td"> <html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>De lete News</title& gt;
</head>
<body>

<?
include(" ../site/site.in c.php";

db_login();

// generate and execute query
$query = "DELETE FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Dele tion successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

require_once(& quot;temp/foot. php";
?>
<?
include(" ../site/site.in c.php";

db_login();

// generate and execute query
$query = "DELETE FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Dele tion successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

require_once(& quot;temp/foot. php";
?>


</body> </html>

ed.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td"> <html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>Un titled Document</ti tle>
</head>
<body>

<?
include(" ../site/site.in c.php";

// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
db_login();

// generate and execute query
$query = "SELECT * FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// if a result is returned
if (mysql_num_rows ($result) > 0)
{
// turn it into an object
$send = mysql_fetch_obj ect($result);
// print form with values pre-filled
?>

Edit News Post
<form action="& lt;? echo $PHP_SELF; ?>" method="P OST">< br /> <input type="hid den" name="id " value="&l t;? echo $send->id; ?>"> ;
Title:<br />
<input size="50 " maxlength=&quo t;250" type="tex t" name="tit le" value="&l t;? echo $send->title ; ?>"> ;<br />
Content:<br />
<textarea name="con tent" cols="40 " rows="10 "><? echo $send->conte nt; ?></texta rea><br />
Author:<br />
<input size="50 " maxlength=&quo t;250" type="tex t" name="aut hor" value="&l t;? echo $send->autho r; ?>"> ;<br />

<input type="Sub mit" name="sub mit" value="Up date">
</form>
<?
}
// no result returned

else {
echo "<font size=-1>That post does not exist.</font >";
}
}
// form submitted
// start processing it
else
{

// set up error list array
$errorList = array();
$count = 0;

// validate text input fields
if (!$title) { $errorList[$cou nt] = "Invalid entry: title"; $count++; }

if (!$content) { $errorList[$cou nt] = "Invalid entry: content"; $count++; }

if (!$author) { $errorList[$cou nt] = "Invalid entry: author"; $count++; }

if (sizeof($errorL ist) == 0) {
db_login();
// generate and execute query
$query = "UPDATE news SET title = '$title', content = '$content', author = '$author' WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Upda te successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

} else {
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>&quo t;;
echo "<ul&g t;";
for ($x=0; $x<sizeof($e rrorList); $x++)
{
echo "<li&g t;$errorList[$x ]";
}
echo "</ul& gt;</font> ;";
}
}

?>



</body> </html>


list.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td"> <html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>Li st News</title& gt;
</head>
<body>

<?
include(" ../site/site.in c.php";

db_login();

//Generate the query so we can retrieve all titles in the DB in descending ID order

$query = "SELECT id, title FROM news ORDER BY id DESC";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// if records are present
if (mysql_num_rows ($result) > 0) {

while($send = mysql_fetch_obj ect($result)) {

echo" $send->title - <a href='ed.php?i d=$send->id '>Edit this</a> - <a href='del.php? id=$send->id '>Delete this</a>& lt;br /><br />"; }
}
?>



</body> </html>

del.php error:
 Explor er said...
< i>Notice: Undefined variable: id in c:\programas\ easyphp1-8\www \admin\del.ph p on line 16
Deletion successful. Go back to the main menu.
Warning: main(temp/foot. php): failed to open stream: No such file or directory in c:\programas\ easyphp1-8\www \admin\del.ph p on line 22

Fatal error: main(): Failed opening required 'temp/foot.php ' (include_path= '.;C:/Programas /EasyPHP1-8\ph p\pear\') in c:\programas\ easyphp1-8\www \admin\del.ph p on line 22

ed.php error:
 Explor er said...
< i>Notice: Undefined variable: submit in c:\programas\ easyphp1-8\www \admin\ed.php on line 15

Notice: Undefined variable: id in c:\programas\ easyphp1-8\www \admin\ed.php on line 20
That post does not exist.


Thats quite it... The del.php one just made it to work but it gives the same error... Oh well... =( Any help?




brunoliveirapt@
hotmail.com |     Viewed: 24,617 Times | Reply to This | To top
  This user is offline  sm0ke
  Subject: "re: Building a News Management Syst..." Posted: @ 10:13 pm on Aug 27 2006    

Member #: 168
Rank: User - (83)
Since: 06/05/06
Posts: 34
From: Manchester - UK

Hi

Looks like your Register Globals is set to off.

try replacing the instance of PHP_SELF with

$_SERVER['PHP_ SELF']

or


$HTTP_SERVER_VA RS['PHP_SELF' ]

hope that helps out




Just because I dont care, doesnt mean I dont understand.

purepcs@hotmail
.co.uk |     Viewed: 24,613 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 6:16 pm on Aug 28 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

Where should i replace??

Can u plz give me the full code? I dont see where that can change anything.. =/




brunoliveirapt@
hotmail.com |     Viewed: 24,601 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Building a News Management Syst..." Posted: @ 9:01 pm on Aug 28 2006    
Unregistered

Try chnging this line:


Code:


<form action="& lt;? echo $PHP_SELF; ?>" method="P OST">< br />



With this:


Code:

<form action="& lt;? echo $_SERVER['PHP_ SELF']; ?>" method="P OST">< br />



See if that helps.



    Viewed: 24,597 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 11:46 am on Aug 29 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

Thats on the ed.php one rigth?
How can that change the del.php problem??
And no that didnt fixed it out.. =(
Can this be a local problem?? Im using easyphp..




brunoliveirapt@
hotmail.com |     Viewed: 24,588 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Building a News Management Syst..." Posted: @ 5:06 pm on Aug 29 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Try changing your code of:

echo" $send->title - <a href='ed.php? id=$send->id '>Edit this</a> - <a href-='del.php ?id=$send->i d'>Delete this</a>& lt;br /><br />";

to this:

Code:


echo("&q uot; . $send->title . "<a href='ed.php?i d=" . $send->id . "'>Ed it This</a> - <a href='del.php? id=" . $send->id . "'>De lete This</a> <BR><B R>";



And check your include paths, its saying they are wrong.



Edited at 05:14:31 pm on 08/29/06


-bs0d | AllSyntax.com

    Viewed: 24,583 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 8:30 pm on Aug 29 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

The changing didnt work...

What do you mean about the include paths?




brunoliveirapt@
hotmail.com |     Viewed: 24,574 Times | Reply to This | To top
  This user is offline  Denzel
  Subject: "re: Building a News Management Syst..." Posted: @ 8:59 pm on Aug 29 2006    
Member #: 163
Rank: User - (14)
Since: 05/07/06
Posts: 14
From: Portugal - Aveiro

Well guys it seems to be a easyphp problem!
I tried in a free hosting server and it worked well. Still dont understand why it works there and not locally... =/
Any idea? =)




brunoliveirapt@
hotmail.com |     Viewed: 24,571 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Building a News Management Syst..." Posted: @ 11:04 pm on Aug 29 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Probably the way PHP is setup on your server. I dont know what easyphp is, but it dont sound like it helped you much! glad you got it to work.




-bs0d | AllSyntax.com

    Viewed: 24,568 Times | Reply to This | To top
  This user is offline  sm0ke
  Subject: "re: Building a News Management Syst..." Posted: @ 2:33 pm on Aug 30 2006    

Member #: 168
Rank: User - (83)
Since: 06/05/06
Posts: 34
From: Manchester - UK

Hi

Glad you got it working - Is the free hosting using a Linux backend? and is easyphp being run on a local winbloze environment?

Its possible its due to the OS in place, or down to the some setting within the easyphp install either in the apache httpd config file or the php.ini file.

Glad it works on the server tho.




Just because I dont care, doesnt mean I dont understand.

purepcs@hotmail
.co.uk |     Viewed: 24,554 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Building a News Management Syst..." Posted: @ 12:35 am on Aug 31 2006    
Unregistered

hiz



    Viewed: 24,547 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Building a News Management Syst..." Posted: @ 3:23 am on Sep 16 2006    
Unregistered

  Denzel said...

< i> del.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>De lete News</title& gt;
</head>

<body>

<?
include(" ../site/site.in c.php";

db_login();

// generate and execute query
$query = "DELETE FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Dele tion successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

require_once(& quot;temp/foot. php";
?>
<?
include(" ../site/site.in c.php";

db_login();

// generate and execute query
$query = "DELETE FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Dele tion successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

require_once(& quot;temp/foot. php";
?>


</body>
</html>

ed.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>Un titled Document</ti tle>
</head>

<body>

<?
include(" ../site/site.in c.php";

// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
db_login();

// generate and execute query
$query = "SELECT * FROM news WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// if a result is returned
if (mysql_num_rows ($result) > 0)
{
// turn it into an object
$send = mysql_fetch_obj ect($result);

// print form with values pre-filled
?>

Edit News Post
<form action="& lt;? echo $PHP_SELF; ?>" method="P OST">
<input type="hid den" name="id " value="&l t;? echo $send->id; ?>"> ;
Title:<br />
<input size="50 " maxlength=&quo t;250" type="tex t" name="tit le" value="&l t;? echo $send->title ; ?>"> ;<br />
Content:<br />
<textarea name="con tent" cols="40 " rows="10 "><? echo $send->conte nt; ?></texta rea><br />
Author:<br />
<input size="50 " maxlength=&quo t;250" type="tex t" name="aut hor" value="&l t;? echo $send->autho r; ?>"> ;<br />

<input type="Sub mit" name="sub mit" value="Up date">
</form>

<?
}
// no result returned

else {
echo "<font size=-1>That post does not exist.</font >";
}
}
// form submitted
// start processing it
else
{

// set up error list array
$errorList = array();
$count = 0;

// validate text input fields
if (!$title) { $errorList[$cou nt] = "Invalid entry: title"; $count++; }

if (!$content) { $errorList[$cou nt] = "Invalid entry: content"; $count++; }

if (!$author) { $errorList[$cou nt] = "Invalid entry: author"; $count++; }

if (sizeof($errorL ist) == 0) {
db_login();

// generate and execute query
$query = "UPDATE news SET title = '$title', content = '$content', author = '$author' WHERE id = '$id'";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<font size=-1>Upda te successful. <a href=index.php& gt;Go back to the main menu</a>. </font>& quot;;

} else {
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>&quo t;;
echo "<ul&g t;";
for ($x=0; $x<sizeof($e rrorList); $x++)
{
echo "<li&g t;$errorList[$x ]";
}
echo "</ul& gt;</font> ;";
}
}

?>



</body>
</html>


list.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>Li st News</title& gt;
</head>

<body>

<?
include(" ../site/site.in c.php";

db_login();

//Generate the query so we can retrieve all titles in the DB in descending ID order

$query = "SELECT id, title FROM news ORDER BY id DESC";
$result = mysql_query($qu ery) or die ("Error in query: $query. " . mysql_error());

// if records are present
if (mysql_num_rows ($result) > 0) {

while($send = mysql_fetch_obj ect($result)) {

echo" $send->title - <a href='ed.php?i d=$send->id '>Edit this</a> - <a href='del.php? id=$send->id '>Delete this</a>& lt;br /><br />";
}
}
?>



</body>
</html>

del.php error:
 Explor er said...N otice: Undefined variable: id in c:\programas\ easyphp1-8\www \admin\del.ph p on line 16
Deletion successful. Go back to the main menu.
Warning: main(temp/foot. php): failed to open stream: No such file or directory in c:\programas\ easyphp1-8\www \admin\del.ph p on line 22

Fatal error: main(): Failed opening required 'temp/foot.php ' (include_path= '.;C:/Programas /EasyPHP1-8\ph p\pear\') in c:\programas\ easyphp1-8\www \admin\del.ph p on line 22

ed.php error:
 Explor er said...N otice: Undefined variable: submit in c:\programas\ easyphp1-8\www \admin\ed.php on line 15

Notice: Undefined variable: id in c:\programas\ easyphp1-8\www \admin\ed.php on line 20
That post does not exist.


Thats quite it... The del.php one just made it to work but it gives the same error... Oh well... =( Any help?



    Viewed: 24,474 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

This Topic is Locked






"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank