Jump to content

PythonHelp

Members
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

0 Neutral

About PythonHelp

  • Rank
    Member
  1. I didn't seem to locate the missing curly brace
  2. Hi ! I am trying to translate my mysqli count query that works perfectly into prepared statements. Unfortunately, after playing around and using my knowledge of PS, I have come up with this script which fails to execute and returns a http 500 error. I may have missed something very silly, I require some guidance on fixing the error. <?php $conn = mysqli_connect("xxxx", "xxxx", "xxxx", "xxx"); $sel_query = "SELECT S1, B1 COUNT(IF(S1 = ?, 1, NULL)) 'Accepted', COUNT(IF(S1 = ?, 1, NULL)) 'Rejected', COUNT(IF(S1 = ?, 1, NULL)) 'Under_Review' FROM Enrol"; $stmt = $conn->prepare($sel_query); $Accepted="Accepted"; $Rejected="Rejected"; $Under_Review="Under Review"; $stmt->bind_param("sss",$Accepted, $Rejected, $Under_Review); $stmt->execute(); $result = $stmt->get_result(); // get the mysqli result if($result->num_rows === 0) exit('No records found!'); while($row = $result->fetch_assoc()) { ?> <tr> <td><?php echo $row["Accepted"]; ?></td> <td><?php echo $row["Rejected"]; ?></td> <td><?php echo $row["Under_Review"]; ?></td> </tr> </table>
  3. I have but not sure which section can help me. Guidance needed please.
  4. Thank you so much, with your support, I am learning as well as becoming a step closer to the end result. So, after looking at the PHP manual, I have altered the script , but now it is producing the error ""Notice: Undefined index for the following lines: <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Present']; ?></td> <td><?php echo $row['Absent']; ?></td> Here is the entire code <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); ?> <?php //Connection for database $conn = mysqli_connect("xxx", "xxxxxxxxxx", "xxxxxxxxxx", "xxxxxxx"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); } $sql = "SELECT Form_Group, COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent FROM attendance"; ?> <!doctype html> <html> <body> <h1 align="center">Summary</h1> <table border="1" align="center" style="line-height:25px;"> <tr> <th>Form</th> <th>Present</th> <th>Absent</th> </tr> <?php //Fetch Data form database if ($result = mysqli_query($conn, $sql)) { while ($row = mysqli_fetch_row($result)) { ?> <tr> <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Present']; ?></td> <td><?php echo $row['Absent']; ?></td> </tr> <?php } mysqli_free_result($result); } mysqli_close($conn); ?> </table> </body> </html>
  5. I believe it is a mysql error , after removing the ' ' around the table name, I am getting: Fatal error: Call to undefined method mysqli_result::fetch_rows() in \\143FF240DC.STORAGE-1B.HOSTING.STACKCP.NET\SITES\1b\1\143ff240dc\public_html\Progress_Tracker\Pages\reports_attendance.php on line 65 After removing the single quotes, I am getting: Fatal error: Call to undefined method mysqli_result::fetch_rows() in \\143FF240DC.STORAGE-1B.HOSTING.STACKCP.NET\SITES\1b\1\143ff240dc\public_html\Progress_Tracker\Pages\reports_attendance.php on line 65
  6. Oh ok, so I fixed some foolish errors (missing commas etc) *embarassed* There now seems to be this final error but I just cant seem to spot what it is - near attendance $sql = "SELECT Form_Group, COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent FROM 'attendance'"; $result = $conn->query($sql); ?>
  7. Thank you Barand. The mysql server is showing the following error: Error 1: Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent, F' at line 3' Error 2: Line 47: $result = $conn->query($sql); i tried to follow the MariaDB syntax but to no success: $sql = "SELECT Form_Group COUNT(DISTINCT Presence LIKE '/') AS Present, COUNT(DISTINCT Presence LIKE 'N') AS Absent, FROM 'attendance'"; $result = $conn->query($sql);
  8. Error message is: Notice: Trying to get property of non-object in \\.........\reports_attendance.php on line ... I looked very closely at the query for a very long time and just cannot find the problem,. It worked well before using the case with just the one count, when the second count went in, it showed this error. I am new to PHP so any guidance or tutorial to help will be greatly appreciated.
  9. I am trying to run a count query and faced with the error: Notice: Trying to get property of non-object in Not sure how to resolve this error in these lines: if($result->num_rows > 0){ while($row = $result->fetch_rows()){ Code: <?php $sql = "SELECT Form_Group COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent, FROM 'attendance'"; $result = $conn->query($sql); ?> <?php //Fetch Data form database if($result->num_rows > 0){ while($row = $result->fetch_rows()){ ?> <tr> <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Present']; ?></td> <td><?php echo $row['Absent']; ?></td> </tr> <?php } } else { ?> <tr> <th colspan="6">There's No data found!!!</th> </tr> <?php } ?>
  10. Hello, Thank you, since learning how to turn on error reporting, I was able to resolve all the previous issues and I have used mysqli which has been new learning for me. I am now able to display filtered data using variables posted from a form and I am able to update the data from multiple rows. The problem I am having now is that after the update I need the table to display the data using the filter fields from the form that was originally submitted. But I am getting the errors: Notice: Undefined index: Att_Date on line 33 Notice: Undefined index: Form_Group on line 34 I have tried to use session but with no luck. I feel stuck at this point and need some guidance. <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> <?php //Connection for database $conn = mysqli_connect("xxxx", "xxxxxxxxx", "xxxxx", "xxxxxxx"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); } $Att_Date=$_POST['Att_Date']; $Form_Group=$_POST['Form_Group']; session_start(); /*session is started if you don't write this line can't use $_Session global variable*/ $_SESSION["newsession1"] = $Att_Date; $_SESSION["newsession2"] = $Form_Group; echo $_SESSION["newsession1"]; echo $_SESSION["newsession2"]; //Select Database $sql = "SELECT * FROM attendance WHERE Form_Group ='$Form_Group' AND Att_Date = '$Att_Date'"; $result = $conn->query($sql); ?> <?php /* Check if button name "Submit" is active, do this */ if(isset($_POST['Submit1'])) { header('Location: '.$_SERVER['REQUEST_URI']); $count=count($_POST["Student_id"]); for($i=0;$i<$count;$i++){ $sql1="UPDATE attendance SET Presence='" . $_POST['Presence'][$i] . "' WHERE Student_id='" . $_POST['Student_id'][$i] . "'"; $result = $conn->query($sql1); } } echo ""; ?> <!doctype html> <html> <body> <h1 align="center">Register</h1> <table border="1" align="center" style="line-height:25px;"> <tr> <th>Stduent ID</th> <th>Name</th> <th>Surname</th> <th>Form</th> <th>Year Group</th> <th>Date</th> <th>Presence</th> </tr> <?php //Fetch Data form database if($result->num_rows > 0){ while($row = $result->fetch_assoc()){ ?> <form method="post"> <tr> <td><input name="Student_id" type="text" value="<?php echo $row['Student_id']; ?>"></td> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Year_Group']; ?></td> <td><?php echo $row['Att_Date']; ?></td> <td><input name="Presence" type="text" value="<?php echo $row['Presence']; ?>"></td> </tr> <?php } } else { ?> <tr> <th colspan="6">There's No data found!!!</th> </tr> <?php } ?> </table> <p class="auto-style1"><input name="Submit1" type="submit" value="submit"></p> </form> </body> </html>
  11. It is supposed to execute the query after sub1 button is pressed on the form which has two fields : Form_Group and Att_Date. The query is: $sql=("SELECT * FROM $tbl_name WHERE Form_Group ='$Form_Group' AND Att_Date = '$Att_Date'");; The query displays no data matching the filter fields, although it worked with $sql="SELECT * FROM attendance";
  12. Sorry, I should have been clear The records display without the Where clause, however, when I refer to the controls on the form to filter the data no records are displayed. Why would only class A be displayed?
  13. Thank you guys. I got the script to display the data and also edit and refresh the page. I am now wanting to filter the data but it does not seem to work. The form with the filter fields: <body> <?php include 'Navigation.php';?> <form method="post" action="Registers_(1).php"> <table frame="box" border="0"align="center" style="width: 38%; height: 63px;"> <tr> <td class="auto-style2"><strong>Select Date</strong></td> <td class="auto-style3"><input name="Att_Date" type="date" />&nbsp;</td> </tr> <tr> <td class="auto-style2"><strong>Select Form Group</strong></td> <td class="auto-style3"><select name="Form_Group"> <option value='SELECT' selected="selected">SELECT</option> <option value='Class A'>Class A</option> <option value='Class A'>Class B</option> </select> </td> </tr> <tr> <td class="auto-style1" colspan="2"> <input name="Sub1" type="submit" value="Load Register" />&nbsp;</td> </tr> </table> </form> The php script: <?php $host="shareddb1d.hosting.stackcp.net"; // Host name $username="xxxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxxxx"; /* Table name */ // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(isset($_POST["Sub1"])){ $Att_Date=$_POST['Att_Date']; $Form_Group=$_POST['Form_Group']; } $sql=("SELECT * FROM $tbl_name WHERE Form_Group ='$Form_Group' AND Att_Date = '$Att_Date'";; $result=mysql_query($sql); /* Count table rows */ $count=mysql_num_rows($result); ?> <?php /* Check if button name "Submit" is active, do this */ if(isset($_POST['Submit'])) { header('Location: '.$_SERVER['REQUEST_URI']); $count=count($_POST["Student_id"]); for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET firstname='" . $_POST['firstname'][$i] . "', lastname='" . $_POST['lastname'][$i] . "', Presence='" . $_POST['Presence'][$i] . "' WHERE Student_id='" . $_POST['Student_id'][$i] . "'"; $result1=mysql_query($sql1); } } echo ""; mysql_close(); ?> <?php include 'Navigation.php';?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center" class="auto-style1"><strong>Id</strong></td> <td align="center" class="auto-style1"><strong>First Name</strong></td> <td align="center" class="auto-style1"><strong>Lastname</strong></td> <td align="center" class="auto-style1"><strong>Year Group</strong></td> <td align="center" class="auto-style1"><strong>Form Group</strong></td> <td align="center" class="auto-style1"><strong>Date</strong></td> <td align="center" class="auto-style3"><strong>Attendance</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"> <input name="Student_id[]" type="text" value="<?php echo $rows['Student_id']; ?>" readonly class="auto-style1"></td> <td align="center"> <input name="lastname[]" type="text" value="<?php echo $rows['lastname']; ?>" readonly class="auto-style1"><span class="auto-style1"> </span> </td> <td align="center"> <input name="firstname[]" type="text" value="<?php echo $rows['firstname']; ?>" readonly class="auto-style1"><span class="auto-style1"> </span> </td> <td align="center"> <input name="Year_Group[]" type="text" value="<?php echo $rows['Year_Group']; ?>" readonly class="auto-style1"><span class="auto-style1"> </span> </td> <td align="center"> <input name="Form_Group[]" type="text" value="<?php echo $rows['Form_Group']; ?>" readonly class="auto-style1"><span class="auto-style1"> </span> </td> <td align="center"> <input name="Att_Date[]" type="text" value="<?php echo $rows['Att_Date']; ?>" readonly class="auto-style1"><span class="auto-style1"> </span> </td> <td align="center" class="auto-style2"> <input name="Presence[]" type="text" value="<?php echo $rows['Presence']; ?>" class="auto-style1"><span class="auto-style1"> </span> </td> </tr> <?php } ?> <tr> <td colspan="7" align="right"> <input type="submit" name="Submit" value="Submit" class="auto-style1"></td> </tr> </table> </td> </tr> </form> </table>
  14. Ok the issue was <? so I added the <?php and it now displays the data from the table,. The next issue is, I update the value in the text box, after clicking submit, it shows the original value and not the updated (which means the value is probably not being updated in the database?
×
×
  • 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.