Hey guys! Fairly new with PHP/MySQL and been working on a website for a class, and having some issues with my drop down not working as intended. What I’m trying to do is simply allow the user to select a name from a drop down field, then after pressing the submit button, would delete the selected name from the database. Here is my code.
<?php ini_set('display_errors', 'on'); error_reporting(E_ALL); session_start(); $_SESSION['title'] = "PEC Menu"; //Opening Session Vars $currentFile = $_SERVER["PHP_SELF"]; //current page for menu $currentUser = $_SESSION['currentname']; // users account info include('../../functions/mainmenu.php'); // menu functions //Menu Content,Code / Buttons Goes here DrawMenu($currentFile, $currentUser); //Setting up database mysql_connect("localhost","root","changeme"); mysql_select_db("certestdb"); $dbLink = mysql_connect("localhost", "root", "changeme"); mysql_query("SET character_set_client=utf8", $dbLink); mysql_query("SET character_set_connection=utf8", $dbLink); $result = mysql_query("SELECT distinct TermID FROM clinical") or die(mysql_error()); $result2 = mysql_query("SELECT FullName FROM useraccess") or die(mysql_error()); $options=''; $options2=''; while($row=mysql_fetch_array($result)) { if (isset($_POST)) { $TermID=$row["TermID"]; $options.= ''.$row['TermID'].''; } }; while($row=mysql_fetch_array($result2)) { if (isset($_POST)) { $FullName=$row["FullName"]; $options2.= ''.$row['FullName'].''; } }; if (isset($_POST)) { mysql_query("DELETE FROM useraccess WHERE FullName='$FullName'") or die(mysql_error()); echo "Success!"; } else { echo "Not successful"; } ?>Add User
<hr size = "5" color = "darkgray">
Assign User to Course
User: </select>
Course:
<select>
</select>
Term:
<SELECT NAME= termid>
<OPTION VALUE=0>Choose</OPTION>
<?php echo $options; ?>
</select>
<input type="submit" value="Assign">
</form> <br><br>
Assign Student to Instructor
Student:
<select>
<option value = "Select"> Select</option>}
<option value = "one"> 1</option>}
<option value = "two"> 2</option>}
<option value = "three"> 3</option>}
</select>
Course:
<select>
<option value = "Select"> Select</option>}
<option value = "one"> 1</option>}
<option value = "two"> 2</option>}
<option value = "three"> 3</option>}
</select>
Instructor:
<select>
<option value = "Select"> Select</option>}
<option value = "one"> 1</option>}
<option value = "two"> 2</option>}
<option value = "three"> 3</option>}
</select>
<input type="submit" value="Assign">
</form><br><br>
Delete User
User:
<SELECT NAME= FullName>
<OPTION VALUE=0>Choose</OPTION>
<?php echo $options2; ?>
</select>
<input type="submit" name="delete" value="delete">
</form><br><br>
<?php ?>
This is where the issue is
if (isset($_POST)) {
mysql_query(“DELETE FROM useraccess WHERE FullName=’$FullName’”) or die(mysql_error());
echo “Success!”;
} else {
echo “Not successful”;
}
What happens is upon submitting, it just deletes the last 2 records in the table “useraccess”.
If anyone could help me, it would be very much appreciated it.