Jump to content

dj262501

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dj262501's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello all, I need your help again. I have this page where the user inputs data: <?php include "include/dbc.php"; include "include/header.inc"; #error checking will go here ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid[]" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value=""></option> <option value="mile">mile</option> <option value="Km">km</option> <option value="M">m</option>; <option value="Yard">yrd</option> <option value="Feet">ft</option> </select></div></td></tr>'; echo'<input type="hidden" name="submitted" value="1">'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> <div></div> <?php include "include/footer.inc"; ?> I want to validate that the user enters data for at least one of all the fields provided (distance, duration, metric). If someone could help me get started I'd greatly appreciate it.
  2. Hello, Im having trouble and need your help. I have two pages. The first establishes the table and calls up a database: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid[]" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> The second page passes those values: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if( is_array($exerciseid) ) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } echo '<h1>Duration</h1>'; if(is_array($duration) ) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> The problem is that this code returns everything: Added Activities Exercise 0 : Fishing from boat, sitting 1 : Fishing from river bank, standing 2 : Fishing in stream, in waders 3 : Fishing, general 4 : Fishing, ice, sitting 5 : Hunting, general Duration Fishing from boat, sitting : 22 Fishing from river bank, standing : Fishing in stream, in waders : Fishing, general : Fishing, ice, sitting : Hunting, general : Distance Fishing from boat, sitting : 22 Fishing from river bank, standing : Fishing in stream, in waders : Fishing, general : Fishing, ice, sitting : Hunting, general : Metric 0 : mile 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile I need a way to say if this variable is empty, null, or equals 0, do not return it. And yes, the variables are arrays. I don't know what else to do. Thanks in advance.
  3. Where in the loop should I put this?
  4. I have a php page where user/db info is being passed: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Duration</h1>'; if (is_array($duration)) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> And here is the output from that code: Added Activities Exercise 0 : Canoeing, on camping trip 1 : Canoeing, rowing, over 6 mph, vigorous effort 2 : Canoeing, rowing, crewing, competition 3 : Canoeing, rowing, light effort 4 : Canoeing, rowing, moderate effort 5 : Diving, springboard or platform 6 : Kayaking 7 : Sailing, boat/board, windsurfing, general 8 : Sailing, in competition 9 : Skiing, water 10 : Ski-mobiling, water 11 : Skin diving, scuba diving, general 12 : Snorkeling 13 : Surfing, body or board 14 : Swimming laps, freestyle, fast, vigorous effort 15 : Swimming laps, freestyle, light/moderate effort 16 : Swimming, backstroke, general 17 : Swimming, breaststroke, general 18 : Swimming, butterfly, general 19 : Swimming, leisurely, general 20 : Swimming, sidestroke, general 21 : Swimming, sychronized 22 : Swimming, treading water, fast/vigorous 23 : Swimming, treading water, moderate effort 24 : Water polo 25 : Water volleyball 26 : Whitewater rafting, kayaking, or canoeing Duration Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Distance Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Metric 0 : mile 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile 6 : mile 7 : mile 8 : mile 9 : mile 10 : mile 11 : mile 12 : mile 13 : mile 14 : mile 15 : mile 16 : mile 17 : mile 18 : mile 19 : mile 20 : mile 21 : mile 22 : mile 23 : mile 24 : mile 25 : mile 26 : mile As you can see, null values are being passed as well. I am hoping that someone can show me the correct way to use php unset to get rid of these null values. Thank you.
  5. Thanks again. Another question: Is there any way to just block empty values and not return anything? Right now I keep getting array
  6. Is there anyway to return just user input and not blank vales/array?
  7. Thanks for the help, but for some reason it's coming back as array
  8. Hello all, I need your help. I have two pages. This is the 1st page: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid[]" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']" value=""></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']" value ""></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This page contains a table that is pulling info from a database stored in phpmyadmin. The values entered in that table are passed to the second page: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } echo '<h1>Duration</h1>'; if ($duration == ""){ echo "No value"; } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> The problem is that ALL the values, empty or w/content, are being passed. So I was wondering if there was a way to pass only user input with an if/else statement. Something like: if ($duration == ""){ echo "No value"; else echo duration; } This, however, is not working and I would like to know what possibly could work that would be structured similarly. Thanks in advance.
  9. Hello all, I am hoping that someone can help me out with some code that I have. Here is the code: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid[]" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> The code pulls variables, called exercise activities, from a table and allows the user to input the duration and distance that they completed the exercise. The second page looks like this: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Duration</h1>'; if (is_array($duration)) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> Here is what the second page of php code returns: [text] Added Activities Exercise 0 : Automobile repair 1 : Carpentry, general 2 : Carrying heavy loads, such as bricks 3 : Construction, outside, remodeling 4 : Electrical work, plumbing 5 : Farming, baling hay, cleaning barn 6 : Farming, milking by hand 7 : Farming, shoveling grain 8 : Marching, rapidly, military 9 : Painting, papering, plastering, scraping Duration Automobile repair : 26 Carpentry, general : Carrying heavy loads, such as bricks : Construction, outside, remodeling : Electrical work, plumbing : Farming, baling hay, cleaning barn : Farming, milking by hand : Farming, shoveling grain : Marching, rapidly, military : Painting, papering, plastering, scraping : Distance Automobile repair : 25 Carpentry, general : Carrying heavy loads, such as bricks : Construction, outside, remodeling : Electrical work, plumbing : Farming, baling hay, cleaning barn : Farming, milking by hand : Farming, shoveling grain : Marching, rapidly, military : Painting, papering, plastering, scraping : Metric 0 : M 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile 6 : mile 7 : mile 8 : mile 9 : mile [/text] Though this works, I want it to be better. I want a way to single out only the data the user inputs and not return everything else. Any ideas/suggestions are welcomed. Thank you!
  10. Hello all, I'm hoping someone can help me out. Here is the code I have for a page that contains a user form: <?phpinclude "include/dbc.php";include "include/header.inc";?><style type="text/css">.mydate{color:#00F;text-decoration:underline;cursor:pointer;}</style><script type="text/javascript">function displayDate(d){var date=new Date();var D=date.getDate();date.setDate(D+d);var YYYY=date.getFullYear();var MM=date.getMonth()+1;MM<10?MM='0'+MM:null;var DD=date.getDate();DD<10?DD='0'+DD:null;var span=document.getElementById('date');span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY;}onload=function(){displayDate(0)};</script><h1>Food Diary</h1><div class="full"><center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /><a href="#" onclick="displayDate(0);return false;">Today</a></center><div class="full"><form name="exercise" id="exercise" method="GET" action=""> <center><table><tr> <td><h3>Add an Activity</h3></td></tr><tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td></tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td></tr></table> </center><table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td></tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td></tr><?phpif(isset($_GET[activity])) {$category=$_GET[activity];$result = mysql_query("SELECT * FROM exercise WHERE type='$category'");?><form action="add_activity.php" method="POST"><?phpwhile($row = mysql_fetch_array($result)) {echo '<tr><td><div>'.$row[Type].'</div></td>';echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>';echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>';echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>';echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>';}mysql_close();?><tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr></form><?php}?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td></tr></table> And here is the page that the user information is supposed to be passed to: <?phpinclude "include/dbc.php";include "include/header.inc";$duration = $_POST["duration['.$row['Name'].']"];echo '<h1>Added Activities</h1>';echo $duration;?> Well, this isn't working for me. The second page code returns this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING When I execute print_r, the values are returned to me. So I have two questions: 1) What do I need to do to change the code on the 2nd page to echo and POST the array? 2)The database contains multiple exercises under the same name. So, when the variables are passed to the 2nd page. All the values are returned regardless of whether they have been filled out or not. What can be done to only returned the user input and not the blank variables?
  11. So you're saying instead of having multiple textboxes, I should replace them with checkboxes? What would be the best way to validate the form if I do it this way?
  12. I appreciate your help guys. I was able to do something to the code. Now it looks like this: <?php include "include/dbc.php"; include "include/header.inc"; ?> <script type="text/javascript"> <!--Hide Code // Function Statements //Function to confirm submit function confirmSubmit() { var submitform = window.confirm("Are you sure you want to submit the activities?"); if (submitform == true) return validateForm(); return false; } // End Hide--> </script> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This somewhat works. The problem is that this code passes all the activities to the second page, where the output looks like this: Array ( [exerciseid] => Hunting, general [duration] => Array ( [Fishing from boat, sitting] => 20 [Fishing from river bank, standing] => [Fishing in stream, in waders] => [Fishing, general] => [Fishing, ice, sitting] => [Hunting, general] => ) [distance] => Array ( [Fishing from boat, sitting] => 25 [Fishing from river bank, standing] => [Fishing in stream, in waders] => [Fishing, general] => [Fishing, ice, sitting] => [Hunting, general] => ) [submit] => Add Activities ) Is there a way I can pass what the user input instead of passing everything (form validation maybe?)
  13. I'm glad that part works. I guess now it's a question of getting the input values to show up on the next page. Is that where the form validation will come in?
  14. I know I will have to validate the form, but is there anyway to pass the values the way the code is right now just for testing purposes?
  15. I want to pass the values the user puts in duration and distance. Should I set default values?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.