Jump to content

john2121

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by john2121

  1. I have wasted so much time of so many of you good folks here just because I didn't understand something so basic. Thanks to all who tried to help and most especially to Pikachu who finally showed me the light. Thank you, guys and my apologies for testing your patience.
  2. Isn't that what I am doing i.e. executing the insert query before getting the last insert id? I am at my wits end because the same code on another page gives a last id of zero the first time and the second last one after I click the enter button in the address bar to reload the page. I am thoroughly confused. I acknowledge I must be a bit dense but I thought mysql_insert_id() was supposed to give the last id.
  3. Actually problem got worse. The code below gives me the second last id, not the last one. if (!$connProj) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databasename", $connProj); $sql="INSERT INTO Submitter (Name, SNL_ID,Org, Email) VALUES ('$name', '$snlid', '$org', '$email')"; $lastid = mysql_insert_id(); echo "last id: " . $lastid; if (!mysql_query($sql,$connProj)) { die('Error: ' . mysql_error()); } So after doing the insert the browser might show me 80 as the last id but in the database the last id is 81. I have checked it many times because I couldn't believe this could happen. Thank you so much for trying to help.
  4. Thank you, guys! However, I tried $lastid = mysql_insertid() but it only inserts in the second table. When I try to use that in a third table the value ends up being a zero. Is this variable valid for inserting into one table only? Thanks!
  5. I am trying to save LAST_INSERT_ID() to a session variable for later use but not with much success. This doesn't work. $_SESSION['lastid'] = LAST_INSERT_ID(); Thank you!
  6. Is it possible to do this? fpdf just opens a dialog box asking the user to save the pdf instead of saving it on the server. Also, is it possible to create a pdf from the data in a mysql table with PHP? Thanks!
  7. In case someone else has the same problem, I solved it by using: document.forms[0].elements instead of: myForm.elements . The second worked in an html page but not in a php page.
  8. I agree that validation should be done server-side but this is a different scenario. In this case the users are a captive audience of inside company professionals and the only validation they want is that the form should be submitted once all of the questions has been answered by selecting a radio button answer. They don't want any other validation. I have figured out how to submit the form with JavaScript after all the questions have been answered but I was wondering if PHP has a similar mechanism. Perhaps,not because this seems to be a client-side issue unless AJAX is used to communicate with the server.
  9. Thanks, jesirose for your response. And, especially, thank you gizmola, the moderator,for taking the time to provide such help. Great site this!
  10. Thank you for your response. I'll try it out. By joining the tables do you mean something like this: SELECT Questions.Question_ID, Questions.Question, Answers.AnswerID, Answers.Answer, Answers.Value FROM Questions INNER JOIN Answers ON Questions.Question_ID = Answers.Question_ID There too my problem was how to make the answers appear as a group below each question. Is a foreach loop used in such situations? Thanks!
  11. I apologize for posting in the wrong section. Here is what I want: Question 1 - Answer Choice 1 - Answer Choice 2 Answer Choice 3 Question 2 - Answer Choice 1 - Answer Choice 2 The answers to the first question have a QuestionID value of 1. The answers to the second question have a QuestionID value of 2. I didn't know how to do it with one recordset so I created two - one for questions and one for answers. // for questions mysql_select_db($database_connProj, $connProj); $query_Recordset1 = "SELECT Questions.Question_ID, Questions.Question FROM Questions"; $Recordset1 = mysql_query($query_Recordset1, $connProj) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); // for answers mysql_select_db($database_connProj, $connProj); $query_Recordset2 = "SELECT Answers.Answer_ID, Answers.Question_ID, Answers.Answer, Answers.Value FROM Answers"; $Recordset2 = mysql_query($query_Recordset2, $connProj) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); I am not sure how to do a foreach loop here so I tried a do while loop and a nested loop. <?php do { ?> <p><?php echo $row_Recordset1['Question_ID']; ?> php echo $row_Recordset1['Question']; ?></p> <?php do { ?> <form id="form1" method="post" action=""> <input type="radio" name="<?php echo "radio" . $row_Recordset2['Question_ID'];?>" id="radiobuttons" value="<?php echo $row_Recordset2['Value']; ?>" /> <label for="radiobuttons"><?php echo $row_Recordset2['Answer']; ?></label> </form> <?php } while ($row_Recordset2['Question_ID'] == $row_Recordset1['Question_ID']); ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> I am not sure how to change it. Thanks!
  12. Hello folks! I have a mysql table with questions and another one with multiple choice answers. The common key is QuestionID. Some questions have 2 answers, some 3, and some 4. I can display a list of all questions on my page but I am unable to display the related answers below them. I have been trying since yesterday but I just can't get it right. It seems to be a loop related problem. Could you give me any pointers? Thank you! John
×
×
  • 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.