Kenny Logins wrote: » http://thenewboston.org/list.php?cat=11 Three weeks?
threein99 wrote: » Can anyone help me populate a textboxes based on a selection from a dropdown menu ? The dropdown is populated with supplier names from my database, depending on which supplier I click, the relavent supplier ID goes into a text box underneath
//Start SQL $link = mysqli_connect($host, $uid, $pwd, $db); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } //End SQL Set Up $query = "SELECT supplierName FROM suppliers LIMIT 100"; $result = mysqli_query($link, $query); $row = mysqli_fetch_array($result, MYSQLI_NUM); echo "<form name=myform>"; echo "<select name=suppliertable>"; $counter = 0; foreach($rows as $row) { echo <option name=name value=".$row[$counter].">".$row[$counter]." </option>; } echo "</select></form>";
ironclaw wrote: » I presume your using a SQL link and know something about interfacing with it. The basic outline://Start SQL $link = mysqli_connect($host, $uid, $pwd, $db); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } //End SQL Set Up $query = "SELECT supplierName FROM suppliers LIMIT 100"; $result = mysqli_query($link, $query); $row = mysqli_fetch_array($result, MYSQLI_NUM); echo "<form name=myform>"; echo "<select name=suppliertable>"; $counter = 0; foreach($rows as $row) { echo <option name=name value=".$row[$counter].">".$row[$counter]." </option>; } echo "</select></form>"; I'm assuming your using HTML. Thats probably littered with mistakes but its the general outline. You basically want to get an array and loop it out into the form. At least thats how I'd do it.
threein99 wrote: » Yeah im using HTML. Sorry for asking this, but which part of that will populate the text box ?
echo "<form name=myform>"; echo "<select name=suppliertable>"; $counter = 0; foreach($rows as $row) { echo <option name=name value=".$row[$counter].">".$row[$counter]." </option>; } echo "</select></form>";
ironclaw wrote: » In all honesty, you should understand nearly every single line of that. Its very basic html. But this bit will build a form with a drop down:echo "<form name=myform>"; echo "<select name=suppliertable>"; $counter = 0; foreach($rows as $row) { echo <option name=name value=".$row[$counter].">".$row[$counter]." </option>; } echo "</select></form>";
threein99 wrote: » Since September we have been shown, javascript, php, and mysql, all thats been achieved is to confuse the entire year
ironclaw wrote: » Thats quite alot though My best suggestion is w3schools. Get a basic HTML template going and then build PHP into it. PHP just adds dynamic functionality so unless you know HTML your not going to be able to do much with PHP.
smcelhinney wrote: » What you're looking for is AJAX. Best way to do this is to think logically and sequentially about what is happening.An option box is displayed with a list of options (PHP/HTML) When the option is changed (Javascript change event handler) Populate another box with options based on this (PHP/HTML/Javascript) There's a very good example here https://forums.digitalpoint.com/threads/onchange-populate-select-boxes-newbie-question.147516/ (2nd response). All you need to do is determine where the options come from, for the second box.
var boxOptions = new Array(); boxOptions['Bar'][] = 'Drinks'; boxOptions['Bar'][] = 'Glasses'; boxOptions['Bar'][] = 'Peanuts'; boxOptions['Bar'][] = 'Crisps'; ... boxOptions['Leisure Centre'][] = 'Weights'; boxOptions['Leisure Centre'][] = 'Energy Bars'; ...
var options = new Array(); boxOptions['Bar'][] = { value: 10, text: 'Drinks'};
smcelhinney wrote: » AJAX is normally used when querying a server (in your case, querying the database), waiting on the response, and doing something with that response. Alternatively, you can create a javascript array on your page, inline, that does the same thing, so you dont have to query. In your case your array might look likevar boxOptions = new Array(); boxOptions['Bar'][] = 'Drinks'; boxOptions['Bar'][] = 'Glasses'; boxOptions['Bar'][] = 'Peanuts'; boxOptions['Bar'][] = 'Crisps'; ... boxOptions['Leisure Centre'][] = 'Weights'; boxOptions['Leisure Centre'][] = 'Energy Bars'; ... Then use Javascript to go through the array, and get all the keys, and use these to populate your first select box. When the select box changes, go back to your array, and grab all the items from boxOptions, and use these to populate your second listbox. Remember to clear the options in the second list box every time the first list box changes. That should do it. You might have to do some messing about with the array if you want the option VALUE to be something other than "Crisps", for example, 10. In this case, you might need to use objects, for example:var options = new Array(); boxOptions['Bar'][] = { value: 10, text: 'Drinks'};
Evil Phil wrote: » 3 weeks? Cutting that short. TBH it's normal for the class to be confused, the only way you start to make sense of this is to cut code in anger. Simply understanding the syntax is not even half the battle, you have to learn how to put these things together. Start with a single task and break it down into smaller and smaller tasks until you can't break it down any more. Then develop each of these tasks one-by-one, don't worry about the other tasks until you have your current one complete. You don't have to have an fully working system to pass the assignment. For future reference have a read of this, you'll find it helpful.
<form action="test.php" method="post" onsubmit= "confirm()" >
<script> function confirm() { if(confirm("add stock ?") { document.location = 'http://http://backToMyform.com/'; " } } </script>
threein99 wrote: » <form action="test.php" method="post" onsubmit= "confirm()" > I am trying to refresh back to a form page when the submit button click is confirmed in my confirm function. The data submits to my database but keeps directing the browser to test.php Here is my confirm function<script> function confirm() { if(confirm("add stock ?") { document.location = 'http://http://backToMyform.com/'; " } } </script> Any tips as to what Im doing wrong ?
<script type="text/javascript"> function proceed(){ window.location = "http://backToMyform.com";} </script> </head> <body> <form action="test.php" method="post" onClick= "javascript:proceed()" >
header("Location: " . http://backToMyform.com);
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Remove Stock</title> </head> <body> </body> </html> <?php include "connect.php"; date_default_timezone_set('Europe/London'); if('$_POST[currentLevel]'>'$_POST[amountToRemove]') { $result = "UPDATE stockitem SET currentLevel = currentLevel-'$_POST[amountToRemove]' WHERE stockitem.stockId='$_POST[removeStockId]' "; $theDate = Date('Ymd'); $theTime = Date('His'); $movementID = "SM".Date('Ymdhis').rand(1000,9999); $sql="INSERT INTO stockmovement(movedBy,stockId,date,time,quantityMoved,movedTo,movementId) VALUES ('$_POST[staffName]','$_POST[removeStockId]','$theDate','$theTime','$_POST[amountToRemove]','$_POST[area]','$movementID')"; if(!mysql_query($sql,$con)) { echo "</br><script>alert('Error connecting to the database!');</script> "; } else if(!mysql_query($result,$con)) { die('Error: ' . mysql_error()); } else { if(mysql_affected_rows() != 0 ) { echo "</br><script>alert('Item has been removed from the stock room!');</script> "; } else { echo "<BR>" . "No Change"; } } }//outer if else { echo "</br><script>alert('Not enough items in the stock room!');</script> ";# echo "</br><script>document.location = 'https://hotel.candept.com/stock/removeStock.html.php';</script> "; } ?>
if($_POST['currentLevel'] > $_POST['amountToRemove'])
Draco wrote: » Your if statement is wrong - you're quoting the values. It should look like this: if($_POST['currentLevel'] > $_POST['amountToRemove'])
threein99 wrote: » That seems to have fixed it, thanks a million, I would never have noticed that .
ironclaw wrote: » If you want some extra kudo's, sanitise the POST data for SQL Injection.
threein99 wrote: » That's a bit advanced for me I'm afraid
$currentLevel = mysqli_real_escape_string($link, $_POST['currentLevel']);
ironclaw wrote: » Depending on how your connecting, it could literally be one line:$currentLevel = mysqli_real_escape_string($link, $_POST['currentLevel']); $currentLevel is now a 'safe' variable. Won't stop a sophisticated attack but would get your some serious kudo's if you explained it well. Link: http://php.net/manual/en/mysqli.real-escape-string.php
Dave! wrote: » err.... doesn't really bode well for your education then! That's pretty basic sanitisation, I would think she'd be quite familiar with it.
threein99 wrote: » This is just a college a project, in a lecture the other day we asked our lecturer to explain how she was using cookies on a login screen she had, she told us to google it so I think using real_escape would be lost on her.
philologos wrote: » OP: You are expecting other people to do your work for you. That's not what learning is about. You're in a computer science / software engineering course you should expect to learn. Your questions are geared towards "can someone do this for me" rather than can someone give me guidance on what steps to consider, what tools to use so that I can build this myself. If while you are learning you are using the "can someone do this for me" what will that mean for when you finish your degree and you're actually developing projects?
philologos wrote: » OP: You are expecting other people to do your work for you. That's not what learning is about. You're in a computer science / software engineering course you should expect to learn. Your questions are geared towards "can someone do this for me" rather than can someone give me guidance on what steps to consider, what tools to use so that I can build this myself. If while you are learning you are using the "can someone do this for me" what will that mean for when you finish your degree and you're actually developing projects? What a poxy attitude! How are you going to view real life projects if you're thinking that now? When I was at uni we were encouraged to learn Android for ourselves for 2 weeks before starting a project. The same for many in terms of PHP / MYSQL and so on. That is an unfair complaint against your lecturer really.