Hi,
I am very new to php and am struggling to work out how to delete a portfolio item (a row from my database using my form which is here): http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php
The problem comes I think because I already have one submit button on the page as you can see.
Ideally when pressed the delete button will remove the row from the database with the same name that is showing in the top drop down box and either go to a page with a 'delete successfull' message or the message wil appear next to the button.
Here is the code for the page:
Code: <?php
include('connectToDB.php');
include('populateDropDownList.php');
include('buildFileList5.php');
//include('deleteCurrentItem.php');
?>
<html>
<head>
<script type="text/javascript">
var existingPortfolioItems = new Array();
function chkFrm(el){
if(el.selectedIndex == 0){
alert("Please choose an option");
return false
}
else{
el.form.submit();
}
}
function hello(){
//alert("Hello It works");
var result = "boo";
location.replace("deleteCurrentItem.php?result"+ result);
//location.href = "deleteCurrentItem.php?Result=" + Result;
}
function updateImg(ele, img) { // using arguments makes this function reusable for multiple items
// ele = dropdown object
// img = image object
document.getElementById(img).src = "uploaded/thumbs/" + ele.value;
//document[img].alt = ele.value;
}
</script>
</head>
<body>
<h1>Select Existing Item:
</h1>
<form action"deleteCurrentItem.php" method="POST" >Existing Item:
<select name="name" onChange="chkFrm(this)">
<option value="Choose" <?php if (!(strcmp("Choose", $_POST['name']))) {echo "SELECTED";} ?>>Choose Portfolio Items</option>
<?php do { ?>
<option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option>
<?php
} while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems));
$rows = mysql_num_rows($PortfolioItems);
if($rows > 0) {
mysql_data_seek($PortfolioItems, 0);
$row_PortfolioItems = mysql_fetch_assoc($PortfolioItems);
}
?>
</select>
------------>
<input type="button" name="deleteButton" onClick="hello();" value="Delete Current Item">
</form>
<form action="addToPortfolioItems.php" onSubmit="return checkForDuplicateNames("name")" method="post">
<table width="884" height="789" border="1">
<tr>
<td width="417" rowspan="5" valign="top">Name:
<input name="name" type="text" value="<?php echo $row_chosen_pItem['name']; ?>" size="25">
<p>Short Description:</p>
<p>
<textarea name="shortDesc" cols="55" rows="4"><?php echo $row_chosen_pItem['shortDesc']; ?></textarea>
</p>
<p>Long Description:</p>
<p>
<textarea name="longDesc" cols="55" rows="10"><?php echo $row_chosen_pItem['longDesc']; ?></textarea>
</p>
<p>Related Item01
<select name="relatedItem01" >
<option value="" >Choose Item</option>
<?php do { ?>
<option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem01']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option>
<?php
} while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems));
$rows = mysql_num_rows($PortfolioItems);
if($rows > 0) {
mysql_data_seek($PortfolioItems, 0);
$row_PortfolioItems = mysql_fetch_assoc($PortfolioItems);
} ?></select>
</p>
<p>Related Item02
<select name="relatedItem02" >
<option value="" >Choose Item</option>
<?php do { ?>
<option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem02']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option>
<?php
} while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems));
$rows = mysql_num_rows($PortfolioItems);
if($rows > 0) {
mysql_data_seek($PortfolioItems, 0);
$row_PortfolioItems = mysql_fetch_assoc($PortfolioItems);
} ?></select>
</p>
<p>Related Item03
<select name="relatedItem03" >
<option value="" >Choose Item</option>
<?php do { ?>
<option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem03']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option>
<?php
} while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems));
$rows = mysql_num_rows($PortfolioItems);
if($rows > 0) {
mysql_data_seek($PortfolioItems, 0);
$row_PortfolioItems = mysql_fetch_assoc($PortfolioItems);
} ?></select>
</p>
<p>Keywords:
<input name="keywords" type="text" value="<?php echo $row_chosen_pItem['keywords']; ?>" size="50">
<p>Skills:
<input name="skills" type="text" value="<?php echo $row_chosen_pItem['skills']; ?>" size="50">
<p>
<input type="submit"/>
</td>
<td width="451" height="157" align="left"><p>Image01:
<select name="img01" onChange="updateImg(this, 'thumbImg01')">
<?php echo buildFileList5('uploaded',$row_chosen_pItem['img01']); ?>
</select></p>
<table width="24" border="1">
<tr>
<td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img01'];?>" alt="hoho" name="thumbImg01" width="100" height="100" id="thumbImg01"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="150" align="left"><p>Image02:
<select name="img02" onChange="updateImg(this, 'thumbImg02')">
<?php echo buildFileList5('uploaded',$row_chosen_pItem['img02']); ?>
</select>
</p>
<table width="24" border="1">
<tr>
<td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg02" width="100" height="100" id="thumbImg02"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="157" align="left"><p>Image03:
<select name="img03" onChange="updateImg(this, 'thumbImg03')">
<?php echo buildFileList5('uploaded',$row_chosen_pItem['img03']); ?>
</select>
</p>
<table width="24" border="1">
<tr>
<td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img03'];?>" alt="hh" name="thumbImg03" width="100" height="100" id="thumbImg03"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="451" height="109" align="left"><p>Image04:
<select name="img04" onChange="updateImg(this, 'thumbImg04')">
<?php echo buildFileList5('uploaded',$row_chosen_pItem['img04']); ?>
</select>
</p>
<img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg04" width="100" height="100" id="thumbImg04"></td>
</tr>
<tr>
<td align="left"><p>Image05:
<select name="img05" onChange="updateImg(this, 'thumbImg05')">
<?php echo buildFileList5('uploaded',$row_chosen_pItem['img05']); ?>
</select>
</p>
<table width="24" border="1">
<tr>
<td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img05'];?>" alt="hh" name="thumbImg05" width="100" height="100" id="thumbImg05"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</form>
<h1>Upload an image file</h1>
<form enctype="multipart/form-data" action="uploader.php" method="POST"><input type="file" name="myfile">
<p>
<input name="Submit" type='submit' value="upload" >
</form>
<h1>Upload a movie file</h1>
<form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile">
<p>
<input name="Submit" type='submit' value="upload" >
<?echo $heldVariable?>
</form>
<h1>Upload a download file</h1>
<form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile">
<p>
<input name="Submit" type='submit' value="upload" >
<?echo $heldVariable?>
</form>
</body>
</html>
<?php
?>
Thanks in advance for any help on this
How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignored, rejected, or misunderstood in this forum. I'm surprised there isn't already any
Prevent PHP mail( ) from appending hostname to from address
Hey guys,I want to be able to send texts to phones via email (since each phone has their own address), and for specifying the from, I want to specify my own number, is there a way to do this?For
Remore client postprocessing phase getting dump SAPSQL_ARRAY_INSERT_DUPREC
Hello Expects,I have started remore client copy. Data was copied successfully. but while running post processing phase I am getting the system logsFailed to activate authorization check for user
New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code right here: " <?php$people = Array(Array('name' => 'Kalle', 'salt' =>
how to load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service
Why do I get this error?
Error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/runevid/public_html/Quests/finished_tutorial.php on line
error with opendir
when i do this if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[$mone]=$file;
Access website from only 1 computer...?
One of my customers wants his website to only be accessed by people in which they bought the website membership from on their computer. He's afraid that the users might share their login's with their
Disabling SAP menu
How do I disable SAP menu for all the users and just restrict them to User Menu in SAP ECC 6.0?
whats wrong with my code please help!!!
this is the errorWarning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/IpSearch.php on line Code: [Select]<?php$srch = $_REQUEST["srch"];if