Jump to content

[SOLVED] php + drop down + validation :)


blueman378

Recommended Posts

hi guys. haha i must have started at least 10 posts on this forum, just in the last 10 days,

 

well anyway i have this code (snippet)

if ($_SERVER['REQUEST_METHOD'] != 'POST'){

echo "<b>1) Select the Game</b><br>";
//gameform
global $database;
    $q = "SELECT gName FROM " . games . "
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error()); 
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Games not found!';
    }
?>

<select name="name">
<?php
   while( $row = mysql_fetch_assoc($result) ) {
    echo '<option value="' . $row['gName'] . '">';
    echo $row[gName] . '</option>';
    }

?>
</select>
<br>
<br>
<?php 
//game form end

echo "<b>1) Select the Thumb</b><br>";
//gameform
global $database;
    $q = "SELECT * FROM " . games . "
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error()); 
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Thumbs not found!';
    }
?>

<select name="thumb">
<?php
   while( $row = mysql_fetch_assoc($result) ) {
    echo '<option value="' . $row['gThumb'] . '">';
    echo $row[gName] . '</option>';
    }

?>
</select>
<br>
<br>
<?php 
//game form end

echo "<INPUT type='reset' name='reset' value='Reset!'>  ";
echo "<INPUT type='submit' name='uninstall' value='uninstall!'></center>";
echo "</form>";
echo "<br><br>";
}
else{
$name = $_POST["name"];
$thumb = $_POST["thumb"];

echo "<b>Game Name: </b>";
echo "$name";
echo "<br><br>";
echo "<b>Uninstalled</b>";
echo "<br><br>";

rename("../thumbs_ins/$thumb", "../thumbs_uins/$thumb");
rename("../games_ins/$name", "../games_uins/$name");

mysql_query("DELETE FROM
".games."
WHERE gName='$name'
AND gThumb='$thumb'
  ") 
or die("Your have an error because:<br />" . mysql_error());

echo "1 game uninstalled";
}
?>

 

basically the code gets some info from the database ( its a game delete form) and fills some drop down boxes the user is then asked to select then game name, and the thumbfile ( both using the game name as 1.png makes it a bit hard) and then it moves the files to the uninstalled directory, and IF both the thumb file and game name are the same it deletes it from the database,

 

now what i am wanting is a simple if statement to be implemented so that the files are moved ONLY IF both drop down boxes are in the same column in the database,

 

simple enough?

 

thanks people,

 

xmas time is coming, so is a prezzy card ( prepaid credit card) so so is a donation :)

Link to comment
Share on other sites

I think this should work

 

change

rename("../thumbs_ins/$thumb", "../thumbs_uins/$thumb");
rename("../games_ins/$name", "../games_uins/$name");

mysql_query("DELETE FROM
".games."
WHERE gName='$name'
AND gThumb='$thumb'
  ") 
or die("Your have an error because:<br />" . mysql_error());

 

to

mysql_query("DELETE FROM
".games."
WHERE gName='$name'
AND gThumb='$thumb'
  ") 
or die("Your have an error because:<br />" . mysql_error());

if (mysql_affected_rows() > 0 )
{
rename("../thumbs_ins/$thumb", "../thumbs_uins/$thumb");
rename("../games_ins/$name", "../games_uins/$name");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.