Jump to content

dmhall0

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Everything posted by dmhall0

  1. Ha... sorry. Here is the query. INSERT INTO u_rides (username, wotype, wodate, woname, bikename, starttime, duration, distance, workkj, spdavg, spdmax, hravg, hrmax, cadavg, cadmax, pwravg, pwrmax, terrain, temp, weather, notes) VALUES ('dhall', 'Cycling', '2011-12-08', 'Test Ride', 'Tarmac SL', '3:34', '3:23', '45', '', '', '', '', '', '', '', '', '', '', '', '', '') So I need it to accept the blanks, or fill them with something I guess. Thanks for the help!
  2. I should also add that some of the questions do have drop-down selection. So how can I take the above code suggestion and make that work across all options? This seems complicated to me, but what do I know! ha
  3. Here is the code: // Add workout to the database if (isset($_POST['submit'])) { // Grab the data from POST $username = $_SESSION['username']; $wotype = cleaninput($dbc, $_POST['wotype']); $wodate = isset($_REQUEST["wodate"]) ? $_REQUEST["wodate"] : ""; $woname = cleaninput($dbc, $_POST['woname']); $bikename = cleaninput($dbc, $_POST['bikename']); $starttime = cleaninput($dbc, $_POST['starttime']); $duration = cleaninput($dbc, $_POST['duration']); $distance = cleaninput($dbc, $_POST['distance']); $workkj = cleaninput($dbc, $_POST['workkj']); $spdavg = cleaninput($dbc, $_POST['spdavg']); $spdmax = cleaninput($dbc, $_POST['spdmax']); $hravg = cleaninput($dbc, $_POST['hravg']); $hrmax = cleaninput($dbc, $_POST['hrmax']); $cadavg = cleaninput($dbc, $_POST['cadavg']); $cadmax = cleaninput($dbc, $_POST['cadmax']); $pwravg = cleaninput($dbc, $_POST['pwravg']); $pwrmax = cleaninput($dbc, $_POST['pwrmax']); $temp = cleaninput($dbc, $_POST['temp']); $terrain = cleaninput($dbc, $_POST['terrain']); $weather = cleaninput($dbc, $_POST['weather']); $notes = cleaninput($dbc, $_POST['notes']); if (!empty($wodate) && !empty($duration) && !empty($distance)) { $query = "INSERT INTO u_rides (username, wotype, wodate, woname, bikename, starttime, " . " duration, distance, workkj, spdavg, spdmax, hravg, hrmax, cadavg, cadmax, pwravg, pwrmax, " . " terrain, temp, weather, notes) " . " VALUES ('$username', '$wotype', '$wodate', '$woname', '$bikename', '$starttime', " . " '$duration', '$distance', '$workkj', '$spdavg', '$spdmax', '$hravg', '$hrmax', '$cadavg', '$cadmax', '$pwravg', '$pwrmax', " . " '$terrain', '$temp', '$weather', '$notes')"; mysqli_query($dbc, $query) or die('Connection Error: '.mysqli_error($dbc)); Here is my cleaninput function: function cleaninput($dbc, $var) { $var=stripslashes($var); $var=htmlentities($var); $var=strip_tags($var); $var=mysqli_real_escape_string($dbc, $var); $var=trim($var); return $var;
  4. Interesting... And if a new user is on the profile page that does not yet have data in the db how with this work? Will it fail or still build the form, but values will be blank? Thanks for the help! This is a pretty cool idea.
  5. Hi SergeiSS Thanks for the reply. I have 2 tables already. Table 1 has questionid and question. Table 2 has questionid and answer. The answers are not static, so creating a table with all possible answers as you suggest is impossible. I guess what I am looking for is some php code that does 2 things: 1. extracts the "questionid" and "answer" fields in an array with a row for each questionid/answer combination (easy, I can do this part) 2. then sets the value of a textbox equal to the answer that matches a specific questionid (almost something like value = answer where questionid = 'Q15')
  6. I have a form with a series of text boxes where the User enters specific data, be it text, numeric, or date/time. It is not mandatory to fill in every box, but when I submit the form to be put into a mysql table, I get errors such as "Incorrect time value: '' for column 'starttime' at row 1" "Incorrect decimal value: '' for column 'workkj' at row 1" How can I setup the mysql table to accept blank answers? Or is there something I need to do in php to fix this? Sorry if this is simple... I'm still learning. Thanks for the help!
  7. I have a profile page where the user answers a list of about 20 questions. These questions are then put into a mysql table with username, questionid, and answer. I can store the answers to the table, but I cannot figure out how to get them back to view and edit. My form is built from basic HTML. I know how to pull answers from a db table with only 1 row of results, where each field is a different question, but this one is different, as it will pull 20 rows, and each row is for a different question. Here is how I populate the questions and then fill in the answers. // If this user has never set their profile, insert empty questions into the database $query1 = "SELECT * FROM u_profile WHERE username = '" . $_SESSION['username'] . "'"; $data = mysqli_query($dbc, $query1); if (mysqli_num_rows($data) == 0) { // First grab the list of questionids $query2 = "SELECT questionid FROM questions ORDER BY q_order"; $data = mysqli_query($dbc, $query2); $questionids = array(); while ($row = mysqli_fetch_array($data)) { array_push($questionids, $row['questionid']); } // Insert empty question rows into the u_profile table, one per question foreach ($questionids as $questionid) { $query3 = "INSERT INTO u_profile (username, questionid) VALUES ('" . $_SESSION['username']. "', '$questionid')"; mysqli_query($dbc, $query3); } } // If the questionnaire form has been submitted, write the responses to the database if (isset($_POST['submit'])) { // Write the questionnaire response rows to the response table foreach ($_POST as $answer_id => $answer) { $query4 = "UPDATE u_profile SET answer = '$answer' WHERE username = '" . $_SESSION['username'] . "' AND questionid = '$answer_id'"; $uprofile_set = "CALL uprofile_set('" . $_SESSION['username'] . "')"; mysqli_query($dbc, $query4) or die( "Connection Error1" . mysqli_error($dbc) ) ; mysqli_query($dbc, $uprofile_set) or die( "Connection Error2" . mysqli_error($dbc) ) ; } $races = "SELECT * FROM u_raceschedule WHERE username = '" . $_SESSION['username'] . "'"; $data = mysqli_query($dbc, $races); if (mysqli_num_rows($data) > 0) { set_time_limit(30); $buildplan = "CALL tplan('" . $_SESSION['username'] . "')"; mysqli_query($dbc,$buildplan) or die("Connection Error2" . mysqli_error($dbc) ) ; Would LOVE any help. I am really new to this whole coding thing.
×
×
  • 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.