Reply
Editing Entries to a database?
Old 08-09-2005, 08:34 AM Editing Entries to a database?
andypugh's Avatar
Novice Talker

Posts: 11
Hi There,

I was wondering if someone could give me some advice on how to build a form so I can edit a submission to my database -

At the moment I have the script in place to submit items to the database (Below)

PHP Code:
<? include("auto_disable.inc"); ?>

<html>
<head>
<title>Submit Book & Movie Details</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>A:link{text-decoration:none} A:link:visited{text-decoration:none} A:link:hover{color:white;text-decoration:underline} </style>
</head>
<body bgcolor="#C0C0C0" text="#FFFFFF" link="#FF9900">
<?
if ($submit)
{
if (!
$newsname)
{
echo 
"Please put in a name for your news article.<br>\n";
?>

            <?
} else {
if (!
$newsby)
{
echo 
"Please enter a username for you to be known by.<br><br>\n";
?>
           
            <?
} else {
if (!
$newsbody)
{
echo 
"Please enter your news.<br><br>\n";
?>
            <?
} else {

$newsbody=ereg_replace("\n","<br>",$newsbody);

$date=date("l F d, @h:iA");

$newsname=addslashes($newsname);
$newsby=addslashes($newsby);
$newsbody=addslashes($newsbody);


$sql="INSERT INTO book1 (newsname,newsby,newsbody,newsat) VALUES ('$newsname','$newsby','$newsbody','$date')";
$result=mysql_query($sql);


$sql="SELECT * FROM book1 ORDER by newsid DESC LIMIT 0,1";
$result=mysql_query($sql);
while (
$myrow=mysql_fetch_array($result))
{
$last_newsid=$myrow["newsid"];
}


$sql="INSERT INTO `forum_topic` (`boardid` , `topic_name` , `topic_by` , `topic_body` , `topic_date` , `topic_type` , `lastpost` , `topic_special_id` , `special_id_type`) VALUES ( '9', '$newsname', 'Admin', '$newsbody', '$date', '0', '0','$last_newsid','3')"
$result=mysql_query($sql);


echo 
"Thanks for your submission, It has now been recorded. If there are problems with this please contact Andy Pugh\n";
}}}} 

else {
?>
             <form method=post action=book1.php>
              
  <p><font face="Verdana"><b>Article Headline:<Br> 
    <input type=text name=newsname size="30">
    <br>
    &nbsp;</b></font></p>
              
  <p><font face="Verdana"><b>Your Name: 
    <Br><input type=text name=newsby size="20">
    <br>
  </b></font>
  </p>
  <p><font face="Verdana"><b>Your News:<Br><textarea rows=12 cols=42 wrap=virtual name=newsbody></textarea>
    <br>
    <br>
    <input type=submit name=submit value="Submit this Article"> </b></font> </p>
</form>
            <?
}
?>
I use auto_disable.inc for the database connection, so authorization is not neccessary -
Basically what I would like is the ability to click on an already posted article to 'book1' for example and have it in a box which I could then edit and resubmit..

If this is quite complex I would be willing to pay for your time.
Andy
__________________
Hogsmeade News - THE Harry Potter Resource!
andypugh is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 08-09-2005, 09:25 AM
KML9870's Avatar
One Bad Mamma :-)

Posts: 4,206
Name: Kandi
Location: Western NY
It's not that difficult, basically it should look something like this:


PHP Code:
 $query_text "select * from YourTable where ArticleID='$Articleid'";
$query mysql_query($query_text);
$result mysql_fetch_array($query);
 
echo    
"<table border='0' cellspacing='1' style='border-collapse: collapse'  width='100%' id='AutoNumber3'><form action='Update.php' method='GET'>
         <tr><p><td height='22'>
 
 
echo
<p align='left'>Field1:</td>
     </left>
     <left>
     
     <p align='left'><input type='text' value='{$result['Field1']}' name='Field2'></td>
     </left>
         </tr>
     <tr><p>
     <p align='left'>Field2:</td>
     </left>
     <left>
 
     <p align='left'><input type='text' value='{$result['Field2']}' name='Field2'></td>
     </left>
         </tr>
<tr><p>
     <p align='left'>Field3:</td>
     </left>
     <left>
 
     <p align='left'><input type='text' value='{$result['Field3']}' name='Field3'></td>
     </left>
         </tr>
     <tr><p>
     <p align='left'>ArticleBody:</td>
     </left><left>
<textarea cols='65' rows='15' wrap='VIRTUAL' name='ArticleBody'>{$result['ArticleBody']}</textarea></td>
     </left>
         </tr>
 
</table><center> <!--<form action='Update.php?'Field1='Field1&'Field2='Field2&'Field3='Field3&ArticleBody=ArticleBody'>//-->
<input type='submit' value='Submit!' width='10' height='8'></td></form><tr><p></form>\n"

Then update.php:
PHP Code:
$sql "UPDATE YourDatabase SET Field1 = '$Field1', Field2 = '$Field2', Field3 = '$Field3', ArticleBody = '$ArticleBody' WHERE Articleid = '$Articleid' LIMIT 1";
 
 
$result mysql_query($sql) or die(mysql_error()); 
__________________
~~Kandi~~
Commit random acts of kindness frequently!


Last edited by KML9870 : 08-09-2005 at 09:28 AM.
KML9870 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Editing Entries to a database?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12764 seconds with 13 queries