just a simple array !!!

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

yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Just change this....

Code: Select all

$zeile=mysql_fetch_array($result); 


echo "{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}"; 


mysql_close(); 
?>
To this...

Code: Select all

if ( mysql_num_rows ( $result ) > 0 )
{
	while ( $zeile = mysql_fetch_assoc ( $result ) )
	{
		echo "{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}";
	}
}
else
{
	echo 'Query returned 0 rows';
}

mysql_close();

?>

yj
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Yeah ... nice one - working ..
just one more thing :roll:
i want to delete a file:

Code: Select all

<html><body>
<?php
error_reporting(E_ALL);

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());
$sql = "SELECT * FROM sam_artikel" or die ("MySQL-Fehler: " . mysql_error());
$result=mysql_query($sql) or die(mysql_error());


if ( mysql_num_rows ( $result ) > 0 )
{
    while ( $zeile = mysql_fetch_assoc ( $result ) )
    {
        echo "<p>{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}</p>";
    }
}
else
{
    echo 'Query returned 0 rows';
}

if ($knopf && $knopf=="delete"){

	if ($_POST['number'] != ""){  
 
	    @delete($_POST['number'],$db); 
	}
}
mysql_close();
?>

<br><br>Welchen Artikel wollen Sie löschen? Geben Sie bitte die id ein:<br><br>
<form method="post">
<input type="text" name="number" length="3">
<input type="submit" name="knopf" value="delete">

</body>
</html>
Something is still wrong!
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Change this....

Code: Select all

if ($knopf && $knopf=="delete"){ 

    if ($_POST['number'] != ""){   

        @delete($_POST['number'],$db); 
    } 
}

To this....

Code: Select all

if ( isset ( $_POST['knopf'] ) && $_POST['knopf'] == 'delete' )
{
	if ( isset ( $_POST['number'] ) && intval ( $_POST['number'] ) != 0 )
	{
		$sql = "DELETE FROM sam_artikel WHERE column_id = " . intval ( $_POST['number'] );

		mysql_query ( $sql ) or die ( 'MySQL-Fehler: ' . mysql_error () ); 
	}
}
Then....

Change * column_id * in my code to the * column_name in your database * that contains the * id * to delete by!



yj
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

*** OMG ***
PERFEKT
THANK YOU SO MUCH
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

OHHH one more thing ...
the files that i want to delete are not just numbers ...
some files are also named dss or something like that ..
with the delete script i use now i can only delete numbers !!!
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Ok then change this....

Code: Select all

if ( isset ( $_POST['knopf'] ) && $_POST['knopf'] == 'delete' ) 
{ 
    if ( isset ( $_POST['number'] ) && intval ( $_POST['number'] ) != 0 ) 
    { 
        $sql = "DELETE FROM sam_artikel WHERE column_id = " . intval ( $_POST['number'] ); 

        mysql_query ( $sql ) or die ( 'MySQL-Fehler: ' . mysql_error () ); 
    } 
}
to this....

Code: Select all

if ( isset ( $_POST['knopf'] ) && $_POST['knopf'] == 'delete' ) 
{ 
    if ( isset ( $_POST['number'] ) && trim ( $_POST['number'] ) != '' ) 
    { 
        $sql = "DELETE FROM sam_artikel WHERE column_id = '" . mysql_real_escape_string ( $_POST['number'] ) . "'"; 

        mysql_query ( $sql ) or die ( 'MySQL-Fehler: ' . mysql_error () ); 
    } 
}
Then like before....

Change * column_id * in my code to the * column_name in your database * that contains the * id * to delete by!

yj
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

hmmmm
no thats not working
i chaged it like this:

Code: Select all

if ( isset ( $_POST['knopf'] ) && $_POST['knopf'] == 'delete' )
{
    if ( isset ( $_POST['number'] ) && trim ( $_POST['number'] ) != '' )
    {
        $sql = "DELETE FROM sam_artikel WHERE eqdes = '" . mysql_real_escape_string ( $_POST['number'] ) . "'"; 
    }
}
now its not deleten anything ...
not even numbers...=(
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Maybe your PHP version is old!

in my code change this....

Code: Select all

mysql_real_escape_string ( $_POST['number'] )

to this....

Code: Select all

addslashes ( $_POST['number'] )

yj
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_real_escape_string() (when using MySQL) is suggested over using addslashes()
Post Reply