
rvinikof
Members-
Posts
15 -
Joined
-
Last visited
Never
Everything posted by rvinikof
-
Using this code: if ($Numofbooks != "") { for ($i = 0; $i < $Numofbooks; $i++) { $Author = $_POST["bookauthor"]; $Title = $_POST["booktitle"]; $Edition = $_POST["edition"]; $ISBN = $_POST["isbn"]; $ReqorOpt = $_POST["reqoropt"]; if (isset($Author[$i])) { echo "<center>"; echo "Please enter an author for every book."; echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>'; echo "</center>"; exit(); } if ($Title[$i] == "") { echo "<center>"; echo "Please enter a title for every book."; echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>'; echo "</center>"; exit(); } if (($ISBN[$i] == "") || (strlen($ISBN[$i]) != 13)) { echo "<center>"; echo "Please enter a 13-digit ISBN for every book."; echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>'; echo "</center>"; exit(); } $sqlinsertlogin = "INSERT INTO bookrequest (requestID, author, title, edition, isbn, loginID, reqoropt, courseID) VALUES ('', '".$Author[$i]."', '".$Title[$i]."', '".$Edition[$i]."', '".$ISBN[$i]."', '".$loginid[0]."', '".$ReqorOpt[$i]."', '".$crnforclass[0]."')"; $insertlogin = mysql_query($sqlinsertlogin); if (!$insertlogin) { $insertloginerr = mysql_error(); echo $insertloginerr; exit(); } } } I'm trying to check to make sure that for every book, every author, title, and isbn is not empty. However, it seems like it only checks the first book. If the first book has an author, but the second doesn't, then it checks title and keeps going. The only time the error pops up is if the first author, title, isbn is empty. How do I make sure that it checks for every author?
-
That works if I use $Author[$i] in the Insert query. Thank you so much.
-
foreach($_POST["bookauthor"] as $Author) { echo $Author.'<br/>'; } I have it pulled in from the form and used in a foreach like you suggested. I mean, it is pulled from the form as a string I guess. Where am I supposed to change it? Or do I have to define it differently in my database?
-
My insert statement looks like this: for ($i = 0; $i < $Numofbooks; $i++) { $sqlinsertlogin = "INSERT INTO bookrequest (requestID, loginID, courseID, author) VALUES ('', '".$loginid[0]."', '".$crnforclass[0]."', '".$Author"')"; $insertlogin = mysql_query($sqlinsertlogin); if (!$insertlogin) { $insertloginerr = mysql_error(); echo $insertloginerr; exit(); } } If I put $Author[$i], then I get the first letter of the the very last value in one row and the second letter of the very last value in the next row and so on. If I just leave $Author, then it puts the last value in every row.
-
Thanks. When I echo it I get all the different values, but then what do I use to insert it? Because when I try it, it only enters the last value whatever number of times. It doesn't insert every value.
-
Using AJAX, I have a drop down that lists a number of books. Once a number is picked, where q is the number picked, it does this: for($i=0; $i < $q; $i++) { echo '<b>Book author:</b> <input type = "text" name = "bookauthor"/><br/><br/>'; echo '<b>Book title:</b> <input type = "text" name = "booktitle"/><br/><br/>'; echo '<b>Book edition:</b> <input type = "text" name = "edition"/><br/><br/>'; echo '<b>ISBN:</b> <input type = "text" name = "isbn"/><br/><br/>'; echo '<b>Required or Optional?</b> <select name = "reqoropt">'; echo '<option value = "required">Required</option><option value = "optional">Optional</option></select><br/><br/>'; echo "<hr/>"; } Once this is submitted, I have requestIDs and a courseID that is inserted into a bookrequest table q number of times. That part works. I need to now insert the author, title, ect. into this table as a new line so that each author, title ect. gets a different requestID. Right now, if q is 2, my table will look like this: requestID courseID author title ect. 1 12 2 12 Instead of: requestID course ID author title ect. 1 12 author1 title1 2 12 author2 title2 I think I need to make the author, title, ect. into an array and then insert it, but everything I've tried isn't really working.
-
I have a loop that creates the option to enter more than one book, author ect., where $q is just the number they enter that determines how many times the text boxes show up. for($i=0; $i < $q; $i++) { echo '<b>Book author:</b> <input type = "text" name = "bookauthor"/>'; echo '<b>Book title:</b> <input type = "text" name = "booktitle"/>'; echo '<b>Book edition:</b> <input type = "text" name = "edition"/>'; echo '<b>ISBN:</b> <input type = "text" name = "isbn"/>'; echo '<b>Required or Optional?</b> <select name = "reqoropt">'; echo '<option value = "required">Required</option><option value = "optional">Optional</option></select>'; } How do I then update this into my table? Before this is updated, I will have a requestID and a courseID that is inserted $q times. I want to have each author, title, ect. be inserted into a different requestID.
-
Thanks. One last question... once I have the data in the drop down, is there a way I can put a blank field before all the data (at index 0) so that it will be blank instead of data from the table appearing? Can I do this without having to add null values or something like that in my table?
-
You were right obviously. But now I've done this: $sqlsubject = "SELECT DISTINCT subject FROM courseinfo"; $subjectquery = mysql_query($sqlsubject) or die('Query failed: ' . mysql_error()); while ($subjectrow = mysql_fetch_row($subjectquery)) { echo '<b>Subject:</b><select name = "subject"><option value = "subject">'; foreach ($subjectrow as $subject) { echo $subjectrow; } echo "</option></select>"; } and the drop down just says Array. What does that mean?
-
I'm trying to input data from a field called subject to insert the different subjects into a drop down on a form to be selected. When I do this: $sqlsubject = "SELECT DISTINCT subject FROM courseinfo"; echo '<b>Subject:</b><select name = "subject"><option value = "subject">$sqlsubject</option></select>'; I just get the drop down saying $sqlsubject, instead of the list of subjects from the database.
-
but then how do i print out the three numbers for each item? when i use the foreach() i get item costs Array. item2 costs Array.
-
how do i assign multiple values to multiple elements? ex. $price = array("item" => 10, 15, 16, => "item2" => 13, 14, 15); i thought this would work, but when i try to show something like: item costs 10, 15, 16. item2 costs 13, 14, 15. instead i get: item costs 10. 0 costs 15. 1 costs 16. item2 costs 13. 2 costs 14. 3 costs 15.
-
how do i open a .html file without an error?
-
I've tried that. Is that supposed to still work even if it doesn't have a .php extension?
-
I'm making a form and after they click submit, I'm using an if/else statement to verify that the username and password they entered are correct, if they are, I want it to open a specific webpage and then in the else statement, show a message and redirect them back to the form page. How do I use php to open a URL?