Jump to content

tycoonbob

Members
  • Posts

    29
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by tycoonbob

  1. With the above, I am still experiencing the same behavior, but the code works. Do you not think the issue is related to the AJAX script? It just seems to me that since the GET address is incorrect, that the problem can't be with the getsku.php page, and the problem lies in the add.php page.
  2. Thanks for the continued help. I apologize for not updating with this info already, but I have made a few changes to reflect how I want to use this function. Here is my current getsku.php: <?php $q = html_entity_decode($_GET['q']); require_once('includes/config.inc.php'); $sql="SELECT sku FROM products WHERE name = '".$q."'"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { echo "<td><input type='hidden' name='sku' value='" . $row['sku'] . "' readonly='readonly' size='35' /></td>"; } mysqli_close($con); ?> Here is my current add.php (my main php page): <html> <head> <link rel="stylesheet" type="text/css" href="css/styles.css" media="screen" /> <title>Add Inventory</title> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getsku.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <?php session_start(); require_once('includes/config.inc.php'); require_once('includes/functions.inc.php'); // Check login status -- if not logged in, redirect to login screen if (check_login_status() == false) { redirect('login.php'); } $thisPage='add'; include('includes/navbar.inc.php'); ?> <h1>Add New Inventory Record</h1> <form method="POST" action="submitadd.php" /> <table id="add"> <tr> <td class="headings"><b>Species:</b></td> <td><select name="species:" onchange="showUser(this.value)"> <option value="select">Choose a Species</option> <?php $prodquery="SELECT name FROM products ORDER BY name ASC"; $result=mysqli_query($con,$prodquery) or die(mysqli_error($con)); while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>"; } ?> </select> </td> </tr> <div id='txtHint' /> <tr> <td class="headings"><b>Fry Count:</b></td> <td><input type="text" name="frycount" value="<?php echo $row['quantityfry']; ?>" size="35" maxlength="4" /></td> </tr> <tr> <td class="headings"><b>Juvie Count:</b></td> <td><input type="text" name="juviecount" value="<?php echo $row['quantityjuv']; ?>" size="35" maxlength="4" /></td> </tr> <tr> <td class="headings"><b>Adult Count:</b></td> <td><input type="text" name="adultcount" value="<?php echo $row['quantityadult']; ?>" size="35" maxlength="4" /></td> </tr> <tr> <td class="headings"><b>Notes:</b></td> <td><input type="text" name="notes" value="<?php echo $row['notes']; ?>" size="35" maxlength="255" /></td> </tr> <tr> <td class="headings"><b>Location:</b></td> <td><select name="location"> <?php $options = set_and_enum_values($con, 'inventory', 'location'); foreach($options as $option): ?> <option><?php echo $option ?></option> <?php endforeach; ?> </select></td> </tr> <tr> <td class="headings"><b>Owner:</b></td> <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): ?> <option><?php echo $option ?></option> <?php endforeach; ?> </select></td> </tr> </table> <br /> <input type="submit" name="submit" value="submit" class="button1" /> </form> </body> </html> Now I've tried using: $q = mysql_real_escape_string(html_entity_decode($_GET['q']))' And things still worked, but it didn't fix my problem. I feel like it's breaking around the $_GET though, since When I select: Cynotilapia afra "Lion's Cove" My GET URL is: GET site/app/getsku.php?q=Cynotilapia%20afra%20%22Lion Which is incomplete, and the correct value is never set to sent to the MySQL query. The only thing I can figure is something is going wrong with the AJAX script around: xmlhttp.open("GET","getsku.php?q="+str,true); But I know absolutely nothing about AJAX, which is why I'm begging for help.
  3. Thanks. So I see a common thing out there is creating an html sanitizing function such as: function htmlsan($htmlsanitize){ return $htmlsanitize = htmlspecialchars($htmlsanitize, ENT_QUOTES, 'UTF-8'); } Is this the path I should be heading toward? Add this to my functions include, but then how/where would I use this in my script? Would this be used in getsku.php or would it be used in the main php in question (and yet, would it be in the AJAX script or in the div "txtHint"?
  4. Follow up question to this. It seems to be working, for the most part. Some of the species names has characters in them which are not being escaped, such as " ' ", and " # ". This is not allowing the name to be pulled properly, thus creating an incomplete record in the database. A specific example is: Cynotilapia afra "Lion's Cove" Which is exactly how it appears in my database. When getsku.php runs, it is setting q= to: Cynotilapia afra "Lion stopping at the " ' ", which is why I assume it's not escaping properly. How can I make sure it escapes the characters like this? The same thing is happening with: Haplochromis sp. "#44 Thickskin" Which is setting q= to: Haplochromis sp. " Other than this issue, things are working great.
  5. Those changes to getuser.php did the trick. I've set the input type='hidden' also, since that is a field I don't care if it's seen. Working like a treat! Thanks!
  6. With this, I'm experiencing the same behavior, but still not working as expected. Does this look right: echo "<table border='1'> <tr> <th>SKU</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['sku'] . "</td>"; echo "</tr>"; } echo "</table>"; I just feel that the problem is somewhere with this. I can see that the AJAX function is working as it's pulling the name out correctly, but I can't confirm that the query in getsku.php is correct, or that it's returning the results correctly.
  7. Wait, I'm wrong. While the URL is wrong, Firebug is showing me this: Params: q Aulonocara rubescens "Ruby Red" So it's seeing the variable correctly. So something must be wrong with getsku.php?
  8. Using Firebug with Firefox, I can see that the AJAX script is working, but it's calling the "name" incorrectly. Example, the Species name is (Aulonocara rubescens "Ruby Red") but the $_GET that is being called is: http://site.com/getsku.php?q=Aulonocara%20rubescens%20%22Ruby%20Red%22 With getsku.php getting that variable for q= by using $_GET, I am assuming it's getting: Aulonocara%20rubescens%20%22Ruby%20Red%22 Instead of: Aulonocara rubescens "Ruby Red" So everything is working, but because the incorrect name, the SQL query is just returning no results. Does this seem like my problem, and how can I fix it?
  9. add.php: <html> <head> <link rel="stylesheet" type="text/css" href="css/styles.css" media="screen" /> <title>Add Inventory</title> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getsku.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <?php session_start(); require_once('includes/config.inc.php'); require_once('includes/functions.inc.php'); $thisPage='add'; include('includes/navbar.inc.php'); ?> <h1>Add New Inventory Record</h1> <form method="POST" action="submitadd.php" /> <table id="add"> <tr> <td class="headings"><b>Species:</b></td> <td><select name="species:" onchange="showUser(this.value)"> <option value="select">Choose a Species</option> <?php $prodquery="SELECT name FROM products ORDER BY name ASC"; $result=mysqli_query($con,$prodquery) or die(mysqli_error($con)); while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>"; } ?> </select> </td> </tr> <tr> <td class="headings"><b>SKU:</b></td> <td><input type="text" name="sku" value="<div id="txtHint" />" readonly="readonly" size="35" /></td> </tr> </table> <br /> <input type="submit" name="submit" value="submit" class="button1" /> </form> </body> </html> getsku.php: <?php $q = intval($_GET['q']); require_once('includes/config.inc.php'); $sql="SELECT sku FROM products WHERE name = '".$q."'"; $result = mysqli_query($con,$sql); echo "<table border='1'> <tr> <th>SKU</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['sku'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>
  10. No error message. The drop down shows values, but the values all just say "name". Like 40 of them.
  11. Thanks for the link. I have never touched AJAX before so I'm sure I will have questions, but I see at least what is going on with this. Hopefully I can make this work. If I change my query to "SELECT name, sku FROM products ORDER BY name ASC" my query breaks and no results are returned. I know the query is valid though, since I can run it against the database directly via phpMyAdmin. Can you provide a little more detail on what you are suggesting here?
  12. Hi everyone. So I have a HTML form using PHP to pull a column from a MySQL table. However, I have a second field in my form that I want to pull a second row of data from that same table, when the first row is selected. Example DB Table: id=1 <---This is Primary Key name=ItemA <---This is the data that shows in the drop down list sku=1234 <---This is the data I want to throw into $_POST['sku'] when something is selected in name Here is the code I currently have for my form: <form method="POST" action="submitadd.php" /> <table id="add"> <tr> <td class="headings"><b>Species:</b></td> <td><select name=species:> <option value="select">Choose a Species</option> <?php $prodquery="SELECT name FROM products ORDER BY name ASC"; $result=mysqli_query($con,$prodquery) or die(mysqli_error($con)); while ($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>"; } ?> </select> </td> </tr> <tr> <td class="headings"><b>SKU:</b></td> <td><input type="text" name="sku" value="<?php echo $row['sku']; ?>" readonly="readonly" size="35" /></td> </tr> Currently, the SKU field is a readonly field but I want it to pull data from the database when someone makes a select on the dropdown above. I assume this will require javascript? I have no experience with javascript, and was hoping someone could help me out or at least point me in the right direction. I don't have a clue how to search for this on Google. Thanks.
  13. This is my final code that worked. The only modification from yours above is replacing the `$_POST` with `$row`, since I am extracting that data via SQL query instead of POST. <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): $selected = (isset($row['owner']) && $row['owner'] == $option) ? ' selected="selected"' : ''; ?> <option<?php echo $selected; ?>><?php echo $option ?></option> <?php endforeach; ?> </select></td> Thanks again!
  14. Ha, I feel like such a newbie. My text editor was telling me there was a syntax error, so I did move the > for option. Moving it back, and using the code you originally provided, and everything works like expected! I can't thank you enough!
  15. Oh wait, this is doing something: <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): $selected = (isset($row['owner']) && $row['owner'] == $option) ? ' selected="selected"' : ''; ?> <option><?php echo $selected; ?><?php echo $option ?></option> <?php endforeach; ?> </select></td> The value that is selected in the database is showing up as: select="selected"PersonsName So it's able to mark which one is which. I'm guessing the HTML didn't execute properly?
  16. <td><select name="owner"> <?php $options = set_and_enum_values($con, 'inventory', 'owner'); foreach($options as $option): $selected = (isset($_POST['owner']) && $_POST['owner'] == $option) ? ' selected="selected"' : ''; ?> <option><?php echo $selected; ?><?php echo $option ?></option> <?php endforeach; ?> </select></td> Didn't seem to work. It didn't break anything, and the drop downs are still working, but they are not defaulting to what data is already in that field. I know I've seen a mysql_* example today that had that ability; going to see if I can find it. It's not one of the 4 I listed in the OP.
  17. I believe there is a syntax error, but I'm not sure where it is. I know there is a missing '>' in '<option>', which I fixed, but I think the single quotes are off balanced in Line 5? With the code as is, and with the '>' added on <option>, it just loads a white page -- which I believe is considered a fatal error. EDIT: Also, I think $_POST might not be the right thing I need either. Earlier in this script I have this: $inven_id = $_GET['id']; $query = "SELECT * FROM inventory INNER JOIN products ON inventory.sku=products.sku WHERE inventory.id = '$inven_id'"; $result = mysqli_query($con,$query) or die(mysqli_error($con)); $row = mysqli_fetch_array($result); And my other table fields are getting the default value by using: <?php echo $row['owner']; ?> For example.
  18. Thanks for explaining, and it now makes sense. One final question on this topic; This works, however, where I'm using this there is already data in selected in this field (when editing). How can I set the SELECTED parameter to what the field currently has?
  19. I really appreciate your help. Unfortunately, I'm still not doing something right. Here is what I have in my table: <tr> <td class="headings"><b>Owner:</b></td> <td><select name="owner"><option value="<?php $fields = set_and_enum_values($con, 'inventory', 'owner'); ?>" /></select></td> </tr> I get a drop down list, but it's empty. Here is config.inc.php, which is where $con is set: <?php $con=mysqli_connect("server","username","password","db_name"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?>
  20. Alright, so I added that to my function.inc.php file, but on each page I now get "Error getting Enum/Set field", while no other data is loading and without calling that function on the page. index.php has: require_once('includes/functions.inc.php') but this function won't be used on that page. Also, I'm confused by the variables in the funciton. Is the '&' intentional? I have a config.inc.php file that has my db connection stored in $con, so should I replace $conn with $con?
  21. Hi everyone. I have another question, which will hopefully be the last piece to get my application going. I have a MySQL table with an enum field, with a few values (Value1, Value2, Value3, Value4). I have a HTML form that is pulling over fields from the same table, but those other fields are varchar fields. I'm wanting to create a drop down box which is dynamically populated with those enum values, and that defaults to the currently selected field. I have found a few examples of this, but they all seem to be deprecated mysql_* code, whereas I'm using mysqli_* throughout. I'm fairly new to PHP, and I have never written a function before. I figure something like this would be out there somewhere, but I haven't been able to find an example here at PHPFreaks, nor on various other forums. Here are some examples of what I have found using mysql_*: http://www.barattalo.it/2010/01/19/php-to-get-enum-set-values-from-mysql-field/ http://stackoverflow.com/questions/3715864/displaying-mysql-enum-values-in-php http://www.larryullman.com/forums/index.php?/topic/916-use-data-type-enum-for-form-drop-down-options/ http://www.pcserviceselectronics.co.uk/php-tips/enum.php I just don't know where to start with creating this function. I need to use this 3 times, or 2 different fields, which is why I assumed a function would be the best way to go. Thanks for any help!
  22. Figured out my issue. I'm using PHP-fpm instead of just PHP, and the www.conf file (/etc/php-fpm.d/www.conf) has a setting for session.save_path which was set to a non-existent directory. Once I changed that to the directory that I had set for that variable in php.ini, it started working.
  23. It does not appear to change.
  24. I see a cookie being created called PHPSESSID, which expires when the session ends. Now what's really bothering me is I've installed WAMP on my local PC, copied over the scripts, imported a copy of the database, and everything works like it's supposed to. I've compared each setting in php.ini, and I am out of ideas. I have spent two days trying to figure this out and I feel like I'm getting nowhere.
  25. Thanks for the replies. The web server is a VM running CentOS 6.x, using Nginx, PHP-fpm, and MySQL. php.ini had "session.save_path" disabled, so I enabled it (uncommented it), set it = to "/tmp/phpsess", created /tmp/phpsess/, and set the owner to nginx:nginx, which is what my web server is using. I've also added the { } around the check_login_status function, and also added the "session_id() && session_write_close();" line to the redirect function. I also added the two debug lines to my php.ini, restarted Nginx and PHP-fpm, but am seeing no error messages at all. Any other ideas?
×
×
  • 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.