BrandonSi Posted June 20, 2006 Share Posted June 20, 2006 Do I need to use HTML to get user input from a browser? I'm writing a simple expense tracker and I want the data input to all be on one line, consisting of amount, category, description, payment method and date.I've got the mysql db set up fine, and I put together code snippets to get a drop-down box to show the various categories available.. but when I try to create a simple text box for a user to input amount or description I get lost.. everything I've found on the web seems to use HTML forms.. I just wanna keep my straight .php file.Here's my code for the drop-down box.[code]<? $dbh=mysql_connect ("localhost", "branthan_et", "enterprise") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("branthan_expensetracker");$sqlOptions = "SELECT * from categories";$resultOptions = mysql_query($sqlOptions);echo '<select name="selectName">';echo '<option value="">--Select--</option>';while($opt = mysql_fetch_array($resultOptions)){echo '<option value="'.$opt['categories'].'">'.$opt['categories'].'</option>';}echo '</select>'; ?>[/code]Do I have to echo the HTML? If so could you share an example of how I would do that please? Basically I want to get all the input into variables and create a new record in the table. I can handle the sql code, but the simple stuff is really messing me up! Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/ Share on other sites More sharing options...
trq Posted June 20, 2006 Share Posted June 20, 2006 Of course you have to use html. There is no such thing as a form in php.[code]<form action="handle.php" action="POST"> <input type="text" name="amount">amount <input type="text" name="category">category <input type="text" name="description">description <input type="text" name="payment">payment <input type="text" name="amount">amount <input type="text" name="date">date</form>[/code]That will post your data to [i]handle.php[/i] which will then be available in the $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47756 Share on other sites More sharing options...
BrandonSi Posted June 20, 2006 Author Share Posted June 20, 2006 [!--quoteo(post=386110:date=Jun 20 2006, 01:22 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 20 2006, 01:22 PM) [snapback]386110[/snapback][/div][div class=\'quotemain\'][!--quotec--]Of course you have to use html. There is no such thing as a form in php.[code]<form action="handle.php" action="POST"> <input type="text" name="amount">amount <input type="text" name="category">category <input type="text" name="description">description <input type="text" name="payment">payment <input type="text" name="amount">amount <input type="text" name="date">date</form>[/code]That will post your data to [i]handle.php[/i] which will then be available in the $_POST array.[/quote]Thanks.. That was kind of a dumb question, but I haven't ever worked with php.Now how would I integrate a drop-down box that's populated from my mysql table into that one category field? I've got a php script to do it that executes fine from the browser as .php, is there a way to link a HTML form so that it gets its data from execution of that script? Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47760 Share on other sites More sharing options...
AndyB Posted June 20, 2006 Share Posted June 20, 2006 Like this:[code]<form action="handle.php" action="POST"> <input type="text" name="amount">amount <input type="text" name="category">category <input type="text" name="description">description<?$dbh=mysql_connect ("localhost", "branthan_et", "enterprise") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("branthan_expensetracker");$sqlOptions = "SELECT * from categories";$resultOptions = mysql_query($sqlOptions);echo '<select name="selectName">';echo '<option value="">--Select--</option>';while($opt = mysql_fetch_array($resultOptions)){echo '<option value="'.$opt['categories'].'">'.$opt['categories'].'</option>';}echo '</select>'; ?> <input type="text" name="payment">payment <input type="text" name="amount">amount <input type="text" name="date">date</form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47762 Share on other sites More sharing options...
BrandonSi Posted June 20, 2006 Author Share Posted June 20, 2006 That's what I was thinking, but isn't my db password going to showup in the html source? Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47763 Share on other sites More sharing options...
trq Posted June 20, 2006 Share Posted June 20, 2006 No....php is parsed on the server. Only the outputed html ends up on the client. Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47765 Share on other sites More sharing options...
BrandonSi Posted June 20, 2006 Author Share Posted June 20, 2006 [!--quoteo(post=386119:date=Jun 20 2006, 01:52 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 20 2006, 01:52 PM) [snapback]386119[/snapback][/div][div class=\'quotemain\'][!--quotec--]No....php is parsed on the server. Only the outputed html ends up on the client.[/quote]Thanks! Does anyone see any formatting issues with that dropdown box php code? The output was fine when run as a .php but now I think the echo commands are screwed up.. maybe a quotation mark issue?dropdown code[code]<?$dbh=mysql_connect ("localhost", "branthan_et", "enterprise") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("branthan_expensetracker");$sqlOptions = "SELECT * from categories";$resultOptions = mysql_query($sqlOptions);echo '<select name="selectName">';echo '<option value="">--Select--</option>';while($opt = mysql_fetch_array($resultOptions)){echo '<option value="'.$opt['categories'].'">'.$opt['categories'].'</option>';}echo '</select>';?>[/code]Output from browser[code] '; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47767 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Are you sure you have php installed and configured properly on the server? Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47854 Share on other sites More sharing options...
redarrow Posted June 21, 2006 Share Posted June 21, 2006 always save files with a .php exstention okexample test.php Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-47855 Share on other sites More sharing options...
BrandonSi Posted June 21, 2006 Author Share Posted June 21, 2006 [!--quoteo(post=386212:date=Jun 20 2006, 07:30 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 20 2006, 07:30 PM) [snapback]386212[/snapback][/div][div class=\'quotemain\'][!--quotec--]always save files with a .php exstention okexample test.php[/quote]God I feel dumb. I was saving it as an .html, since it had .html code in it. [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Thanks, it works perfectly now! Quote Link to comment https://forums.phpfreaks.com/topic/12478-simple-question-data-input/#findComment-48037 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.