Jump to content

msebar

Members
  • Posts

    14
  • Joined

  • Last visited

Recent Profile Visitors

707 profile views

msebar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The empty statement worked. Thanks much
  2. The if statement doesn't work the rest of the code does. If I leave the fields blank coming in from the form it echo's the first statemnet. If I fill in the form the first statment still gets echoed and my results don't show. So my issue really is the else is not working
  3. Sorry for the miss spell on correctly counldn't edit the title I need to have the following 3 varibles checked to see if they are set and if not display an error saying "All fields need to be filled in." My problem is that it's not working. Did I mess up on my if statement? $tempneeded $lowtemp $gallons <?php $tempneeded = $_POST['tempneeded']; $lowtemp = $_POST['lowtemp']; $gallons = $_POST['gallons']; htmlspecialchars($tempneeded, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($lowtemp, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($gallons, ENT_QUOTES, 'UTF-8') . ' ' . $wgd = .5; $tempdiff = $tempneeded - $lowtemp; $wattsneeded = $tempdiff * ($gallons * $wgd); if (!isset ($lowtemp,$tempneeded,$gallons)) { echo "<b>All fields need to be filled in.</b>"; } else { echo "<b>You will need a total of $wattsneeded watts to rasie your tempature $tempdiff degress, from $lowtemp to $tempneeded.</b></td></tr>"; } ?>
  4. Wow I think I need a break. Be learning PHP on and off for the last 5 years and decided to dig in deep this time. I think I will take the rest of the night off and start tomorrow or Monday. Just trying to absorb as much as I can in short time. BTW your correct it worked. I spent 2 hours on this as I didn't want to ask the question. Had no choice started to get frustrated. Thanks again you guys are always there for me.
  5. Came a long way with the code since Friday and have another issue. I can echo the session username on my pages but not into the insert command to the database. I need this so when a user logs in only their data will be seen. Here is the code pages. Here is the page code this does echo the username Logged in as <?php echo "$username"; ?> <?php // Start session session_start() ; $username = $_SESSION['username']; // Include required functions file require_once('include/db/functions.inc.php') ; // Check login status ... if not logged in, redirect to login screen if (check_login_status() == false) { redirect('login.php') ; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Add A New Tank(WAD)</title> <style type="text/css"></style> </head> <body> <p align="center"><a href="../test/index.php">Home</a> | <a href="../test/register.php">Register</a> | <a href="../test/login.php">Login</a> | <a href="../test/tank.php">Add Tank</a> | <a href="../test/fish.php">Add Fish</a> | <a href="../test/plants.php">Add Plants</a> | <a href="../test/water-test.php">Add Water Test</a> | <a href="../test/include/login/logout.inc.php">Logout</a></p></p> <p>Logged in as <?php echo "$username"; ?> </p> <table width="810" border="2" align="center"> <tr> <td> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" bgcolor="#FFFFFF" scope="col"><h2><b>Your Tanks(WAD)</b></h2></td> </tr> <form action="/test/include/tank/tank.inc.php" method="post" name="tank" id="tank"> <table border="2" align="center" cellpadding="0"> <tr> <td><div align="left"><b>Tank Name: </b> </div></td> <td><div align="left"> <input type="text" name="tankname" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Date Filled With Water: </b> </div></td> <td><div align="left"> <input type="text" name="date" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Length: </b> </div></td> <td><div align="left"> <input type="text" name="length" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Depth: </b> </div></td> <td><div align="left"> <input type="text" name="depth" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Height: </b> </div></td> <td><div align="left"> <input type="text" name="height" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Volume: </b> </div></td> <td><div align="left"> <input type="text" name="volume" size="25" /> </div></td> </tr> <tr> <td><div align="left"><b>Type of Tank: </b> </div></td> <td><div align="left"> <input type="text" name="type" size="25" /> </div></td> </tr> <tr> <td></div></td></tr> <tr> <td><div align="left"><b>Notes: </b> </div></td> <td><div align="left"> <p> <textarea name="notes" cols="50" rows="10"></textarea> </p> </div></td> </tr> <tr> <th colspan="2"><p> <input type="submit" value="Add New Tank" /> </p></th> </tr> </table> </form> <tr> <td align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><font size="2"> © 2014 <a href="http://www.pctechtime.com">PC TECH TIME</a> </font> </div></td> </tr> </table> <tr> <td></td></td></tr> <tr> <td></tr></td></tr> </table> </body> </html> This is tank.inc.php which works except for the username being inserted into the database. I did try removing the mysqli_close($con); but that didn't help. I did have it working when I removed the mysqli_close($con); but then I logged out and then back in and it stopped? <?php include_once "../../../test/include/db/db.inc.php"; // escape data and set variables $tankname = mysqli_real_escape_string($con, $_POST['tankname']); $date = mysqli_real_escape_string($con, $_POST['date']); $length = mysqli_real_escape_string($con, $_POST['length']); $depth = mysqli_real_escape_string($con, $_POST['depth']); $height = mysqli_real_escape_string($con, $_POST['height']); $volume = mysqli_real_escape_string($con, $_POST['volume']); $type = mysqli_real_escape_string($con, $_POST['type']); $notes = mysqli_real_escape_string($con, $_POST['notes']); $username = $_SESSION['username']; // # setup SQL statement $sql="INSERT INTO tank (tankname, username, date, length, depth, height, volume, type, notes) VALUES ('$tankname', '$username', '$date', '$length', '$depth', '$height', '$volume', '$type', '$notes')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo 'New Tank Added '; mysqli_close($con); ?>
  6. That worked great. Thanks. What got me confused was that if I ran the select file by itself each option would be on a different line. After seeing your fix it makes sense.
  7. When I look at my page in source view the <br> are in the drop down but not working. Here is my php code along with the view source. This is the main page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Water Analysis Data(WAD)</title> <style type="text/css"></style> </head> <body> <p align="center"><a href="../test/index.html">Home</a> | <a href="../test/register.php">Register</a> | <a href="../test/login.php">Login</a> | <a href="../test/tank.php">Add Tank</a> | <a href="../test/fish.php">Add Fish</a> | <a href="../test/water_test.php">Add Water Test</a></p> <p align="center"> </p> <table width="810" border="2" align="center"> <tr> <td><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" bgcolor="#FFFFFF" scope="col"><h2><b>Water Analysis Data(WAD)</b></h2></td> </tr> <tr> <td bgcolor="#FFFFFF"> <form id="form1" method="POST" action="/include/waterparameters/water-parameters.inc.php"> <table border="2" align="center" cellpadding="0"> <tr> <td><div align="left"><b>Tank Name: </b> </div></td> <td><div align="left"> <select id="tankname" type='text' name="tankname"> <option> <?php include_once '/include/dropdowns/water-parameters-dd.inc.php'; ?> </option> </select> </div></td> </tr> <tr> <td><div align="left"><b>Test Date: </b> </div></td> <td><div align="left"> <input id="date" type="text" name="date" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Temperature: </b> </div></td> <td><div align="left"> <input id="temperature" type="text" name="temperature" size=25> </div></td> </tr> <tr> <td><div align="left"><b>pH: </b> </div></td> <td><div align="left"> <input id="ph" type="text" name="ph" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Ammonia: </b> </div></td> <td><div align="left"> <input id="ammonia" type="text" name="ammonia" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Nitrite: </b> </div></td> <td><div align="left"> <input id="nitrite" type="text" name="nitrite" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Nitrate: </b> </div></td> <td><div align="left"> <input id="nitrate" type="text" name="nitrate" size=25> </div></td> </tr> <tr> <td><div align="left"><b>phosphate: </b> </div></td> <td><div align="left"> <input id="phosphate" type="text" name="phosphate" size=25> </div></td> </tr> <tr> <td><div align="left"><b>GH: </b> </div></td> <td><div align="left"> <input id="gh" type="text" name="gh" size=25> </div></td> </tr> <tr> <td><div align="left"><b>KH: </b> </div></td> <td><div align="left"> <input id="kh" type="text" name="kh" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Iron: </b> </div></td> <td><div align="left"> <input id="iron" type="text" name="iron" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Potassium: </b> </div></td> <td><div align="left"> <input id="potassium" type="text" name="potassium" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Notes: </b> </div></td> <td><div align="left"> <p> <textarea id="notes" name="notes" cols="50" rows="10"></textarea> </p> </div></td> </tr> <tr> <th colspan=2><p> <input type="submit" value="Submit"id="submit1" class="submit" name="submit" /> </p></th> </tr> </table> </form></td> </tr> <tr> <td align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><font size=2> © 2014 <a href="http://www.pctechtime.com">PC TECH TIME</a> </font> </div></td> </tr> </table></td> </tr> </table> </body> </html> This is the include for the page (the echo line for <br> shows in the source but doesn't produce the break <?php include_once "/include/db/db.inc.php"; $result = mysqli_query($con,"SELECT tankname FROM tank"); while($row = mysqli_fetch_array($result)) { echo $row['tankname']; echo "<br>"; } mysqli_close($con); ?> Here is the source when you bring the file up in a browser <select id="tankname" type='text' name="tankname"> <option> Tank 1<br>Tank 2<br>Tank 3<br> </option> </select>
  8. I know it's a mess, I am in the process of learning and I will work on cleaning it up. Thanks
  9. Yes that is what I was missing. I got it to work but now the selection doesn't post to the database.
  10. Can someone help here. I can't get the drop down to populate before the post. It does populate after post and the selected option doesn't post after it get populated. Here is the code I have Once I get everything working I will be moving to mysqli or pod <?PHP require_once('../../lib/connections/db.php'); include('../../lib/functions/functions.php'); checkLogin('2'); $getuser = getUserRecords($_SESSION['user_id']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Water Analysis Data(WAD)</title> <style type="text/css"> </style> </head> <body> <div align="right"><a href="../wad/index.php">Home</a> | <? if (!empty($getuser[0]['thumb_path'])){echo "<a href='.//manage_photo.php'>Manage My Photo</a> | ";} else {echo "<a href='../upload_photo.php'>Upload Photo</a> | ";} ?><a href="../change_pass.php">Change password</a> | <a href="../edit_profile.php">Edit Profile</a> | <a href="../log_off.php?action=logoff">Sign Out</a></div></td> <p>Welcome <?php if(empty($getuser[0]['first_name']) || empty($getuser[0]['last_name'])){echo $getuser[0]['username'];} else {echo $getuser[0]['first_name']." ".$getuser[0]['last_name'];} ?></p> <br><br><br> <?php // this is processed when the form is submitted // back on to this page (POST METHOD) if ($_SERVER['REQUEST_METHOD'] == "POST") { $usernow = $getuser[0]['username']; $userid = $usernow; # escape data and set variables $tank = addslashes($_POST["tank"]); $date = addslashes($_POST["date"]); $temperature = addslashes($_POST["temperature"]); $ph = addslashes($_POST["ph"]); $ammonia = addslashes($_POST["ammonia"]); $nitrite = addslashes($_POST["nitrite"]); $nitrate = addslashes($_POST["nitrate"]); $phosphate = addslashes($_POST["phosphate"]); $gh = addslashes($_POST["gh"]); $kh = addslashes($_POST["kh"]); $iron = addslashes($_POST["iron"]); $potassium = addslashes($_POST["potassium"]); $notes = addslashes($_POST["notes"]); // build query // # setup SQL statement $sql = " INSERT INTO water_parameters "; $sql .= " (id, userid, tank, date, temperature, ph, ammonia, nitrite, nitrate, phosphate, gh, kh, iron, potassium, notes) VALUES "; $sql .= " ('', '$userid', '$tank', '$date', '$temperature', '$ph', '$ammonia', '$nitrite', '$nitrate', '$phosphate', '$gh', '$kh', '$iron', '$potassium', '$notes') "; // #execute SQL statement $result = mysql_query($sql); // # check for error if (mysql_error()) { print "Database ERROR: " . mysql_error(); } print "<h3><font color=red>New Water Parameters Were Added</font></h3>"; } ?> <table width="810" border="2" align="center"> <tr> <td> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" bgcolor="#FFFFFF" scope="col"> <h2><b>Water Analysis Data(WAD)</b></h2></td> </tr> <tr> <td bgcolor="#FFFFFF"> <form name="water_parameters" action="water_parameters.php" method="POST"> <table border="2" align="center" cellpadding="0"> <tr><td><div align="left"><b>Tank Name: </b> </div></td><td><div align="left"> <?php echo "<select>"; $results = mysql_query("SELECT tank FROM tank WHERE userid = '$userid'"); while($row = mysql_fetch_array($results)) { echo "<option value=". $row["tank"] .">". $row["tank"] . "</option>"; } echo "</select>"; ?> </div></td></tr> <tr><td><div align="left"><b>Test Date: </b> </div></td><td><div align="left"> <input type="text" name="date" size=25> </div></td></tr> <tr><td><div align="left"><b>Temperature: </b> </div></td><td><div align="left"> <input type="text" name="temperature" size=25> </div></td></tr> <tr><td><div align="left"><b>pH: </b> </div></td><td><div align="left"> <input type="text" name="ph" size=25> </div></td></tr> <tr><td><div align="left"><b>Ammonia: </b> </div></td><td><div align="left"> <input type="text" name="ammonia" size=25> </div></td></tr> <tr><td><div align="left"><b>Nitrite: </b> </div></td><td><div align="left"> <input type="text" name="nitrite" size=25> </div></td></tr> <tr><td><div align="left"><b>Nitrate: </b> </div></td><td><div align="left"> <input type="text" name="nitrate" size=25> </div></td></tr> <tr><td><div align="left"><b>phosphate: </b> </div></td><td><div align="left"> <input type="text" name="phosphate" size=25> </div></td></tr> <tr><td><div align="left"><b>GH: </b> </div></td><td><div align="left"> <input type="text" name="gh" size=25> </div></td></tr> <tr><td><div align="left"><b>KH: </b> </div></td><td><div align="left"> <input type="text" name="kh" size=25> </div></td></tr> <tr><td><div align="left"><b>Iron: </b> </div></td><td><div align="left"> <input type="text" name="iron" size=25> </div></td></tr> <tr><td><div align="left"><b>Potassium: </b> </div></td><td><div align="left"> <input type="text" name="potassium" size=25> </div></td></tr> <tr><td><div align="left"><b>Notes: </b> </div></td><td><div align="left"> <p><textarea name="notes" cols="50" rows="10"></textarea></p> </div></td></tr> <tr><th colspan=2><p><input type="submit" value="Add New Test"></p></th></tr> </table> </form> </td> </tr> <tr> <td align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><font size=2> © 2014 </font> </div></td> </tr> </table> </td> </tr> </table> </body> </html>
  11. That worked pefect thank you very much. Once I do finish the site being I have only 3 more pages to complete I will look into converting it to MYSQLi. From what I just looked to convert it I think it most likely be a pain in the butt. But I see it has to be done. Thanks once again. Mike
  12. I have a membership site that a user creates a username and password at registration. The user logs in and all that works. The usersname is located in the database under users. Each page is protected and you must login to access it. Here is the code for that checkLogin('2'); $getuser = getUserRecords($_SESSION['user_id']); If the user login is correct they have access to the page. This all works fine as I said. On this page is a form that gets filled out. All the data except the username is added to the database for the contents of this form. I need to have the username added to the database to track who the data belongs to. Here is the code I have for this, can some tell me where I messed up. The line under the the code <body> pulls the username and the echo command prints the username on the page. I repeated this code under the if ($_SERVER['REQUEST_METHOD'] == "POST") code and it also prints the username. <?php // this is processed when the form is submitted // back on to this page (POST METHOD) if ($_SERVER['REQUEST_METHOD'] == "POST") { $usernow = $getuser[0]['username']; $userid = $usernow; echo "$userid"; # escape data and set variables $userid = addslashes($_POST["userid"]); $date = addslashes($_POST["date"]); $temperature = addslashes($_POST["temperature"]); $ph = addslashes($_POST["ph"]); $ammonia = addslashes($_POST["ammonia"]); $nitrite = addslashes($_POST["nitrite"]); $nitrate = addslashes($_POST["nitrate"]); $phosphate = addslashes($_POST["phosphate"]); $gh = addslashes($_POST["gh"]); $kh = addslashes($_POST["kh"]); $iron = addslashes($_POST["iron"]); $potassium = addslashes($_POST["potassium"]); $notes = addslashes($_POST["notes"]); // # setup SQL statement $sql = " INSERT INTO water_parameters "; $sql .= " (id, userid, date, temperature, ph, ammonia, nitrite, nitrate, phosphate, gh, kh, iron, potassium, notes) VALUES "; $sql .= " ('', '$userid', '$date', '$temperature', '$ph', '$ammonia', '$nitrite', '$nitrate', '$phosphate', '$gh', '$kh', '$iron', '$potassium', '$notes') "; // #execute SQL statement $result = mysql_query($sql); // # check for error if (mysql_error()) { print "Database ERROR: " . mysql_error(); } print "<h3><font color=red>New Water Parameters Were Added</font></h3>"; } ?>
×
×
  • 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.