Jump to content

zer0uk

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by zer0uk

  1. Thanks for the replies ..... I don't get an error anymore 🙂 but the drop down box (which the code populates from db.) no longer appears so somethings up !! 😞 remove the code and hardcode "J" ... code works and the drop down list is populated with results filtered by "J" so I now have ... 1st pic code , 2nd pic code of working code div class="row s2 m2 l2"> <div> <label for="course_id">Choose the course raced:</label> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT `course_id`,`course_name` FROM `tbl_courses` WHERE `district`= {$_SESSION['g_district']} "); while($row = $resultset->fetch_assoc()) { echo "<option value='" . $row['course_id'] . "'>" . $row['course_name'] . "</option>"; } ?> </select> <div class="row s2 m2 l2"> <div> <label for="course_id">Choose the course raced:</label> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT `course_id`,`course_name` FROM `tbl_courses` WHERE `district`= 'J' "); while($row = $resultset->fetch_assoc()) { echo "<option value='" . $row['course_id'] . "'>" . $row['course_name'] . "</option>"; } ?> </select>
  2. please can you help .. I'm passing a value from another page using $_SESSION and trying to then use it in a SELECT statement in SQL think I'm missing something ... if hard code the value it works , and I have also checked at the other end that the variable is being assigned ... code is (its the = $_SESSION['g_district'] "); that's causing the issue I'm getting Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /Applications/XAMPP/xamppfiles/htdocs/mytimekeeper/add/add.php on line 170 in the browser <div class="row s2 m2 l2"> <div> <label for="course_id">Choose the course raced:</label> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT `course_id`,`course_name` FROM `tbl_courses` WHERE `district`= $_SESSION['g_district'] "); while($row = $resultset->fetch_assoc()) { echo "<option value='{$row[course_id]}'>{$row['course_name']}</option>"; } ?> </select>
  3. Figured this out now, was actually a lot easier than I thought .... learning 🙂
  4. Thanks for your reply so tbl_rides has a column "username_id" which has a FK to a table tbl_accounts.id the table holds the id, username, password, email tbl_account was the table used for registration and $_SESSION using column username
  5. Hi Can anyone help please. I have a web site that users fill in data about rides and post the to a mysql db I am using $_SESSION to store the user that is logged in. what I want to do is any records posted need to posted with the username stored and also when I retrieve the record I only want to SELECT the records that the lodge in user has posted. below is the php page I am using to add records ... Really appreciate any help as I am stuck on how to go about doing this ... <?php // database connect include('../db_connect.php'); session_start(); // blank fields $var_course_name = $var_r_time = $var_r_date = $var_bike = $var_comments =''; $errors = array('course' => '', 'r_time' =>'', 'r_date' =>'', 'bike' =>'', 'comments' =>''); //-------- Check Data ----------- //Check if Data is sent & validate if(isset($_POST['name_submit'])){ if(empty($_POST['name_submit'])){ Echo 'No Course passed'; } else { $var_course_id = mysqli_real_escape_string($conn, $_POST['course_id']); $var_r_time = mysqli_real_escape_string($conn, $_POST['r_time']); $var_r_date = mysqli_real_escape_string($conn, $_POST['r_date']); $var_bike = mysqli_real_escape_string($conn, $_POST['bike']); $var_comments = mysqli_real_escape_string($conn, $_POST['comments']); //Create sql $sql = "INSERT INTO tbl_rides(course_id, r_time, r_date) VALUES ('$var_course_id', '$var_r_time', '$var_r_date')"; //Save to DB and check if(mysqli_query($conn, $sql)){ } else { echo 'query error: ' . mysqli_error($conn); } } } //end of checking ?> <!DOCTYPE html> <html> <head> </head> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <!--Import Google Icon Font--> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <?php if($_SESSION["name"]) { ?> <div class="grey" > Welcome <?php echo $_SESSION["name"]; ?> </div> <?php }else echo "<h1>Please login first .</h1>"; ?> <header> <title>My TimeKeeper - Log Race</title> <body bgcolor="#bdbdbd"> </header> <body> <nav class="nav-wraper grey "> <div class="container"> <a href="../index_logged_in.php" class="brand-logo"> My TimeKeeper <i class="material-icons right">watch_later</i></a> <a href="#" class="sidenav-trigger" data-target="mobile-links"> <i class="material-icons">menu</i> </a> <ul class="right hide-on-med-and-down"> <li><a href="../login/logout.php">Logout <i class="material-icons right">close</i> </a></li> <li><a href="#">Statistics <i class="material-icons right">trending_up</i> </a></li> <li><a href="#">Forum <i class="material-icons right">forum</i> </a></li> </ul> </div> </nav> <ul class="sidenav" id="mobile-links"> <li><a href="../login/logout.php">Logout <i class="material-icons right">close</i> </a></li> <li><a href="#">Statistics <i class="material-icons right">trending_up</i> </a></li> <li><a href="#">Forum <i class="material-icons right">forum</i> </a></li> </ul> <div class="container"> <form class="grey-text text-lighten-2" action="add.php" method="POST"> <div class="row"> <div class="centre"> <h2 class="grey-text text-lighten-2">Log a race</h2> </div> <br> <div class="input-field"> <i class="material-icons prefix">date_range</i> <input type="text" name="r_date" class="datepicker"> <label for="r_date">Choose the date you raced</label> </div> <div class="input-field"> <i class="material-icons prefix">watch_later</i> <input value="hh:mm:ss"type="time" name="r_time"> <label for="r_time">Please enter your race time</label> </div> <div class="input-field"> <i class="material-icons prefix">directions_bike</i> <input type="text" name="bike"> <label for="bike">Please enter the bike used</label> </div> <div class="input-field"> <i class="material-icons prefix">comment</i> <input type="text" name="comments"> <label for="comments">Please enter any comments</label> </div> <div> <label for="course_id">Choose the course raced:</label> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT course_id, course_name FROM tbl_courses"); while($row = $resultset->fetch_assoc()) { echo "<option value='{$row[course_id]}'>{$row['course_name']}</option>"; } ?> </select> <div> <input class="btn grey darken-2" type="submit" name="name_submit" value="submit"> </div> </div> </form> </div> <section class="container section" id="photo's"> <div class="row"> <div class="col s12 l14"> <image src="../images/tony_m.jpeg" alt="" class="responsive-img" height=1000 px> </div> </section> <!-- Javacript --> <script src=https://code.jquery.com/jquery-3.4.1.min.js></script> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script> $(document).ready(function(){ $('.sidenav').sidenav(); $('select').formSelect(); $('.datepicker').datepicker(); }); </script> </body> <footer> <div class=>&copy; Copyright 2020 My TimeKeeper</div> <!-- Javacript --> <script src=https://code.jquery.com/jquery-3.4.1.min.js></script> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script> $(document).ready(function(){ $('.sidenav').sidenav(); }) </script> </footer> </html>
  6. Whoops on the variable !!! Thanks all its been driving me mad , its working perfectly cheers.
  7. Thanks for the help , I changed my code to yours but now my drop menu has nothing in it. What I want is the course_id be the value and the course_name as the label for the option. <?php // database connect include('../db_connect.php'); //-------- Check Data ----------- //Check if Data is sent & validate if(isset($_POST['name_submit'])){ if(empty($_POST['name_submit'])){ Echo 'No Course passed'; } else { $var_course_id = mysqli_real_escape_string($conn, $_POST['course_id']); //Create sql $sql = "INSERT INTO tbl_rides(course_id) VALUES ('$var_course_id')"; //Save to DB and check if(mysqli_query($conn, $sql)){ //success echo ("$var_course_id"); } else { echo 'query error: ' . mysqli_error($conn); } } } //end of checking ?> <!DOCTYPE html> <html> <form class="white" action="dropdown.php" method="POST"> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT course_id, course_name FROM tbl_courses"); while($rows = $resultset->fetch_assoc()) { echo "<option value='{$row[course_name]}'>{$row['course_name']}</option>"; } ?> </select> <div class="centre" > <input type="submit" name="name_submit" value="Submit my information !" /> </div> </form> </html>
  8. Thanks for your reply that produced quite a strange drop down so the information in the courses table is (course_id) = 15 (course_name) =J2/1 my drop down with your new loop had a J and then a 1 so I think it was only using the 1st letter from both columns and displaying both !!! I changed my code slightly and it now displays the J2/1 in the dropdown which is correct but its still trying to post that information rather than the course_id back to the db so weighting a 0 (which is wrong should be 15) I will try and post the new code below (correctly ) <?php // database connect include('../db_connect.php'); //-------- Check Data ----------- //Check if Data is sent & validate if(isset($_POST['name_submit'])){ if(empty($_POST['name_submit'])){ Echo 'No Course passed'; } else { $var_course_id = mysqli_real_escape_string($conn, $_POST['course_id']); //Create sql $sql = "INSERT INTO tbl_rides(course_id) VALUES ('$var_course_id')"; //Save to DB and check if(mysqli_query($conn, $sql)){ //success echo ("$var_course_id"); } else { echo 'query error: ' . mysqli_error($conn); } } } //end of checking ?> <!DOCTYPE html> <html> <form class="white" action="dropdown.php" method="POST"> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT * FROM tbl_courses"); while($rows = $resultset->fetch_assoc()) { $var_course_name = $rows['course_name']; echo "<option value='$var_course_name'>$var_course_name</option>"; } ?> </select> <div class="centre" > <input type="submit" name="name_submit" value="Submit my information !" /> </div> </form> </html>
  9. Hi Thanks for the reply but I don't seem to be able to see where it tells me how to change the data I supply to the form from course_name to course_id, below is the code at the minute this will populate the list with course_id and post to the DB correctly. I need the List to Display the name (course_name) <?php // database connect include('../db_connect.php'); //-------- Check Data ----------- //Check if Data is sent & validate if(isset($_POST['name_submit'])){ if(empty($_POST['name_submit'])){ Echo 'No Course passed'; } else { $var_course_id = mysqli_real_escape_string($conn, $_POST['course_id']); //Create sql $sql = "INSERT INTO tbl_rides(course_id) VALUES ('$var_course_id')"; //Save to DB and check if(mysqli_query($conn, $sql)){ //success } else { echo 'query error: ' . mysqli_error($conn); } } } //end of checking ?> <!DOCTYPE html> <html> <form class="white" action="dropdown.php" method="POST"> <select name="course_id"> <?php // query to create course_id dropdown $resultset = $conn->query("SELECT course_id FROM tbl_rides"); while($rows = $resultset->fetch_assoc()) { $var_course_id = $rows['course_id']; echo "<option value='$var_course_id'>$var_course_id</option>"; } ?> </select> <div class="centre" > <input type="submit" name="name_submit" value="Submit my information !" /> </div> </form> </html>
  10. Hello, must admit i'm very new to this and just a hobiest , I am creating a page which will be used for logging information. With a mysql database i have two tables "tbl_rides" & "tbl_courses" rides is the main table for storing information and has a foreign key associating column "course_id" with course_id in the tbl_courses What i want to do on a HTML/PHP page is display a drop down box that has the contents of "course" from the tbl_courses but when the user selects it and submits the record is written to the main form "tbl_rides" "course_id" so display the friendly name via the foreign key but the record is written to "tbl_rides" Can that be done .. am i going about this wrong ? Thanks for any help Andrew.
×
×
  • 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.