Search the Community
Showing results for tags 'html'.
-
I am new at php. I am trying to loop a number in each click of a button. See attached picture for reference. 1 should iterate after the click of the button and will stop to iterate when it gets to 5. Here is my code: <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; $n = 1; $n <= $num; echo $n; ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html> If I try to loop it this way, <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; for($i = 1; $i <= $num; $i++){ echo $i; } ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html> the result is Question 12345 of 5.
-
Hey guys. I need help with the program. I get error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\index.php on line 15 Here is my code: 1st file. <?php include_once 'includes/DuombazesInfo.php' ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $sql = "SELECT * FROM vartotojai"; $result = mysqli_query($con, $sql); $resultCheck = mysqli_num_rows($result); if ($resultCheck > 0) { while ($row = mysqli_fetch_assoc($result)) { echo $row['vartotojas_vardas']; } } ?> </body> </html> 2nd file. <?php $dbServername = "localhost"; $dbUsername = "root"; $dbPassword = ""; $dbName = "duombaze"; $con = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbPassword);
-
Hello Larry and Hello Community, I bought book php and mysql for dynamic web sites in english from USA since i didn't see it in my native language. I gave a look all book for make general feeling and then i will read better and careful example and teching suggestions. Book is very very good in my opinion. My question is about what is best techinque to store html inside mysql database. I'm studying a bit how work CKeditor, but i think many html editor work more or less in same way, and it use a textarea to collect the html, so what you really need to do after a submit or similar processes is simply get the value of texarea and use php to store html in database. I'm asking how handle security, quote and double symbols or other problems. If i have understand i can use directly mysql_real_escape when i get textarea, simply before send html inside mysql or i can use prepared statement and in this case i think i can't use mysql_real_escape so i need pheraps to use htmlentities. I'm a little confuse about conflict you could have use both htmlentities, prepared statement, mysql_real_escape, etc.. I'm not exactly sure how i is best way general speaking in term of 100% secutiry and in term or not ruin html inside mysql and also i'm not sure what is procedure to make the contrary, i mean get html from mysql and serve i in page. Thanks very much. Andrea
-
Good day! First off, great book sofar! I am only on chapter 2 and I love it. (I don't have excel tho so unsure if the database parts will work) Anywho, I am creating different handle_forms to see if I can have it give different responses as I go along. However, it constantly reverts back to handle_form.php even when I go into the html document and change <form action="handle_form.php" method="post"> to <form action="handle_form1.php" method="post"> Am I missing something on how to do that to test different forms?
-
Modified the recursive function on page 19 to return divs instead of an ordered list. Function: function make_list($parent, $sub=FALSE) { // set attribute if (!$sub) { $attribute = 'id="menu"'; } else { $attribute = 'class="submenu"'; } // set tasks access global $tasks; foreach ($parent as $task_id => $todo) { // new loop? if (!$sub) { echo '<div id="main">'; } // build div echo '<div ' . $attribute . '>' . $todo . '</div>'; // check for next array if (isset($tasks[$task_id])) { // call function again make_list($tasks[$task_id], TRUE); } else { // close 'main' div echo '</div>'; } } } Output: <div id="main"> <div id="menu">Task 1</div> <div class="submenu">Subtask 1</div> <div class="submenu">SubSubTask 1</div> </div> <div id="main"> <div id="menu">Task 2</div> <div class="submenu">Subtask 2</div> <div class="submenu">SubSubTask 2</div> </div> <div id="main"> <div id="menu">Task 3</div> <div class="submenu">Subtask 3</div> </div> <div id="main"> <div id="menu">Task 4</div> <div class="submenu">Subtask 4</div> </div> The problem is: Both the SubTask and SubSubTask divs have the same class of 'submenu'. <div class="submenu">Subtask 1</div> <div class="submenu">SubSubTask 1</div> I'm trying to get them to have different class names, like so: <div class="submenu">Subtask 1</div> <div class="subsubmenu">SubSubTask 1</div> How might I structure the function to accomplish this? Any ideas would be helpful. ~ David
-
In going through this particular edition the HTML pages are supposed to be created with <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Do I have to input these particular HTML tags - or can they be safely replaced just with <!DOCTYPE HTML><meta http-equiv="content-type" content="text/html; charset=utf-8" />? Thank you.
-
The book won't get here until sometime tomorrow but I was able to get through chapter one via Kindle without a problem. I created a PHP file with the following HTML form in the beginning: <h3>Committee Volunteer Application</h3> <h4>Enter your Faculty ID</h4> <form method="post"> ID: <input name="soarid" type = "text" /> <input type = "submit" value "Go" /> </form> This was followed by PHP code that is to act upon the submitted value. However, the script does not wait for the form to be submitted but continues to execute. How do I make it wait for the submit button? BTW, separating this code into its own HTML file, it will run a separate PHP file when called by the form.
-
Case #1: Variable created from a POST: $identity = $_POST['soarid']; SELECT statement works just fine: $result = mysql_query("SELECT * FROM faculty WHERE id = $identity") or die("Faculty ID Not Found"); Variable created from a db field: $fac_school = $row["school"]; Variable content verified ok Attempt to use that variable in a SELECT statement: $result = mysql_query("SELECT * FROM position WHERE school = $fac_school") or die("Not found"); Does not work! Forcing the variable value thusly: $fac_school = "SOBM"; $result = mysql_query("SELECT * FROM position WHERE school = $fac_school") or die("Not found"); Still does not work! But this works: $result = mysql_query("SELECT * FROM position WHERE school = 'SOBM' ") or die("Not found"); Case #2: Similar to above but using INSERT INTO. The insert fails when variable values are used but ok when strings are used for values. All examples int the "PHP and MySQL" book use strings and not variables. What am I missing?
-
I want to get the primary key values of movie and actor table. When i selected values in radio button primary key has been created automatically to the movie and actor table. Now I want to get that primary key value and insert to the movie_actor table. my code connect.php <?php $dbc = mysqli_connect('localhost','root','black98765','db_name') OR die("Cannot connect to MySQL:" . mysqli_connect_error()); //insert into actor table $q = "INSERT INTO actor (name) VALUES ('$actor')"; //insert into movie table $q2 = "INSERT INTO movie (movie_name, release_year) VALUES ('$movie','$year')"; //movie_actor table $q3 = "INSERT INTO movie_actor (movie_no,actor_no,rate) VALUES ('$rate')"; //what value i need to put inside values for movie_no and actor_no? //connect and insert $q $r = mysqli_query($dbc,$q); $r2 = mysqli_query($dbc,$q2); $r3 = mysqli_query($dbc,$q3); if($r && $r2 && $r3){ echo "Inserted Successfully!"; }else{ echo "Failed to Insert Data!"; mysqli_error($dbc); } mysqli_close($dbc); ?> form.php <?php if(isset($_POST['submit'])){ if($_SERVER['REQUEST_METHOD'] == 'POST'){ $error = array(); //choose actor if(!isset($_POST['actor'])){ $error[] = "Please choose of the following actors!"; }else{ $actor = $_POST['actor']; } //choose movie if(!isset($_POST['movie'])){ $error[] = "Please choose of the following movies!"; }else { $movie = $_POST['movie']; } //choose release year if(!isset($_POST['year'])){ $error[] = "Please choose of the following release year!!"; }else{ $year = $_POST['year']; } //choose rate if(!isset($_POST['rate'])){ $error[] = "Please choose of the following rate!"; }else{ $rate = $_POST['rate']; } //if no errors if(empty($error)){ require('connect.php'); }else{ echo "<p>System Error!</p>"; foreach($error as $msg){ echo $msg."<br/>\n"; } } } } ?> <form action="form.php" method="POST"> <p>Select on the following Selections</p> <p><label for="actor">Name of Actor:</label> <input type="radio" name="actor1" value="Jet Li"/>Jet Li <input type="radio" name="actor2" value="Sylvester Stallone"/>Sylvester Stallone <input type="radio" name="actor3" value="Jason Statham"/>Jason Statham</p> <p><label for="movie">Name of Movie:</label> <input type="radio" name="movie1" value="Expendables 3"/>Expendables 3 <input type="radio" name="movie2" value="Rocky"/>Rocky <input type="radio" name="movie3" value="Kiss of the Dragon"/>Kiss of the Dragon</p> <p><label for="movie">Release Year:</label> <input type="radio" name="year1" value="2014"/>2014 <input type="radio" name="year2" value="1976"/>1976 <input type="radio" name="year3" value="2001"/>2001</p> <p><input type="submit" name="submit" value="Insert"/></p> </form>
-
I am building a site from the info in this book. And the post I am writing as you read this has a toolbar at the top that allows me to add bold to text, and other cool options. Where could I get a toolbar like this for my website, so I can add it to form fields.? The main thing I am looking for is adding paragraphs when people type 2 carriage returns on their keyboard. So that the text area form field behaves like as if you are typing in a word processing document. Adding bold to text, italics, and underline would be great too, but as a beginner I can accept if the paragraphs is all I can handle code-wise. I do know some javascript, so if coding it involves that I might be able to. Any ideas on how to go about this would be wonderful!
-
Hi, I've been troubleshooting the Creating the Views section in Chapter 9 and I can't seem to figure out why it keeps displaying the emptycart.html after I click add to Cart for the Kona Decaf item? It checks if the rows returned back from the Stored Proc is greater than zero. It should be as I added the item but yet it keeps showing the HTML for emptycart.html and not the cart.html file. To troubleshoot to see if the "if else" and the cart.html is working I changed the code to if the rows returned are <=0 and it finally showed my cart.html. But why doesn't it work when it is $r > 0? if (mysqli_num_rows($r) > 0) { // Products to show! include ('/views/cart.html'); } else { // Empty cart! include ('/views/emptycart.html'); }
-
Just wanted to recommend a website called CodeCademy.com. They offer free courses in Javascript, html, css, Ruby and several other languages and courses. It works kind of like a lot of those new apps you find on your phone. You get a task, you provide an answer, that answer is validated, and you can move along to a new course once finished. People learn differently, but I diffidently need to write code alongside learning. For those new to JS, I would definitly recommend reading Larry's book along with these tasks. You'll find out you learn a lot fast and in a fun way. Some of the tasks involve several revision of a black jack game, a cash register and other fun tasks. You also get trophies from a point system considering how well you've done. A very enjoyable and good way to deploy JavaScript code. Has anyone else tried it?