简体   繁体   中英

my query wont work what should i do?

/this is my code, what do you think is the problem in my code. Department doesn't exist in my form so i just give it a value of 7.I want to call from department table that have the departmentId of 7. $res doesn't execute so it must be in my query, please help

$department = 7;
$depId   = "SELECT * FROM departments";

$query_dept         = mysql_query($depId, $conn);
$query_dept_results = mysql_fetch_array($query_dept);



if($query_dept_results['departmentId'] == $department) {
   $id    = $query_dept_results['departmentId'];      
   $query = "INSERT INTO suggestion (departmentId,name,address,barangay,message) VALUES('$id','$sfullname','$saddress','$sbarangay','$smessage')";
   $res = mysql_query($query);
  }
   if ($res) {
    $errTyp = "success";
    $errMSG = "Sending successfully";
    unset($sfullname);
    unset($saddress);
    unset($sbarangay);
    unset($smessage);
    header("Location:pupuntahan.php");
   } else {
    $errTyp = "danger";
    $errMSG = "Something went wrong, try again later..."; 
   }

your query need where clause.so change in sql stament like this

$depId   = "SELECT * FROM departments where departmentId = '$department'";

it will return which have departmentId of 7.

side note :- security.database.sql-injection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM