Page 1 of 1

Value zero

Posted: Wed Jun 21, 2006 7:28 am
by NiGHTFiRE
This is my code:

Code: Select all

<?php 
$mysql_server = "xxx"; 
$mysql_user = "xxx"; 
$mysql_password = "xxx"; 
$mysql_database = "xxx"; 
  
$conn = mysql_connect($mysql_server, $mysql_user, $mysql_password); 
mysql_select_db($mysql_database, $conn); 
$sql = "SELECT * 
                FROM auction 
                ORDER BY id DESC"; 
if (!$result = mysql_query($sql)) 
{ 
        die("Could not get the item list: " . mysql_error()); 
} 

echo '<form method="post" action="tabortauktion.php">'; 
echo '<select name="auction">'; 
while ($row = mysql_fetch_array($result)) 
{ 
        echo '<option value="' . $row['id'] . '">' . $row['auktionnamn'] . '</option>'; 
} 
echo '</select>'; 
echo "<input type='submit' name='submit' value='Få fram auktion'>"; 
echo '</form>'; 
?> 
<?php 
include "connect.php"; 
error_reporting(E_ALL); 

if (isset($_POST['auction'])) 
{ 
        // You would really want to validate this here, 
        // But I am keeping this intentionally simple 
       $item_id = $_POST['auction']; 

        $sql = "SELECT * 
                        FROM auction 
                        WHERE id = $item_id ORDER BY id DESC"; 
        if (!$result = mysql_query($sql)) 
        { 
                die("Could not get the selected item: " . mysql_error()); 
        } 
                
        $item_array = mysql_fetch_array($result); 
        $sql2 = "SELECT * FROM bud WHERE item = $item_id"; 
                    if (!$result2 = mysql_query($sql2)) 
        { 
                die("Could not get the selected item: " . mysql_error()); 
        } 
                
                
        echo '<form method="post" action="tabortauktion.php">'; 
                echo 'Ta bort denna auktion: '; 
                echo "<br>"; 
echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value=''" . $row['auktionnamn'] . ">"; 
                echo "<br>"; 
        echo '</form>'; 
                echo "<br>"; 
                                echo "<input type='submit' name='submit' value='Få fram fakta'>"; 
                
//if($_POST['tabort_ja']) { 
//$sql2 = "DELETE * FROM auction WHERE id = $item_id LIMIT 1"; 
//$result2 = mysql_query($sql2) or die(mysql_error()); 
//echo "Auktionen har blivit raderat"; 
//echo "<a href='admin.php'>Tillbaka till Admin Panelen</a>"; 
//break; 
//} 
        if($_POST['tabort_ja']) 
        { 
          $tabort=addslashes($_POST['tabort_ja']); 
          mysql_unbuffered_query("DELETE FROM auction WHERE id=$tabort"); 
    } 
        if(!$result=mysql_query("SELECT id,auktionnamn,item,datum_borja,maxantalbud,antalbud,bild,marknadsvarde,info,status FROM `auction` ORDER BY `id`"))echo(mysql_error()); 
} 
?>



The checkbox got the value zero so none gets deleted. How should i solve it?
Thanks

Posted: Wed Jun 21, 2006 8:40 am
by bdlang
Can you please elaborate on the problem? Is that supposed to be two seperate scripts? Please be more specific.

Posted: Wed Jun 21, 2006 9:10 am
by NiGHTFiRE
Okey. Well first there is a script which shows all data from a mysql table and shows it in a select many. And then when you press submit You should get a checkbox with the value of the id of that mysql row. And then when you press on that submit button that row should get deleted.
Understand?
Thanks

Posted: Wed Jun 21, 2006 9:17 am
by bdlang
NiGHTFiRE wrote:Okey. Well first there is a script which shows all data from a mysql table and shows it in a select many. And then when you press submit You should get a checkbox with the value of the id of that mysql row. And then when you press on that submit button that row should get deleted.
Understand?
Thanks
Yes, but are you saying the value in all the checkboxes are zero, or that when you get to the DELETE portion of your code, the value is zero? Have you checked the HTML source output from the script? One thing I can see is you're using addslashes to the value of $_POST['tabort_ja'], which appears to be the ID value brought down from the form submission. Are you certain magic_quotes are off? Do you need to use an escaping slash at this point? Would it make more sense to use is_numeric() on the $_POST index value first?

Is this code responsible for the checkbox with the ID value?

Code: Select all

echo " Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value=''" . $row['auktionnamn'] . ">";
What is the HTML output of this? Is 'auktionnamn' the record ID value?

Posted: Wed Jun 21, 2006 9:41 am
by NiGHTFiRE
This is the output of it:
<input type="checkbox" name="tabort_ja" value="">

So the value is empty. Don't know how i will give it the id of that row.
$row['auktionnamn'] is a name, $row['id'] is the id of that row but it doesn't work.

Thanks

Posted: Wed Jun 21, 2006 11:25 am
by bdlang
NiGHTFiRE wrote:This is the output of it:
<input type="checkbox" name="tabort_ja" value="">

So the value is empty. Don't know how i will give it the id of that row.
$row['auktionnamn'] is a name, $row['id'] is the id of that row but it doesn't work.

Thanks
Ok, so shouldn't the output look like

Code: Select all

<input type="checkbox" name="tabort_ja" value='2' />Record Name
Try changing your script to

Code: Select all

echo "Ja&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tabort_ja' value='{$row['id']}' />{$row['auktionnamn']}";

Posted: Wed Jun 21, 2006 11:43 am
by NiGHTFiRE
Still gives me <input type='checkbox' name='tabort_ja' value='' />

Posted: Wed Jun 21, 2006 11:45 am
by feyd
$row is false by the time you are working with it there.