Jump to content


Photo

Simple Question - Data Input


  • Please log in to reply
9 replies to this topic

#1 BrandonSi

BrandonSi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 06:15 PM

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.

<?
 $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>'; 
?>

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!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 June 2006 - 06:22 PM

Of course you have to use html. There is no such thing as a form in php.
<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>
That will post your data to handle.php which will then be available in the $_POST array.

#3 BrandonSi

BrandonSi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 06:35 PM

[!--quoteo(post=386110:date=Jun 20 2006, 01:22 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 20 2006, 01:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Of course you have to use html. There is no such thing as a form in php.
<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>
That will post your data to handle.php 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?

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 June 2006 - 06:38 PM

Like this:

<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>

Legend has it that reading the manual never killed anyone.
My site

#5 BrandonSi

BrandonSi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 06:40 PM

That's what I was thinking, but isn't my db password going to showup in the html source?


#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 June 2006 - 06:52 PM

No....php is parsed on the server. Only the outputed html ends up on the client.

#7 BrandonSi

BrandonSi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 06:57 PM

[!--quoteo(post=386119:date=Jun 20 2006, 01:52 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 20 2006, 01:52 PM) View Post[/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
<?
$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>';
?>


Output from browser
 '; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?>


#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 21 June 2006 - 12:24 AM

Are you sure you have php installed and configured properly on the server?

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 June 2006 - 12:30 AM

always save files with a .php exstention ok

example

test.php
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 BrandonSi

BrandonSi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 June 2006 - 02:12 PM

[!--quoteo(post=386212:date=Jun 20 2006, 07:30 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 20 2006, 07:30 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
always save files with a .php exstention ok

example

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users