rmmo Posted July 3, 2008 Share Posted July 3, 2008 hi all... im back with another question... how can i do somthing complicated in a simple way? no here is my real question... i have a form on page1 it posts two variables username & password to a second page, page now on this page there is a table with checkboxes... what i want to do is to take the variables username & password from page1 as well as the results of the checkboxes from page2 to another page, page three and put them into a MYSQL query! <?php session_start(); ?> ..... HTML STUFF ...... <?php // connect to and select db $conn = mysql_connect($host, $dbuser, $dbpass) or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db($dbname, $conn) or trigger_error("SQL", E_USER_ERROR); // if there are posted vars... if ($_POST['USERNAME'] && $_POST['PASSWORD']) { // sanitize $username = mysql_real_escape_string($_POST['USERNAME']); $password = mysql_real_escape_string($_POST['PASSWORD']); // see if they are in table $query = "SELECT `customer_name`, `customer_password` FROM `customer` WHERE `customer_name` = '$username' AND `customer_password` = '$password'"; $results = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows returned. $rows = mysql_num_rows($results); // if something returned... if ($rows > 0) { // user/pass exist, do something, like make a session var signifying user is logged in $_SESSION['loggedin'] = true; require("artsonlinestorermmomenu.php"); echo "welcome $username"; require("artsonlinestorermmoproducts.php"); // if nothing returned... } else { if($username == 'g' & $password == 'p') { echo "welcome guest user (again please note you may only browse the site before registration"; require("artsonlinestorermmoproductsguest.php"); } else { //user/pass do not exist, do something echo "sorry your username and password did not match or you are not registered"; require("artsonlinestorermmo.php"); } } // end if..else $rows // if no username and/or pass posted... } else { echo "plase enter a username and password. If you are not a registerd user and would like to register please follow the link."; require("artsonlinestorermmo.php"); } // end if..else username/password ?> </body> </html> so i want to keep the values that are posted from up there ^. (username, password) $conn = mysql_connect($host, $dbuser, $dbpass) or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db($dbname, $conn) or trigger_error("SQL", E_USER_ERROR); if($db){ $query = "select * from product"; $result = mysql_query($query); ?> <table border bgcolor ='green'> <tr> <th>product id</th> <th>name</th> <th>description</th> <th>price ($)</th> </tr> <? while($row = mysql_fetch_array($result) ){ ?> <form method="post" action="artsonlinestorermmoorders.php"> <tr> <td><?=$row['prod_id'] ?></td> <td><?=$row['prod_name'] ?></td> <td><?=$row['prod_desc'] ?></td> <td><?=$row['prod_price'] ?></td> <td><input type="checkbox" name="<?=$row['prod_id'] ?>" value="1" /></td> </tr> <? } //end while }else die("sorry could not retreive product listings"); ?> <input type="submit" name="submit" value="order selected" /> <input name="reset" type="reset" value="clear" /> </form> </body> </html> i need the results from the checkboxes up there ^ (returns an array... i need the keys from the array (prod_id)s) then i need to put them into an insert query it would look somthing like this insert into orders values ('$customer_id', '$prod_id', 'sysdate') so that means i need to use the $username to first query the database to find its matching 'customer_id'.... so select 'customer_id', 'customer_address' from customer where 'customer_name' like '($username)'; i dunno im new to this im sure you guys can tell that... oh and is there anyway to enter that ^ (sysdate?) right so thats my problem i know its alot to ask but if you can make any sense of it all please any help would be greatly appreciated RMMO thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/ Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 on the second form just put a hidden input form in and pass the values behind the scenes.. retrieve them again on the third page.. Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580573 Share on other sites More sharing options...
rmmo Posted July 3, 2008 Author Share Posted July 3, 2008 ok so a hidden form tag... great umm what about the two mysql queries did they look ok? and how about the sysdate question? any idea? thanks alot ag3nt42 and thanks in advanced to anyone else who may help. RMMO Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580714 Share on other sites More sharing options...
rmmo Posted July 3, 2008 Author Share Posted July 3, 2008 ummm... well the hidden form tag didnt work out too well.... ??? i think im going to need some help sorting it out,,,, ive tried for about an hour.. i keep getting undeclared variables and when i manage to pass it the dont show the values they show... $variable name so if anyone knows how to do this could you give me a hand many thanks in advanced RMMO Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580726 Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 when passing variables across pages you have two options (that i can think of) either uses $_SESSION (requires a session be intiated) or use hidden form fields <input type='hidden' name='TheName' value='".$VARIABLE."' /> notice the type is hidden so the users cannot see it... but we can still send over a value on the next page just use this to get the data if(!(isset($_POST['TheName']))) { $Z=''; //Not Set } else { $Z=$_POST['TheName']; } $Z now holds the post value if it exists. otherwise $Z holds blank value Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580792 Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 ok so a hidden form tag... great umm what about the two mysql queries did they look ok? and how about the sysdate question? any idea? the sql queries looked ok... for the system date have a look through here to find a function that suits your needs Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580793 Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 and when i manage to pass it the dont show the values they show... $variable name make sure that your variable is not quoted.. and also you may find it more effcient to do this with your html echo("<input type='hidden' name='name' value='".$Value."' "); notice how when I plug in the variable I use quotes to unquote it and periods to seperate it from the regular html.. this way php will parse the variable and echo out its value.. and if you have alot of html.. makes it way easier to do this \/ rather then pluggin <?php ?> in evertime you need to write someting.. echo(" <html> <body> <table> <tr> <td> SOME CODE </td> </tr> </table> </body> </html> "); the above code will hold its formatting aswell. which is nice when you don't want to add in a bunch to PHP_EOL into your script.. and then anytime you need to plug a variable all you have to do is add this ".$Variable." Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580795 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Actually, ag3nt42, templating systems are the easiest. =P And it should work with hidden fields....but you need to check the input after every submit because you can easily change POST data. Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580861 Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 templating system? Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580907 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Such as Smarty. But if you ARE going to echo out HTML in PHP, I'd personally use printf() and tidy. Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580913 Share on other sites More sharing options...
ag3nt42 Posted July 3, 2008 Share Posted July 3, 2008 nvrm Quote Link to comment https://forums.phpfreaks.com/topic/113013-values-from-array-values-from-a-previous-post-into-a-mysql-query/#findComment-580923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.