php mssql help

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

Post Reply
Forum Newbie
Posts: 3
Joined: Thu Jul 07, 2022 8:43 am

php mssql help

Post by mkamp81 »

I have in this php code, mssql script that was pulling 100s of records. I was able to fix that but now when a user selects a campus, it will not load any data for the campuses, it is blank. Can someone help me figure out how I need to rework either the script of the if statement? I am new to php but learning. Thanks

Code: Select all

 <div class="container container-rounded bg-1">
      <form action="user_list.php" method="post">
        <select name="campus">
          <option value="999">All</option>
          <option value="101">Vandagriff</option>
          <option value="102">Coder</option>
          <option value="103">Stuard</option>
          <option value="104">McCall</option>
          <option value="105">Walsh</option>
		  <option value="106">Annetta</option>
          <option value="107">Early Childhood Academy</option>
          <option value="041">Aledo Middle School</option>
		  <option value="042">McAnally Middle School</option>
          <option value="009">Daniel</option>
          <option value="001">High School</option>
        Last Name: 
        <input type="text" name="query" /> 
        <input type="submit" value="Search" />
        <!--	if ($_SESSION['access'] == 2){-->
		<!--Student ID: <input type="text" name="query" value= '.$row['stu_id'].'> />
		<button type="submit" class="btn btn-primary btn-sm">Details</button>-->
        if (!( isset($_POST['query']))) {
            echo "    </div>\n";
            echo "</body>\n";
            echo "</html>";
            $lname= check_input($_POST['query']);
            $campus = check_input($_POST['campus']);
            $lname = $lname . '%';
        $connectionInfo = array(  "UID"=>$dbuser,
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
        if( $conn === false ){
            echo "Unable to connect.</br>";
            die( print_r( sqlsrv_errors(), true));
$query = "declare @pagenumber int SET @PageNumber = 1 declare @pagesize int set @pagesize = 75 select * from (SELECT ROW_NUMBER() OVER (ORDER BY T1.stu_id asc) AS RowNum,T1.stu_id, T1.Student_ControlNumber,T1.StateStudentID, T1.grd_lvl, T1.name_f, T1.name_l ,T1.name_m, CONVERT(varchar(24),T1.StudentDOB) as 'studentDOB', T2.common_name, RTRIM(T1.Pre2000StudentLogin) AS networklogin,RTRIM(T1.Pre2000StudentLogin) + '' AS gaccount" .
                " FROM [Students] AS T1 INNER JOIN [Campus] AS T2 ON T1.campus_id = T2.campus_id " .
                " WHERE name_l LIKE '%s' AND T1.LastUpdate = (SELECT MAX(LastUpdate) FROM [Students])) as student_records where RowNum between (((@pagenumber - 1) * @pageSize )+ 1) 
and (@pagenumber * @pageSize ) ";
    if ($campus <> '999'){
            $query = $query . " AND common_name = '%s' ORDER BY name_l, name_f";
            $tsql = sprintf($query,$lname,$campus);
            $query = $query . " ORDER BY name_l, name_f";
            $tsql = sprintf($query,$lname);
        $stmt = sqlsrv_query( $conn, $tsql);
        if( $stmt === false ){
            echo "Error in executing query.</br>";
            die( print_r( sqlsrv_errors(), true));
User avatar
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: php mssql help

Post by Benjamin »

Use the following line to turn on display errors, so you can see what the error is:

Code: Select all

ini_set('display_errors', 1);
Post Reply