Jump to content

cainam29

Members
  • Posts

    75
  • Joined

  • Last visited

cainam29's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks Barand. That actually did the trick, I never had thought that there was an All vs ALL issue in the code.
  2. Thanks Barand, So here would be the updated code to fetch data, <?php$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDBPDO"; // check data before use it and convert from string to expected type, use try, not like here: $status = $_POST['status']; $date = $_POST['date']; $date1 = $_POST['date1']; // use valid data to select rows try { //1. connect to MySQL database $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); //2. set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //3. create query string $sql = 'SELECT column1, column2, status FROM tracker WHERE 1=1'; if ($status != 'ALL') $sql .= ' AND status = :st'; $sql .= ' AND scheduled_start_date BETWEEN :d1 AND :d2'; //4. prepare statement from query string $stmt = $conn->prepare($sql); //5. bind optional parameters if ($status != 'ALL') $stmt->bindParam(':st', $status); //6. bind parameters $stmt->bindParam(':d1', $date); $stmt->bindParam(':d2', $date1); //7. execute statement $stmt->execute(); //8. returns an array containing all of the result set rows $result = $stmt->fetchAll(PDO::FETCH_ASSOC); //get count of rows $numrow = count($result); //print array - there is many solution to print array, //to debug you can do: //print_r($result); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; if($numrow == 0) echo "No results found."; else echo "Count: $numrow</br>"; { echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th align='center'><strong>Column1</strong></th> <th align='center'><strong>Column2</strong></th> <th align='center'><strong>Status</strong></th> </tr>"; foreach ($result as $row => $info) { echo "<form action='crqretrieve_status_test1.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['column1'] . "<input type=hidden name=column1 value=" . $info['column1'] . " </td>"; echo "<td align='center'>" . $info['column2'] . "<input type=hidden name=column2 value=" . $info['column2'] . " </td>"; echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . " </td>"; echo "</tr>"; echo "</form>"; } } echo "</table>"; ?> And Select Options 1-4 works when selected individually but not when selecting ALL (which means selecting all options at the same time), <select name="status" id="status" style="width: 224px;"> <option value="" selected="selected">Please select...</option> <option value="All">All</option> <option value="Option1">Option1</option> <option value="Option2">Option2</option> <option value="Option3">Option3</option> <option value="Option4">Option4</option> </select> I tried to print the result and I am just getting Status select options 1-4 must be showing in the table If I filter Status to ALL but I am not getting anything. I wonder where the issue is now.
  3. Thanks for the response mac_gyver. So here's what I tried, I updated my code to fetch data to below, <?php$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDBPDO"; // check data before use it and convert from string to expected type, use try, not like here: $status = $_POST['status']; $date = $_POST['date']; $date1 = $_POST['date1']; // use valid data to select rows try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //create query string $sql = 'SELECT column1, column2, status FROM tracker WHERE 1=1'; if ($status != 'ALL') $sql .= ' AND status = :st'; $sql .= ' AND scheduled_start_date BETWEEN :d1 AND :d2'; // prepare sql $stmt = $conn->prepare($sql); //bind parameters if ($status != 'ALL') $stmt->bindParam(':st', $status); $stmt->bindParam(':d1', $date); $stmt->bindParam(':d2', $date1); $stmt->execute(); //do some output $result = $stmt->fetchAll(); print_r($result); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } //to count if there are any results $numrow = mysql_num_rows($result); if($numrow == 0) { echo "No results found."; } else { echo "CRQ Count: $numrow"; } { echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th align='center'><strong>Column1</strong></th> <th align='center'><strong>Column2</strong></th> <th align='center'><strong>Status</strong></th> </tr>"; while($info = mysql_fetch_array($result)) { echo "<form action='retrieve_status.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['column1'] . "<input type=hidden name=column1 value=" . $info['column1'] . " </td>"; echo "<td align='center'>" . $info['column2'] . "<input type=hidden name=column2 value=" . $info['column2'] . " </td>"; echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . " </td>"; echo "</tr>"; echo "</form>"; } } echo "</table>"; include 'include/DB_Close.php'; $conn = null; ?> But I am getting the error below when I am selecting ALL, Line 69 refers to $numrow = mysql_num_rows($result); Line 98 refers to while($info = mysql_fetch_array($result)) And when i select any of the option I am getting the message, And the same error as selecting ALL, I kind of lost from here and do not know how to proceed anymore.
  4. I have seen a lot of demos or sort of the same questions with the Select All option. But what I want is to just have a drop down that will allow me to select All option and not showing the entire Select box. Individual Select option works but not when I tried to use ALL as an option. Here is my sample HTML: <select name="status" id="status" style="width: 224px;"> <option value="" selected="selected">Please select...</option> <option value="All">All</option> <option value="Option1">Option1</option> <option value="Option2">Option2</option> <option value="Option3">Option3</option> <option value="Option4">Option4</option> </select> From the code above I would want to filter the result using the All option. So this is the page is where I filter and show the results in a table, <script> $(document).ready(function(){ $("#results").show(); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#RetrieveList").on('click',function() { var status = $('#status').val(); var date = $('#Date').val(); var date1 = $('#Date1').val(); $.post('retrieve_status.php',{status:status, date:date, date1:date1}, function(data){ $("#results").html(data); }); return false; }); }); </script> <form id="form2" name="form2" method="post" action=""> <table width="941" border="0" align="center"> <tr> <th width="935" colspan="9" scope="col">Status: <select name="status" id="status" style="width: 224px;"> <option value="" selected="selected">Please select...</option> <option value="All">All</option> <option value="Option1">Option1</option> <option value="Option2">Option2</option> <option value="Option3">Option3</option> <option value="Option4">Option4</option> </select> Start Date:<input type="text" name="Date" id="Date" size="8"/> End Date:<input type="text" name="Date1" id="Date1" size="8"/> <input name="action" type="submit" id="RetrieveList" value="Retrieve List" /> </th> </tr> </table> </form> <div id="results"> </div> And this is how I fetch the data, <?php require 'include/DB_Open.php'; $status = $_POST['status']; $date = $_POST['date']; $date1 = $_POST['date1']; if ($_POST['status'] == 'ALL') { $sql_status = '1'; } else { $sql_status = "status = '".mysql_real_escape_string($_POST['status'])."'"; } $sql="SELECT column1, column2, status FROM tracker WHERE status = '" . $sql_status . "' AND scheduled_start_date BETWEEN '" . $date . "' AND '" . $date1 . "' ORDER BY scheduled_start_date"; $myData = mysql_query($sql); //to count if there are any results $numrow = mysql_num_rows($myData); if($numrow == 0) { echo "No results found."; } else { echo "CRQ Count: $numrow"; } { echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th align='center'><strong>Column1</strong></th> <th align='center'><strong>Column2</strong></th> <th align='center'><strong>Status</strong></th> </tr>"; while($info = mysql_fetch_array($myData)) { echo "<form action='retrieve_status.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['column1'] . "<input type=hidden name=column1 value=" . $info['column1'] . " </td>"; echo "<td align='center'>" . $info['column2'] . "<input type=hidden name=column2 value=" . $info['column2'] . " </td>"; echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . " </td>"; echo "</tr>"; echo "</form>"; } } echo "</table>"; include 'include/DB_Close.php'; ?>
  5. need help java script below not working, its supposed to allow only the word "Resolved" and "Re-assigned" in one of my text area, so if the user enter other values, the form will not be submitted... function checkAllowedWords(){ var allowedWords, textString, textArray, length, word; allowedWords=["Resolved","Re-assigned"]; textString= document.getElementById("$Status").value; //replace the "text-area-element-id" with your actual id for that textarea textArray=str.split(" "); //if comma separated values are provided use "," instead of " " length = textArray.length; word = null; for (var i = 0; i < length; i++) { word = textArray[i]; if (allowedWords.indexOf(word, 0) === -1) { //indexOf() returns the index of the first "word" value found in the "allowedWords" array, and returns -1 if the value was not found in array alert(word + " is not allowed! The accepted values are: " + allowedWords.toString()); //This will popup an alert message for your testing purposes, you can implement anything you wish here to let the user know what's going on } } }
  6. my code below works perfect in Mozilla and Chrome but not in IE8, when i select a Radio button in IE its showing other options for other Radio button, need help in fixing the issue in IE8 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script src="jquery.chained.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <link rel="stylesheet" href="style.css" /> <script type="text/javascript" src="infratool.js"></script> <script> $(function() { $("#submit").hide(); $("#Category").change(function() { window.location = $(this).val().split(" ")[0]; if(loc) window.location.href = loc; }) }); </script> <table width="392" border="0"> <td colspan="2" align="center"><form id="form1" name="form1" method="post" action=""> <tr> <td align="center"> <label><input name="Radio1" type="radio" id="TestA" value="TestA" onclick="showSelect();" />TestA</label> <label><input name="Radio1" type="radio" id="TestB" value="TestB" onclick="showSelect();" />TestB</label> </td> </tr> </form> <div id="div-id" align="center"><select name="Category" id="Category" class="hide"> <option value=" TestA TestB" selected="selected">--</option> <option value="TestA1.php TestA">TestA1</option> <option value="TestA2.php TestA">TestA2</option> <option value="TestA3.php TestA">TestA3</option> <option value="TestA4.php TestA">TestA4</option> <option value="TestA5.php TestA">TestA5</option> <option value="TestB1.php TestB">TestB1</option> <option value="TestB2.php TestB">TestB2</option> <option value="TestB3.php TestB">TestB3</option> <option value="TestB4.php TestB">TestB4</option> <option value="TestB5.php TestB">TestB5</option> <option value="TestB6.php TestB">TestB6</option> </select><input type="submit" value="Go" id="submit"/> </div> </table> here are the other java scripts ive been using //Show Select option after clicking Radio button: function showSelect() { var select = document.getElementById('Category'); select.className = 'show'; } //Select option, separates the link from Class $(function(){ var select = $('#Category'), options = select.find('option'); $('[type="radio"]').click(function(){ var visibleItems = options.filter('[value*="' + $(this).val() + '"]').show(); options.not(visibleItems).hide(); if(visibleItems.length > 0) { select.val(visibleItems.eq(0).val()); } }); }); $(function() { $("#submit").hide(); $("#Category").change(function() { window.location = $(this).val().split(" ")[0]; if(loc) window.location.href = loc; }) }); and here is the screenshot in Firefox and IE8 respectively.
  7. I want to pull up the data that corresponds to the value of the drop down and show it to a text area within a fieldset, I want my page to just initially show the drop down then after selecting a value it will show the data in a text area without refreshing the page, here is the code: <div id="mainContent"> <table width="619" border="0" align="center"> <td align="center"><form id="form1" name="form1" method="post" action="" > <fieldset> <legend><strong>EA</strong></legend> <p> <select name="ea_name" id="ea_name"> <option value="" selected="selected">Please select...</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> </p> </fieldset> </form></td> </table> <div id="results"></div> </div> Here is the code that I've tried that will pull up data and show to a text area but all im getting is No results found. <?php require 'include/DB_Open.php'; $ea_name = $_POST['ea_name']; $sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'"; $myData = mysql_query($sql); //to count if there are any results $numrow = mysql_num_rows($myData); if($numrow == 0) { echo "No results found."; } else { echo '<fieldset><legend><strong>Information</strong></legend><p> <table width="auto" height="172" border="0"> <tr><th>Error</th></tr> <tr><th>Resolution</th></tr> <tr><th>Contact/s</th></tr>'; while($info = mysql_fetch_array($myData)) { echo "<form action='retrieve.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>"; echo "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>"; echo "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>"; echo "</tr>"; echo "</form>"; } } echo "</fieldset>"; include 'include/DB_Close.php'; ?>
  8. i have this code below as part of my entire Select option, <option value="Running Request |Running > 1 hour">Running Request |Running > 1 hour</option> everything works fine except that when i try to view the uploaded data it would have this result: Running Request |Running > 1 hour 1 hour' /> so the 1 hour is duplicated and would have /> in the end, im thinking it could be the > causing it but just cant get through it...please help...i need to remove the excess 1 hour' /> when I view the uploaded data...
  9. i think i figured it out...i just noticed that i am modifying the same file but saved on a different directory...code works perfect...sorry i just got so confused because of my php copying to another directory but then im still modifying the old one...thanks for the advise regarding this $myusername = mysql_real_escape_string ( htmlspecialchars ($_POST['myusername'])); $mypassword = mysql_real_escape_string ( htmlspecialchars ($_POST['mypassword']));
  10. the problem is the user's name is not being displayed...
  11. i wanted to display the user name after they logged in, i have the code below, this is my login.php <tr bgcolor="#FFFFFF"> <td width="71">Username</td> <td width="181"><input name="myusername" type="text" id="myusername" /></td> </tr> <tr bgcolor="#FFFFFF"> <td>Password</td> <td><input name="mypassword" type="password" id="mypassword" /></td> </tr> <tr bgcolor="#FFFFFF"> <td><input type="submit" name="Submit" value="Login" /></td> </tr> here is my checklogin.php <?php $host="*****"; // Host name $username="*****"; // Mysql username $password="*****"; // Mysql password $db_name="*****"; // Database name $tbl_name="*****"; // 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"); // username and password sent from form $myusername = mysql_real_escape_string ($_POST['myusername']); $mypassword = mysql_real_escape_string ($_POST['mypassword']); $myusername = htmlspecialchars ($_POST['myusername']); $mypassword = htmlspecialchars ($_POST['mypassword']); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ $row=mysql_fetch_array($result); session_start(); $_SESSION['login'] = "1"; $_SESSION['myusername'] = $row['username']; header("location: infratools.php"); } else { echo "Wrong Username or Password"; session_start(); $_SESSION['login'] = ''; } ?> and here is one of the page where i want to display the user name, infratools.php <?PHP session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) { header ("Location: infralogin.php"); } ?> <p>Logged in as: <?php echo $_SESSION['myusername']; ?></p>
  12. hi there i think i figured out what i really want now, i think i may just need a client side script to accomplish what i want, so instead of using the SELECT, what i want is to replace it with a TEXT FIELD with the name of the user who logs in, so that when he retrieves data from the DB, he would just have to select the date and user's name is already pre-defined, in that way, datas that will be gerated by the SQL script is just for the user and does not have option to select or view other users records, i think i need a java script code here, can you show me a sample code as well? here is the SELECT which should be replaced by TEXT FIELD with pre-defined USERS value already <select name="XiD" id="XiD"> <option value="USER1">USER1</option> <option value="USER2">USER2</option> <option value="USER3">USER3</option> <option value="USER4">USER4</option> <option value="USER5">USER5</option> <option value="USER6">USER6</option> <option value="" selected="selected">Please Select...</option> </select>
  13. do u have a sample script that i can try to work on...just need a glimpse of the script so i would know how to start...im not asking for the actual code...just need to visualize the script...
×
×
  • 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.