Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL query is running but not running
    primarykey
    data
    text
    <p>Alright let me explain myself here:</p> <p>I am making an online text based game. I have a page where 3 things can happen:</p> <p> <li>They can create a position</li> <li>Can edit a position</li> <li>Can delete a position</li></p> <p>So far I have creating a position working. I moved on deleting a position next. All was good and I got no errors, no warnings, etc.. And when I ran it, it came back to the screen it was supposed to after the script to delete the position ran. It is only supposed to come here after the query runs.</p> <p>Well nothing happened and after 3 hours of trying crap I'm coming to you guys b/c I'm on my last leg. I still have no critical errors, nothing is making it fail: Here is my code.</p> <pre><code>&lt;?php //In the include file is the connection to the db include("library/new_library.php"); //Below is the session id, gets their position id from the DB, than grabs whether or not they can edit the company $user_id = $_SESSION['user_id']; $sql = "SELECT ID, PositionID FROM users WHERE ID = '$user_id'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { $position = $row['PositionID']; } $sql = "SELECT * FROM tblCPositions WHERE PositionID = '$position'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { $editCompany = $row['Edit_Company']; } //Next I check for position edit and if they try to put in the position id of a position the company does not control it gives them a "nice" message. $company = $_SESSION['company']; if($_GET['pidedit']){ $position = $_GET['pidedit']; $sql = "SELECT * FROM tblCPositions WHERE PositionID = '$position'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { if($row['CompanyID'] != $company) { $warning = "&lt;div class='warning'&gt;You are trying to edit a position that does not belong to your company. DO NOT TRY TO CHEAT THE SYSTEM!&lt;/div&gt;"; } else { $positionArray[] = array(ID =&gt; $row['PositionID'], name =&gt; $row['Name'], hire =&gt; $row['Hire'], fire =&gt; $row['Fire'], bid =&gt; $row['Contract'], edit =&gt; $row['Edit_Company'], finances =&gt; $row['Finances']); } } } //Here I check for $_GET delete elseif($_GET['piddelete']) { $position = $_GET['piddelete']; $sql = "SELECT * FROM tblCPositions WHERE PositionID = '$position'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { if($row['CompanyID'] != $company) { $warning = "&lt;div class='warning'&gt;You are trying to delete a position that does not belong to your company. DO NOT TRY TO CHEAT THE SYSTEM!&lt;/div&gt;"; } } } else { $sql = "SELECT * FROM tblCPositions WHERE CompanyID = '$company'"; $query = mysql_query($sql); $number = mysql_num_rows($query); $numberLeft = 12 - $number; while($row = mysql_fetch_assoc($query)) { $positionArray[] = array(ID =&gt; $row['PositionID'], name =&gt; $row['Name'], hire =&gt; $row['Hire'], fire =&gt; $row['Fire'], bid =&gt; $row['Contract'], edit =&gt; $row['Edit_Company'], finances =&gt; $row['Finances']); } } // if($_POST['submitNewPosition']) { $name = $_POST['positionName']; $hire = $_POST['hire']; $fire = $_POST['fire']; $bid = $_POST['bid']; $edit = $_POST['edit']; $finances = $_POST['finances']; $cid = $_SESSION['company']; $sql = "INSERT INTO tblCPositions(CompanyID, Name, Hire, Fire, Contract, Edit_Company, Finances) VALUES ('$cid','$name','$hire','$fire','$bid','$edit','$finances')"; $query = mysql_query($sql); if($query) { header("location: view_company.php?newp=success"); } } //Haven't finished this section yet if($_POST['submitEditPosition']) { $name = $_POST['positionName']; $fire = $_POST['hire']; $fire = $_POST['fire']; $bid = $_POST['bid']; $edit = $_POST['edit']; $finances = $_POST['finances']; } //This this is my problem area, this is where it says its running the query but its not. if(isset($_POST['deletePosition'])) { $deleteID = $_GET['piddelete']; $deleteSql = "DELETE FROM tblCPositions WHERE PositionID = '$deleteID'"; $deleteQuery = mysql_query($deleteSql); if($deleteQuery) { header("location: view_company.php?delete=success"); } if(!$deleteQuery) { header("location: view_company.php?delete=failure"); } } </code></pre> <p><strong>UPDATE</strong> - </p> <p>Ok so I got it working the problem was something I forgot, this form was just meant to be a "yes or no form" so I was doing post only to post the submit button, nothing else was on the form. What I had forgot was on the action="file.php" (what I had) I had forgotten to pass on the get variable so once I changed it to action="file.php?piddelete=12" it worked.</p> <p>Thanks for everyones help I really appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload