adding delete button or check box to form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

adding delete button or check box to form

Postby myitalan » Mon Jul 23, 2012 12:10 am


I have a form that that will upload an image with comments saving to an xml file.

The page also list all the images and comments in the xml page.

What I am having trouble with is creating a delete button or check box to delete a record in the xml file via the php form.

Here is the Form:
Syntax: [ Download ] [ Hide ]
            <form action="playlistaction.php" method="post" enctype="multipart/form-data">
     <td colspan="2"class="labelcell"><label for="title">Title:</label></td>
     <td colspan="2"class="fieldcell"><input type="text" id="title" name="title"  tabindex="1"/></td>
     <td colspan="2"class="labelcell"><label for="description">Description:</label></td>
     <td colspan="2"class="fieldcell"> <input type="text" id="description" name="description"  tabindex="2"/><br />
     <td colspan="2"class="labelcell"><label for="userfile">Image Upload:</label></td>
     <td colspan="2"> <input name="userfile" type="file" id="userfile" tabindex="2"/><br />
   <tr style="display:none">
 <td colspan="2"class="labelcell"><label for="img">Image</label></td>
    <td colspan="2" class="fieldcell"> <input type="text" id="img" name="img"  tabindex="4"></td>
   <td colspan="4"><input type="submit" name="upload" class="box" value="Submit" tabindex="5" /></td>
<h2>Current entries:</h2>
<p>Title - Description - Image  </p>
<div style="border:1px solid black; overflow:auto; height:400px; width:800px">
$doc = new DOMDocument();
$doc->load( 'photoGallery.xml' );
$gallery = $doc->getElementsByTagName( "images" );
foreach( $gallery as $images )
  $artists = $images->getElementsByTagName( "title" );
  $title = $artists->item(0)->nodeValue;
  $titles= $images->getElementsByTagName( "description" );
  $description= $titles->item(0)->nodeValue;
  $tmbs = $images->getElementsByTagName( "tmb" );
  $tmb = $tmbs->item(0)->nodeValue;
  $imgs = $images->getElementsByTagName( "img" );
  $img = $imgs->item(0)->nodeValue;
  echo "<b>$title - $description - $tmb\n</b><br>";}?>

I've tried to add this to the echo but it brakes the code.

Syntax: [ Download ] [ Hide ]
  echo "<b>$title - $description - $tmb <input name="delete" type="button" value=" ">\n</b><br>";}?>

Thank in advance.
Last edited by Benjamin on Mon Jul 23, 2012 12:59 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
Forum Newbie
Posts: 2
Joined: Sat Jul 14, 2012 3:05 pm

Re: adding delete button or check box to form

Postby social_experiment » Mon Jul 23, 2012 4:32 am

Syntax: [ Download ] [ Hide ]
echo "<b>$title - $description - $tmb <input name="delete" type="button" value=" ">\n</b><br>";}?>

You have to escape the double quotation marks in the string; in the snippet above the php is parsed until the next " is reached, which in the case isn't the end of the statement (marked by a ; ) so you receive an error
Syntax: [ Download ] [ Hide ]
echo "<b>$title - $description - $tmb <input name=\"delete\" type=\"button\" value=\" \">\n</b><br>";}?> </div>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
DevNet Master
Posts: 2775
Joined: Sun Feb 15, 2009 12:08 pm
Location: .za

Re: adding delete button or check box to form

Postby califdon » Mon Jul 23, 2012 12:27 pm

Or, if you don't like to enter all those escape backslashes, you can use single quotes within the double quotes:
Syntax: [ Download ] [ Hide ]
echo "<b>$title - $description - $tmb <input name='delete' type='button' value=' '>\n</b><br />";}?>
I don't make syntax errors. It's just that sometimes whoever wrote the programming language failed to anticipate my creative coding.
User avatar
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 9:30 pm
Location: California, USA

Return to PHP - Code

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests