For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > Edit script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Edit script
smurf

2004-05-24, 12:34 pm

I've written this edit script with the help of a tutorial yet it
doesn't work, me and my friend have looked over the script
thousands of times but it doesn't work. It seems to send the
changed data to the edit_process.php file parses down doesn't do
the update but then displays the echo "News item changed";
I even tried posting the whole edit script into 1 file and using the
"<? echo PHP_SELF ?>" function for the forms
but that dint work.
I'll post the 2 scripts though see if anyone can figure out whats
wrong.

Here is the edit page:
--------

<?php

include "config.php";

db =
mysql_connect(db_host,db_user,db_pass
);
mysql_select_db (db_name) or die ("Cannot
connect to database");
/* We have now connected, unless you got an error message */
/* We now select one news post, and bring it into some text boxes */
if (!_GET["id"])
{
_ _ _die("Warning: Unable to process non ID-ed
query.");
}
query = "SELECT id, title, author, email, body _FROM news
WHERE id = " . _GET["id"];
result = mysql_query(query);
while(r=mysql_fetch_array(result))
{ _ _
/* This bit sets our data from each row as variables, to make it
easier to display */
title=r["title"];
author=r["author"];
email=r["email"];
body=r["body"];
id=r["id"];

/* Now lets display the titles */
_ _echo "<form method='post'
action='edit_process.php'>
_<TABLE>
_ <TR><TD> Title: </TD><TD>
<input type='text' name='title'
value='title'> </TD></TR>
_ <TR><TD> Author: </TD><TD>
<input type='text' value='author'>
</TD></TR>
_ <TR><TD> Email: _</TD><TD>
<input type='text' value='email'>
</TD></TR>
_ <TR><TD> Body: </TD><TD>
<textarea name='body' cols='30'
rows='10'>body</textarea>
</TD></TR>
_ <input type='hidden' name='id'
value='id'>
_ <TR><TD></TD> <TD><input
type='submit' name='Submit'
value='Save'></TD></TR>
_</TABLE>
</form>";
}
mysql_close(db);
?>
--------

And here is the edit_process.php:
--------

<?php
include "config.php";

db =
mysql_connect(db_host,db_user,db_pass
);
mysql_select_db (db_name) or die ("Cannot
connect to database");
/* We have now connected, unless you got an error message */
/* Lets save some news ! */
query = "UPDATE news SET title='title',
author='author', email='email',
body='body' WHERE id = 'id'";
result = mysql_query(query);
echo "News item saved.";
mysql_close(db);
?>

--------
Any help would be greatly appriciated



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


smurf

2004-08-18, 3:56 pm

:( no one has any ideas then :(

http://www.gta-shack.com/boards #1 source for GTA Info + free hosting
for GTA sites.

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


chuckury

2004-08-18, 3:57 pm

...
email='email', body='body' WHERE id =
'id'";
result = mysql_query(query);
echo "News item saved.";
...
Add or die(mysql_error()) to the end of the second line of ^ so it
becomes:
result = mysql_query(query) or die(mysql_error());

And then tell us the error you get if you get one.

http://www.php.net/manual/ | http://www.google.com
Current chuQuery release:
http://dennmat.beigetower.org/chuquery.zip <- Link Fixed Now It
Works, if you have comments or find problems with it please PM me.

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


AJB

2004-08-18, 3:57 pm

What aabout config.php?
the file that is included?



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


smurf

2004-08-18, 3:57 pm

right, there is nothing wrong with the config file and i added the or
die(mysql_error()); but there has been no change i still just get it
up saying "News item Saved"
Not fair :(

http://www.gta-shack.com/boards #1 source for GTA Info + free hosting
for GTA sites.

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com