thelee Posted November 13, 2012 Share Posted November 13, 2012 i want create a form to make a order.but for the name form,i want to it fill automatically based on session login. can someone help me ? here is some detail that i can provide for the order form <?php session_start(); if(isset($_SESSION['MM_Username'])) { echo "Welcome ".$_SESSION['MM_Username'].""; } else { echo "why you dont register?"; } ?> <style type="text/css"> <!-- .style1 {color: #FFFF00} .style4 {color: #00FFFF} .style8 {color: #00FF00} .style9 {color: #FFFFFF} .style10 { font-size: 18px; color: #FFFFFF; } body { background-image: url(wallpaper%20system.jpg); } body {background-attachment:fixed} body {background-repeat:no-repeat} --> </style> </head> <body> <form name="form1" method="post" action="order_product_process.php"> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10">Order Form:</p> <div align="center"> <table width="249" border="1" bgcolor="#000000"> <tr> <td width="54"><span class="style1">Name</span></td> <td width="179"><input name="name" type="text" id="name" maxlength="30"></td> </tr> <tr> <td><span class="style4">Address</span></td> <td><textarea name="address" id="address"></textarea></td> </tr> <tr> <td><span class="style1">Phone</span></td> <td><input name="phone" type="text" id="phone" maxlength="30"></td> </tr> <tr> <td><span class="style9">IC Number </span></td> <td><input name="ic" type="text" id="ic" maxlength="30"></td> </tr> <tr> <td><span class="style8">Product Name </span></td> <td><input name="product_name" type="text" id="product_name" maxlength="30"></td> </tr> <tr> <td><span class="style1">Quantity</span></td> <td> <input name="quantity" type="text" id="quantity" maxlength="30"></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Order"> <input name="Reset" type="reset" id="Reset" value="Reset"></td> </tr> </table> </div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </form> </body> </html> here is the order databse structure CREATE TABLE `order` ( `order_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL DEFAULT '', `address` varchar(30) NOT NULL DEFAULT '', `phone` varchar(30) NOT NULL DEFAULT '', `ic` varchar(30) NOT NULL DEFAULT '', `product_name` varchar(30) NOT NULL DEFAULT '', `quantity` int(30) NOT NULL DEFAULT '0', PRIMARY KEY (`order_id`) ) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1 Quote Link to comment https://forums.phpfreaks.com/topic/270627-auto-filling-name-form-fields-based-on-session-login/ Share on other sites More sharing options...
Muddy_Funster Posted November 13, 2012 Share Posted November 13, 2012 just create a variable to hold the user name and then echo it into the value="" of the name input element : <?php session_start(); if(isset($_SESSION['MM_Username'])) { $MM_Username = $_SESION['MM_Username']; echo "Welcome ".$_SESSION['MM_Username'].""; //<<------Be aware you are echoing this inside the html head, not the body. } else { $MM_Username = ''; echo "why you dont register?"; //<<--------This too } ?> <style type="text/css"> <!-- .style1 {color: #FFFF00} .style4 {color: #00FFFF} .style8 {color: #00FF00} .style9 {color: #FFFFFF} .style10 { font-size: 18px; color: #FFFFFF; } body { background-image: url(wallpaper%20system.jpg); } body {background-attachment:fixed} body {background-repeat:no-repeat} --> </style> </head> <body> <form name="form1" method="post" action="order_product_process.php"> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10"> </p> <p align="center" class="style10">Order Form:</p> <div align="center"> <table width="249" border="1" bgcolor="#000000"> <tr> <td width="54"><span class="style1">Name</span></td> <td width="179"><input name="name" type="text" id="name" maxlength="30" value="<?php echo $MM_Username; ?>"></td> </tr> <tr> <td><span class="style4">Address</span></td> <td><textarea name="address" id="address"></textarea></td> </tr> <tr> <td><span class="style1">Phone</span></td> <td><input name="phone" type="text" id="phone" maxlength="30"></td> </tr> <tr> <td><span class="style9">IC Number </span></td> <td><input name="ic" type="text" id="ic" maxlength="30"></td> </tr> <tr> <td><span class="style8">Product Name </span></td> <td><input name="product_name" type="text" id="product_name" maxlength="30"></td> </tr> <tr> <td><span class="style1">Quantity</span></td> <td> <input name="quantity" type="text" id="quantity" maxlength="30"></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Order"> <input name="Reset" type="reset" id="Reset" value="Reset"></td> </tr> </table> </div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/270627-auto-filling-name-form-fields-based-on-session-login/#findComment-1392003 Share on other sites More sharing options...
thelee Posted November 13, 2012 Author Share Posted November 13, 2012 omg.it doesnt work.the name form doesnt fill automatically. and it have some eror . =( Quote Link to comment https://forums.phpfreaks.com/topic/270627-auto-filling-name-form-fields-based-on-session-login/#findComment-1392033 Share on other sites More sharing options...
Muddy_Funster Posted November 13, 2012 Share Posted November 13, 2012 probably because I missed one of the "S"'s out of SESSION....typo, sorry but if your getting errors, it's always best to tell us what they are! Quote Link to comment https://forums.phpfreaks.com/topic/270627-auto-filling-name-form-fields-based-on-session-login/#findComment-1392041 Share on other sites More sharing options...
thelee Posted November 13, 2012 Author Share Posted November 13, 2012 ok sorry.the problem solved.thanks a lot man.i love u muah !!! but im not gay !! muahhh Quote Link to comment https://forums.phpfreaks.com/topic/270627-auto-filling-name-form-fields-based-on-session-login/#findComment-1392042 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.