Jump to content

oolongdavies

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

oolongdavies's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for that, but I'm getting the following error - parse error, unexpected T_CONSTANT_ENCAPSED_STRING it relates to line 34 which is this line: echo "<option ".($row['fld_fruit']==$currentvalueoffruit?' selected ':' ')." value=$row[fld_fruit]>$row[fld_fruit]</option>"; Any ideas? TIA
  2. I have a script that gets values from a db and populates a dropdown box. I would like to autoselect the value from the db that matches $currentvalueoffruit? Does anyone know how to achieve this? Here's the code... $currentvalueoffruit = $_SESSION['fruit']; $sql = "SELECT * FROM tbl_food"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { echo '<option value="' . $row['fld_fruit'] . '"'; echo '>'; echo $row['fld_fruit] . '</option>'; }
  3. Hi, I have some code to upload files to a server but I am having difficulty modifying it to: 1. Only upload PDF files 2. rename the filename to a session variable called $filename For some reason, at the moment my code will allow me to upload all file types except for PDF files! Any help would be much appreciated. HEre's my code: $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } Thanks for looking.
  4. Brilliant - You the man!
  5. Thanks for that, I'm getting closer... That does work but it only adds the value of the last checkbox selected. Ideally, I would like to add each checkbox value (and username) to a new row in the db - so if 5 checkboxes are ticked, 5 new records are inserted. I really appreciare your help. TIA J
  6. Thanks for that but I can't get it to work. At the moment, the echo $query statement just displays "INSERT INTO table (fld_username, fld_risk) VALUES ("jupiter","Array")" I'deally, here's what I'd like - if 4 boxes are checked, then I need to insert 4 records where each record has the $SESSION['username'] value and one of the checkbox values. Alternatively, I could live with one row that contains the username and an array of the checkbox values. However, I have no idea how to retrieve them...
  7. Thanks for that, but what about the username variable? I understand the concept but not the code! Any help would really be appreciated. Tia J
  8. The following code selects checkbox values and posts them back to the page in an array. I can get the two echo statements at the bottom of the script to display the correct results, and I can even add the checkbox values to the database. However, the table 'tbl_product_risks' contains two fields, fld_risk and fld_username. The username is stored in $_SESSION['username'] and I would like to add this value to the database (fld_username) for each checkbox value (fld_risk) that is inserted - so the records would be inserted 'checkboxvalue', 'username'. I am a php novice and I would appreciate any help (I have been all day on this and I seem to be going round in circles!) <?include_once('dbconn.php');?> <form name = "addmsds3" action="index3.php" method="post"> <?php $sql = "SELECT * FROM tbl_risk_phrases"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { echo '<input type="checkbox" name="selection[]" value="' . $row['fld_risk_phrase_id'] . '">'; echo '' . $row['fld_risk_phrase_id'] . ''; echo '<br>'; } ?> <input type="submit" value="submit" name="submit"> </form> <br> <?php if(!isset($_POST)) exit(); $selections = (isset($_POST['selection']))?$_POST['selection']:NULL; $count = count($selections); $query = 'INSERT INTO tbl_product_risks (fld_risk) VALUES ('; $add = "'".implode("','",$selections)."'"; $query .= $add.')'; echo $query; echo '<br>'; echo $count ?>
  9. Thanks, I just copied the important code. I'm not that good at programming and I'm not entirely certain how I can achieve what I want to do. Any advice would be much appreciated. TIA
  10. I am trying to add records to a database based on a session variable called $_SESSION['user_id'] and checkbox values selected by the user. I think I need to store the data in an array and then somehow manipulate so that it can be inserted into a row in the db. I also have a feeling that I will have to cycle through the array elements and store each value in a dynamically created variable so that it can be inserted. So, does anybody know how I can achieve this? btw, the page posts to itself here's my code: <?php if ($_POST['submit'] == 'submit') { $sql='INSERT INTO mytable (fld_user, fld_cboxvalue) VALUES '. $_SESSION['user_id'] .' ,"' .$_POST['risks'] .'")'; mysql_query($sql) or die(mysql_error()); header('location: mypage.php'); } ?> <form name = "risks" method="post"> <input type="checkbox" name="risks" value="R00" >R00<br> <input type="checkbox" name="risks" value="R01" >R01<br> <input type="checkbox" name="risks" value="R02" >R02<br> <input type="checkbox" name="risks" value="R03" >R03<br> <input type="submit" value="submit" name="submit"> </form> Thanks in advance, J
  11. I tried your code on the first form and second forms but it displays 0.
  12. Here's the code from form1.php that adds the values to the database and redirects to form2.php if ($_POST['add'] == 'Add Record') { $sql = 'INSERT INTO tbl_details (surname, forename) VALUES ("' .$_POST['surname'].'" , "'. $_POST['forename'] .'")'; mysql_query($sql) or die(mysql_error()); header('location: form2.php'); } How can I retrieve the value of user_id from the record I have just created?
  13. Thanks, to be honest, I don't understand. I have tried it but I can't get it to work? Any ideas?
  14. To keep this simple, just assume I have 2 forms: Form 1 has two fields, "surname" and "forename". Form 2 has two fields, "address" and "zip code". I have a database with a table called tbl_details, the fields are: user_id - this is an autoincremented value surname forename address zip code When form1 is submitted, the surname and forename are inserted into the table (and a new autonumber is generated in the user_id field) and Form2.php is displayed. Is there any way of retrieving the user_id value of the data recently entered? Thanks in advance O
  15. @dgiberson ;D Nice one!
×
×
  • 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.