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
roondog
Forum Newbie
Posts: 18 Joined: Sun Jul 22, 2007 11:56 am
Post
by roondog » Tue Oct 09, 2007 6:21 am
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
here is my codeCode: Select all
<?php
$con = mysql_connect('localhost', '******', '******');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ('roondog_gallery', $con);
mysql_query("DELETE FROM test WHERE picname=$_POST[remove]");
mysql_close($con);
?>
and my form
Code: Select all
<html>
<head>
<style type="text/css">
img{
width: 100px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$con = mysql_connect('localhost', '******', '*****'}
mysql_select_db('roondog_gallery', $con);
$result = mysql_query("SELECT * FROM test");
while($row = mysql_fetch_array($result))
{
echo "<form action='picdelete.php' method='post'>";
echo "<img src='$row[picname]' />";
echo "<input type='checkbox' name='remove' value='$row[picname]' />";
}
echo "<input type='submit' value='delete picture' />";
echo "</form>";
if (mysql_rows_affected() => 1){
echo
?>
</body>
</html>
i get no errors but the columns are not deleting.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by
roondog on Tue Oct 09, 2007 6:28 am, edited 1 time in total.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Oct 09, 2007 6:24 am
This
roondog wrote: here is my code
Code: Select all
mysql_query("DELETE FROM test WHERE picname=$_POST[remove]");
should be
Code: Select all
mysql_query("DELETE FROM test WHERE picname=".$_POST['remove']);
in case picname is ID (i.e. numeric)
or
Code: Select all
mysql_query("DELETE FROM test WHERE picname='".$_POST['remove']."'");
in case picname is a string.
EDIT: Gosh! I always forgot that it is valid syntax in PHP ( "blah-blah $array[key]")
Last edited by
VladSun on Tue Oct 09, 2007 7:43 am, edited 2 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
olog-hai
Forum Commoner
Posts: 34 Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada
Post
by olog-hai » Tue Oct 09, 2007 6:25 am
Do this to check if you have something:
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Oct 09, 2007 6:35 am
I must warn you that passing $_POST values directly into the SQL query is a huge security risk. You should validate/sanitize the user input data.
There are 10 types of people in this world, those who understand binary and those who don't
roondog
Forum Newbie
Posts: 18 Joined: Sun Jul 22, 2007 11:56 am
Post
by roondog » Tue Oct 09, 2007 7:26 am
Thanks, i'm just trying to get it to work first. Also thanks for the quick response but it's still not working.
miro_igov
Forum Contributor
Posts: 485 Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria
Post
by miro_igov » Tue Oct 09, 2007 7:31 am
Do you have display_errors disabled?
This is very strange construction at the end of your form:
Code: Select all
if (mysql_rows_affected() => 1){
echo
?>
roondog
Forum Newbie
Posts: 18 Joined: Sun Jul 22, 2007 11:56 am
Post
by roondog » Tue Oct 09, 2007 7:41 am
i started writing something but i've deleted that now.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Oct 09, 2007 7:45 am
Please, post your new code and the result from:
as olog-hai has suggested.
There are 10 types of people in this world, those who understand binary and those who don't
roondog
Forum Newbie
Posts: 18 Joined: Sun Jul 22, 2007 11:56 am
Post
by roondog » Tue Oct 09, 2007 7:58 am
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
code is:Code: Select all
<?php
$con = mysql_connect('localhost', 'roondog', 'twiggy');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ('roondog_gallery', $con);
if($POST['picname']){
mysql_query("DELETE FROM test WHERE picname=' " .$_POST['remove']. "'");
}
print_r($_POST);
mysql_close($con);
?>
form is
Code: Select all
<html>
<head>
<style type="text/css">
img{
width: 100px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$con = mysql_connect('localhost', 'roondog', 'twiggy');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('roondog_gallery', $con);
$result = mysql_query("SELECT * FROM test");
while($row = mysql_fetch_array($result))
{
echo "<form action='picdelete.php' method='post'>";
echo "<img src='$row[picname]' />";
echo "<input type='checkbox' name='remove' value='$row[picname]' />";
}
echo "<input type='submit' value='delete picture' />";
echo "</form>";
?>
</body>
</html>
result form print_r($POST) is
Array ( [remove] => ./images/alfie.jpg )
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Oct 09, 2007 8:03 am
You have a redundant white space in your query - between the first single quote and the double quote.
And what is:
???
you don't have a $_POST key "picname" in your form neither you have $POST array- it is $_POST.
There are 10 types of people in this world, those who understand binary and those who don't
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Oct 09, 2007 9:52 am
There are escaping/validation issues to contend with as well. Since we have many threads dedicated to these topics, I'll let you search them out instead of rehashing.