Page 1 of 2
form problem
Posted: Tue Jun 10, 2003 8:07 am
by irealms
i have this script:
Code: Select all
<?php
echo 'Alter the data below and submit to update the news article.';
$editquery = "SELECT * FROM blog where id = '$_GET[article]'";
$editresult = mysql_query($editquery, $db_conn) or die("query [$editquery] failed: ".mysql_error());
if (mysql_num_rows($editresult) >0)
{
$row = mysql_fetch_assoc($editresult);
$date = $row['date'];
$title = $row['title'];
$entry = $row['entry'];
}
echo '<form method="post" action="index.php?page=artedit">';
echo 'Date:<br /><input type="text" name="date" value="'.$date.'"><br />';
echo '<br />';
echo 'Title:<br /><input type="text" name="title" value="'.$title.'"><br />';
echo '<br />';
echo 'News Entry:<br /><textarea name="entry" rows=10 cols=60 value="'.$entry.'"></textarea><br />';
echo '<input type="submit" value="Edit">';
echo '</form>';
?>
and the date/time are printed in the form but the entry variable does not show in the text area. Any ideas?
Posted: Tue Jun 10, 2003 8:25 am
by []InTeR[]
Code: Select all
<textarea name="entry" rows=10 cols=60 value="'.$entry.'"></textarea>
must be
Code: Select all
<textarea name="entry" rows=10 cols=60>".$entry."</textarea>
thanks
Posted: Tue Jun 10, 2003 8:40 am
by irealms
yeah noticed that about 10mins after i posted, hehe.
I am having problems with the query atm
Code: Select all
<?php
echo 'Alter the data below and submit to update the news article.';
$editquery = "SELECT * FROM blog where id = '$_GET[article]'";
$editresult = mysql_query($editquery, $db_conn) or die("query [$editquery] failed: ".mysql_error());
if (mysql_num_rows($editresult) >0)
{
$row = mysql_fetch_assoc($editresult);
$artid = $row['id'];
$date = $row['date'];
$title = $row['title'];
$entry = $row['entry'];
}
if (!isset($_POST['date']) || !isset($_POST['title']) || !isset($_POST['entry']))
{
echo '<form method="post" action="index.php?page=artedit">';
echo 'Date:<br /><input type="text" name="date" value="'.$date.'"><br />';
echo '<br />';
echo 'Title:<br /><input type="text" name="title" value="'.$title.'"><br />';
echo '<br />';
echo 'News Entry:<br /><textarea name="entry" rows=10 cols=60>'.$entry.'</textarea><br />';
echo '<input type="submit" value="Edit">';
echo '</form>';
}
else
{
$editedquery = "UPDATE blog set (date,title,entry) VALUES ('$_POST[date]','$_POST[title]','$_POST[entry]') where id = '$_GET[article]'";
$editedresult = mysql_query($editedquery, $db_conn) or die("query [$editedquery] failed: ".mysql_error());
if (mysql_num_rows($editedresult) >0)
{
echo 'You have updated article '.$artid.' "'.$title.'"';
}
}
?>
problem is the update query won't work.
GO, GO, GO, STOP
Posted: Tue Jun 10, 2003 12:47 pm
by phpScott
GO, GO, GO, STOP
first of all I have never had much success with using $_POST['varName'] in my queries but what ever works.
but in this line
Code: Select all
<?php
$editedquery = "UPDATE blog set (date,title,entry) VALUES ('$_POST[date]','$_POST[title]','$_POST[entry]') where id = '$_GET[article]'";
?>
you go $_POST $_POST $_POST $_GET
I don't think you mix methods like that. If you forming is submiting via the Post method you can only use POST.
phpScott
Re: thanks
Posted: Tue Jun 10, 2003 2:49 pm
by twigletmac
irealms wrote:problem is the update query won't work.
Could you elaborate a bit further.
Mac
Posted: Tue Jun 10, 2003 2:53 pm
by liljester
i dont think you can have post and get data either... unless you post the data like so: action="page.php?article=1". ive never tried it tho..
Posted: Tue Jun 10, 2003 2:56 pm
by twigletmac
It is entirely possible to do that - as you can when you post a form send a bunch of information in the URL as well as sending infomation by POST.
Mac
ohhhh
Posted: Tue Jun 10, 2003 5:55 pm
by phpScott
thanks twig for clearing that up. I can see a few applications where that would be useful
phpScott
Posted: Wed Jun 11, 2003 5:16 am
by irealms
sure twig the error i get is:
query [UPDATE blog SET date='10/06/03 , title='Forum error fixed' , entry='Fixed the error that was popping up in the forums.' where id=] failed:
Posted: Wed Jun 11, 2003 5:18 am
by volka
echo '<form method="post" action="index.php?page=artedit">';
where id = '$_GET[article]'"
I might be wrong but I can't see a
GET-parameter
article, only $_GET['page']=='artedit'
Posted: Wed Jun 11, 2003 5:21 am
by irealms
ok go to
http://www.irealms.co.uk/crimson and logon as test/test
go to site announcements and click edit on one of the articles. You will see the get i'm using is sent by the link when you click on the article edit.

Posted: Wed Jun 11, 2003 5:22 am
by volka
http://www.irealms.co.uk\crimson\index.php?page=siteann : page not found
edit: ah, because of the backslashes. Must be
http://www.irealms.co.uk/crimson/index.php?page=siteann
Posted: Wed Jun 11, 2003 5:26 am
by volka
you do not pass the article id from the edit-form to the update-script
<form method="post" action="index.php?page=artedit">Date:<br /><input type="text" name="date" value="04/06/03" style="font-size:10px;border:solid 1px;"><br /><br />Title:<br /><input type="text" name="title" value="Smilies <img src="
http://irealms.co.uk/crimson/forums/smi ... iley15.gif border="0" />" style="font-size:10px;border:solid 1px;"><br /><br />News Entry:<br /><textarea name="entry" rows=10 cols=60 style="font-size:12px;border:solid 1px;"><p>
I have installed a smilie mod to the forum though at present they don't seem to show in the posts, this is being looked into. The text formatting seems to work though! Also started work on a site roster, at present it just shows username, main character and rank. This feature may not be completed until nearer the games release as at present we don't know exact details regarding how many characters your allowed and other character related areas.
</p></textarea><br /><input type="submit" value="Edit" ></form>
ok
Posted: Wed Jun 11, 2003 5:34 am
by irealms
ok changed it a bit and i'm now getting:
query [UPDATE blog set (date,title,entry) VALUES ('10/06/03','Forum error fixed','Fixed the error that was popping up in the forums.') where id = '8'] failed:
so it is using the right id
code is:
Code: Select all
<?php
echo 'Alter the data below and submit to update the news article.';
$editquery = "SELECT * FROM blog where id = '$_GET[article]'";
$editresult = mysql_query($editquery, $db_conn) or die("query [$editquery] failed: ".mysql_error());
if (mysql_num_rows($editresult) >0)
{
$row = mysql_fetch_assoc($editresult);
$artid = $row['id'];
$date = $row['date'];
$title = $row['title'];
$entry = $row['entry'];
}
if (!isset($_POST['date']) || !isset($_POST['title']) || !isset($_POST['entry']))
{
echo '<form method="post" action="index.php?page=artedit">';
echo '<input type="hidden" name="id" value="'.$artid.'">';
echo 'Date:<br /><input type="text" name="date" value="'.$date.'" style="font-size:10px;border:solid 1px;"><br />';
echo '<br />';
echo 'Title:<br /><input type="text" name="title" value="'.$title.'" style="font-size:10px;border:solid 1px;"><br />';
echo '<br />';
echo 'News Entry:<br /><textarea name="entry" rows=10 cols=60 style="font-size:12px;border:solid 1px;">'.$entry.'</textarea><br />';
echo '<input type="submit" value="Edit" >';
echo '</form>';
}
else
{
$editedquery = "UPDATE blog set (date,title,entry) VALUES ('$_POST[date]','$_POST[title]','$_POST[entry]') where id = '$_POST[id]'";
$editedresult = mysql_query($editedquery, $db_conn) or die("query [$editedquery] failed: ".mysql_error());
if (mysql_num_rows($editedresult) >0)
{
echo 'You have updated article '.$artid.' "'.$title.'"';
}
}
?>
Posted: Wed Jun 11, 2003 5:39 am
by volka
ok, now it's time to read the
manual entry for UPDATE 
You used the syntax for
INSERT INTO
and also take a look at
http://php.net/mysql_escape_string