All,

I have a small select box for deleting a page, and I need to include the pos(which is position when it gets submitted) - So I can update the database position of the pages.

How can I put the pos in this too when it gets submitted?

<?php //This dropdown is for page deleting!!
			$query="SELECT id, linklabel, pos FROM pages ORDER BY pos ASC";
			$result = mysqli_query($myConnection, $query);
			?>			
			<form action="../page_delete_parse.php" onsubmit="return confirm('- Are you sure you want to delete this page?')" method="post" />
			<select class="boxstyles" name='linklabel' />
			<?php			
			// printing the list box select command
			while($row=mysqli_fetch_array($result)){//Array or records stored in $row
			echo "<option value=\"$row[id]\">$row[linklabel]</option>";
			// Option values are added by looping through the array
			}
			?>
            </select>			
			<input type="submit" name="formSubmit"  value="&nbsp;Delete&nbsp;"/>
			</form>
			<?php
			mysqli_free_result($result);
			?>

And also, I think my code looks messy, if someone can help me organize it, so I only have the mysql parts in the top and then just drop the variables in the form when needed.

Ive tried to clean it up, but i managed to make in not work :-)

Klemme

//Get the id for the row to delete
$row_id = $_POST['linklabel'];

//Write the query
$sql = "DELETE FROM pages WHERE id=" . $row_id;

//Execute the query
$query = mysql_query($sql);
if($query){
     echo "The row is successfully deleted from the database."; 
}
else{
     die("Cannot delete the row. " . mysql_error());
     exit;
}

Hope this help!

Hey Zero13,

Thanks for your reply, but I think you have misunderstood my question.

My delete query is working fine, I was asking how i could include the pos when the drop down gets submitted, so I can do an update query too, on the position.

I think I can use a hidden field for this?

Look at the code below...I think so this is what you are looking for...

data.php

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("SELECT name FROM aaa")
or die("query error");
echo "<form action='' method='GET'>";
echo "<select name='s'>";
while($r=mysql_fetch_array($result))
{
//echo $r['name'];
echo "<option value='".$r['name']."'>".$r['name']."</option>";
}
echo "</select>";
echo "<input type='submit' value='submit' name='submit'>";
echo "</form>";
if(isset($_GET['s']))
{echo "<form action='abc.php'>";
echo "<input type='text' value='".$_GET['s']."' name='a'>";
echo "<input type='submit' value='submit' name='submit'>";
echo "<input type='hidden' value='".$_GET['s']."' name='b'>";
echo "</form>";
}
?>

abc.php

<?php
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
$db=mysql_select_db("abc",$con)
or die("database not found");
$result=mysql_query("UPDATE aaa SET name='".$_GET['a']."' where name='".$_GET['b']."'")
or die("query error");
header("Location:1.php");
?>

Hope this will solve your problem....

Well almost solved, but not entirely :-)

I am actually not looking to have another submit button, but as my code looks now, I am passing ID and LINKLABEL (from the DB), when the form below gets submitted.

As you can see I am also selecting pos (Which is position of the pages in my database) - AND I want to include the position in the same from, so when submitted, both, ID, LINKLABEL, and also POS gets submitted with the same submit button.

Here is the select box again - I have made a comment in ALL CAPS, where I think I can put the pos together as a value along side with the ID and the Linklabel (So one select box/form, and one submit button).

<?php 
//This dropdown is for page deleting!!
$query="SELECT id, linklabel, pos FROM pages ORDER BY pos ASC"; /*Notice: pos here! The value I want to include when submitted*/
$result = mysqli_query($myConnection, $query);
?>		
	
<form action="../page_delete_parse.php" onsubmit="return confirm('- Are you sure you want to delete this page?')" method="post" />
<select class="boxstyles" name='linklabel' />
<?php	
		
// printing the list box select command
while($row=mysqli_fetch_array($result)){//Array or records stored in $row
echo "<option value=\"$row[id]\">$row[linklabel]</option>";/*IN THIS LINE, WHERE I HAVE THE ID AND THE LINKLABEL - HOW CAN I ALSO ATTACH $ROW[POS]??? HOW DO I CONCATENATE THE VALUES, ISNT THAT POSSIBLE??*/
// Option values are added by looping through the array
}
mysqli_free_result;
?>
</select>	
		
<input type="submit" name="formSubmit"  value="&nbsp;Delete&nbsp;"/>

</form>
<?php
mysqli_free_result($result);
?>

Sorry if I was explaining badly before, but now I think it should be clear what I am trying to do :-)

Just an addition to the existing code, where $row[pos]; also gets included with the ID and LINKLABEL..

Because I need to update that in the database too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.