Jump to content

jupiter

New Members
  • Posts

    4
  • Joined

  • Last visited

jupiter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I tried wrapping my code in a for loop as outlined above and I couldn't get it to work. So I'm trying Plan B. $fileTypeExt = pathinfo($path1,PATHINFO_EXTENSION); echo $fileTypeExt . "<br/>"; $fileTypeExt2 = pathinfo($path2,PATHINFO_EXTENSION); echo $fileTypeExt2 . "<br/>"; // Allow certain file formats if($fileTypeExt == "txt" || $fileTypeExt == "doc" || $fileTypeExt == "pdf") { echo "Your file extensions are allowed."; $uploadOk = 1; } else { echo "Sorry, only TXT, PDF, & DOC files are allowed. <br />"; $uploadOk = 0; } // Allow certain file formats if($fileTypeExt2 == "txt" || $fileTypeExt2 == "doc" || $fileTypeExt2 == "pdf") { echo "Your file extensions are allowed."; $uploadOk2 = 1; } else { echo "Sorry, only TXT, PDF, & DOC files are allowed. <br />"; $uploadOk2 = 0; } Plan B works, but I was wondering if there's a more compact way to write this. I frequently get tripped up on how to extend working logic to additional cases. For instance, do I need a $fileTypeExt and $fileTypeExt2 variables? Same with $uploadOk and $uploadOk2? I guess a switch statement would work if I had many cases. Perhaps one answer is to make a giant conditional, e.g., if($fileTypeExt == "txt" || $fileTypeExt == "doc" || $fileTypeExt == "pdf") && ($fileTypeExt2 == "txt" || $fileTypeExt2 == "doc" || $fileTypeExt2 == "pdf")...but I didn't know if that was the best approach. It would remove the need for two status variables ($uploadOk and $uploadOk2). Thanks in advance for your ideas.
  2. I'm working on a two-file upload form and want to be able to check the mime types of two filenames in a string variable. The code below was working when the variable @resume_path contained just one filename. How can I modify this to accommodate two files? when I echo $resume_path, I get, for example: cover_letter_centerline.doc, cover_letter_ctg.doc Thanks! //DO NOT TRUST $_FILES['upfile']['mime'] VALUE !! //Check MIME Type by yourself. $finfo = new finfo(FILEINFO_MIME_TYPE); if (false === $ext = array_search( $finfo->file($_FILES['resume_path']['tmp_name']), array( 'txt' => 'text/plain', 'doc' => 'application/msword', 'pdf' => 'application/pdf', ), true )) { throw new RuntimeException('Invalid file format.'); } echo "Sorry, invalid file format. Please try again."; echo $ext;
  3. @Ch0cu3r Thanks. That worked. I replaced: $result = mysqli_query($link, $sql) or die(mysql_error()); with $result = mysqli_query($link, $sql) or die('Connect Error: ' . mysqli_connect_error()); and my page is rendering completely.
  4. I'm experimenting with a basic CRUD App. The table created by the code below renders, however when I view source, the last tag is the closing </tr> after the while loop finishes. There's nothing after that. No closing table, html, or body tags. I can't see what I've done wrong. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Eric's PHP CRUD App</title> <style type="text/css"> table { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; text-align: center; margin: 0 auto; } table td { text-align:center; border: 1px solid #dfdfdf; } tr:nth-child(odd) { background: #fdfdfd; } tr:nth-child(even) { background: #B8D3FF; } th { background-color:#ccc; } .center { width: 1050px; margin:0px auto; } h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; padding-bottom: 15px; text-align: center; margin: 0 auto; color: white; } </style> </head> <body bgcolor="#999"> <?php require_once("db_connect.php"); echo "<h1>Update Student Records</h1>"; echo "<table cellpadding='10'>"; echo "<tr bgcolor='#cccccc'>"; echo "<th>First Name</th>"; echo "<th>Last Name</th>"; echo "<th>Test 1 Grade</th>"; echo "<th>Test 2 Grade</th>"; echo "<th>Test 3 Grade</th>"; echo "<th>Test 4 Grade</th>"; echo "<th>Final Exam Grade</th>"; echo "<th>Average Grade</th>"; echo "<th>Final Grade</th>"; echo "<th>delete</th>"; echo "<th>edit</th>"; echo "</tr>"; $sql = "SELECT * FROM students"; $result = mysqli_query($link, $sql) or die(mysql_error()); while($row = mysqli_fetch_array($result, MYSQLI_ASSOC) or die(mysql_error())) { $final = ""; $average = (($row["test1Grade"]) + ($row["test2Grade"]) + ($row["test3Grade"]) + ($row["test4Grade"]) + ($row["finalExamGrade"])) / 5; if ($average >= 90) { $final = "A"; } else if ($average >= 80) { $final = "B"; } else if ($average >= 70) { $final = "C"; } else if ($average >= 60) { $final = "D"; } else if ($average < 60) { $final = "F"; } echo "<tr>"; echo "<td>" . $row["firstName"] . "</td>"; echo "<td>" . $row["lastName"] . "</td>"; echo "<td>" . $row["test1Grade"] . "</td>"; echo "<td>" . $row["test2Grade"] . "</td>"; echo "<td>" . $row["test3Grade"] . "</td>"; echo "<td>" . $row["test4Grade"] . "</td>"; echo "<td>" . $row["finalExamGrade"] . "</td>"; echo "<td>" . round($average) . "</td>"; echo "<td>" . $final . "</td>"; echo "<td><a href='delete.php?id=" . $row['studentID'] . "'>›</a></td>"; echo "<td><a href='update.php?id=" . $row['studentID'] . "'>›</a></td>"; echo "</tr>"; } echo "</table>"; ?> <a href='insert.php'>Add new student</a> </body> </html>
×
×
  • 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.