Jump to content

hikingwithu2

Members
  • Posts

    48
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://www.wiegand.org

Profile Information

  • Location
    Barranquilla, Colombia

hikingwithu2's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I have about 20 webpages that include mysqli procedural stuff, and I want to change those to mysqli procedural w/prepared statements. I've been through many sites that "teach" using prepared statements but none talk about converting an existing site to using them. An example (some of my existing code): if (isset($_POST['upload'])) { $description = $_POST['description']; $picAlt = $_POST['picAlt']; $status = $_POST['status']; mysqli_query($db, "INSERT INTO pics (fileName, description, picAlt, status) VALUES ('$fileName', '$description', '$picAlt', '$status')"); $_SESSION['message'] = "The photo has been saved"; header('location: photos_manager.php'); } Do I simply change my code to this?: if (isset($_POST['upload'])) { $description = $_POST['description']; $picAlt = $_POST['picAlt']; $status = $_POST['status']; $insertQry = 'insert into pics (fileName, description, picAlt, status) values(?,?,?,?)'; $insertStatement = mysqli_prepare($db,$insertQry); mysqli_stmt_bind_param($insertStatement,'ssss',$_POST['fileName'], $_POST['description'],$_POST['picAlt'], $_POST['status']); mysqli_stmt_execute($insertStatement); mysqli_close($db); $_SESSION['message'] = "The photo has been saved"; header('location: photos_manager.php'); } Then what after that? Does anything else anywhere in my pages that use this insert need to be changed?
  2. I'm using the w3.css modal to display videos stored on the local server: <button onclick="document.getElementById('<?php echo $row['id']; ?>').style.display='block'" class="w3-button w3-black"><i class="far fa-play-circle fa-3x"></i> <?php echo $row['short_description']; ?></button> <div id="<?php echo $row['id']; ?>" class="modal"> <div class="modal-content"> <div class="w3-container"> <span onclick="document.getElementById('<?php echo $row['id']; ?>').style.display='none'" class="w3-button w3-display-topright close">&times;</span> <video controls src="videos/<?php echo $row['fileName']; ?>" width="200"> </video> <p><?php echo $row['description'] ?></p> </div> </div> </div> <script> var modal = document.getElementById('<?php echo $row['id']; ?>'); window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> And that is working fine. Now I would like to add a pageHits column to my sql videos table and track the number of hits to each individual video. (I already track the number of hits to the videos page and that works fine.) I've tried numerous bits of code from numerous website and stackexchange and so far none of them have worked to increase the counter in the database. What code do I need to add to simply count the hits to the individual video modals? Thanks.
  3. Oh, I just noticed something! The last "else" has no condition, is this the reason why my code didn't work? Because my final "else" had a condition? If true, then do I need to add a final "else" with no condition? (The page is working now without it.) But, what is the correct thing to do?
  4. Thanks, that does indeed fix it, but I don't understand why it is happening. After all, the form of the process is (from this W3 site) - if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; } Which is how my code was written, using the third condition as only "else".
  5. I am writing a CRUD and this is a test page to combine 3 separate files into one page. If I comment out the final "else" section entirely the first "if" section and the "else if" section work fine, no errors. After I remove the comment marks for the final "else" section I get this error: PHP Parse error: syntax error, unexpected '?>' in /public_html/crud/test.php on line 139 (<- the line 139 the error points to is the final php closing tag before the closing body tag) It should be obvious, simple, but I can't find any reason why it is throwing out that error and breaking the page (it is just a blank white page). I'm sure somebody can scan through the code and see what I'm missing. Thanks. <!DOCTYPE html> <html> <head> <?php require_once "../HeaderStuff.php"; require_once "../connection.php"; ?> <style> table { width: 100%; } th {background-color: #f1f1c1;} .margin {margin-top: 4em;} </style> </head> <body style="background-color:<?php echo $bgColor; ?>"> <?php $choice = $_GET['choice']; $id = $_GET['id']; if ($choice == 'blogsEdit') { ?> <table class="w3-table-all"> <thead> <tr> <th class="textBig w3-padding-32 w3-left-align">Website Administration - Edit Blog</th> </tr> </thead> </table> <?php $sql = "SELECT id, cat, Fdate, title, para1, story, pic, picAlt FROM blogs WHERE id = $id"; $result = mysqli_query($link, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { // Display each field of the records. $id=$row['id']; // the blog id $cat=$row['cat']; // the blog category $Fdate=$row['Fdate']; // the blog date $title=$row['title']; // short title of the blog $para1=$row['para1']; // the introduction paragraph $story=$row['story']; // the rest of the blog after the intro paragraph $pic=$row['pic']; // picture for the blog $picAlt=$row['picAlt']; // alt text for the picture ?> <fieldset> <form action="blogsUpdate.php" method="post"> <table class="w3-table-all"> <tr> <th>Category:</th> <td><?php echo $cat; ?></td> </tr> <tr> <th>Blog Date:</th> <td><input type="text" name="Fdate" value="<?php echo $Fdate; ?>" /></td> </tr> <tr> <th>Blog Title</th> <td><input type="text" name="title" size="150" value="<?php echo $title; ?>" /></td> </tr> <tr> <th>Intro Paragraph</th> <td><textarea name="para1" id="para1" cols="150" rows="5"><?php echo $para1; ?></textarea></td> </tr> <tr> <th>Story</th> <td><textarea name="story" id="story" cols="150" rows="10"><?php echo $story; ?></textarea></td> </tr> <tr> <th>Picture File Name</th> <td><input type="text" name="pic" size="50" value="<?php echo $pic; ?>" /></td> </tr> <tr> <th>Picture Alt Text</th> <td><input type="text" size="150" name="picAlt" value="<?php echo $picAlt; ?>" /></td> </tr> <tr> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <td colspan="2"><button type="submit">Save Changes</button></td> </tr> </table> </form> </fieldset> <?php } } else { echo "0 results"; } } else if ($choice == 'lessonsEdit') { ?> <table class="w3-table-all"> <thead> <tr> <th class="textBig w3-padding-32 w3-left-align">Website Administration - Edit Lesson</th> </tr> </thead> </table> <?php $sql = "SELECT id, cat, Fname FROM blogs WHERE id = $id"; $result = mysqli_query($link, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { // Display each field of the records. $id=$row['id']; // the lesson id $cat=$row['cat']; // the lesson category $Fname=$row['Fname']; // the file name ?> <fieldset> <form action="lessonsUpdate.php" method="post"> <table class="w3-table-all"> <tr> <th>Category:</th> <td><?php echo $cat; ?></td> </tr> <tr> <th>File Name:</th> <td><input type="text" name="Fname" value="<?php echo $Fname; ?>" /></td> </tr> <tr> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <td colspan="2"><button type="submit">Save Changes</button></td> </tr> </table> </form> </fieldset> <?php } } else { echo "0 results"; } } else ($choice == 'writsEdit') { ?> <table class="w3-table-all"> <thead> <tr> <th class="textBig w3-padding-32 w3-left-align">Website Administration - Edit Writing</th> </tr> </thead> </table> <?php $sql = "SELECT id, cat, title, story FROM blogs WHERE id = $id"; $result = mysqli_query($link, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { // Display each field of the records. $id=$row['id']; // the writing id $cat=$row['cat']; // the category $title=$row['title']; // title of the writing $story=$row['story']; // the poem or story ?> <fieldset> <form action="writsUpdate.php" method="post"> <table class="w3-table-all"> <tr> <th>ID:</th> <td><?php echo $id; ?></td> </tr> <tr> <th>Category:</th> <td><?php echo $cat; ?></td> </tr> <tr> <th>Title</th> <td><input type="text" name="title" size="150" value="<?php echo $title; ?>" /></td> </tr> <tr> <th>Story</th> <td><textarea name="story" id="story" cols="150" rows="10"><?php echo $story; ?></textarea></td> </tr> <tr> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <td colspan="2"><button type="submit">Save Changes</button></td> </tr> </table> </form> </fieldset> <?php } } else { echo "0 results"; } } ?> </body> </html>
  6. I found my problem, and hopefully others searching these forums can learn from my mistake - I removed a level of div that was overriding a previously called div. The second div had display:block which was overriding the previous div which has display:table-cell. The two divs now match each others heights as described in the docs.
  7. Ok, I think I have something on this topic - the two cells do indeed always match sizes as long as the cell to the right is the same or small height as the cell on the left. If the right-cell is taller, the left-cell will not adjust and match the height. It appears to work only with the right-cell matching the left-cell. I haven't done any extra testing yet, but that appears to be what is happening. What I have done today is put some text in the left-cell and an image in the right-cell, if the image is taller than what the left-cell wants for the its own text, then the right-cell (image cell) grows taller. If I put more text in the left-cell it will grow automatically of course, but the right-cell will also grow to match it. Edit: I might be wrong afterall, as I just tried it with two div of text and no matter how much text is in either, the two side by side divs will not align to the same height. It's very strange, as I use side by side boxes in many places and they all align perfectly no matter what is in each of them. More testing... More testing shows the right-cell follows the left-cell for height. As the left-cell changes height the right-cell will follow, but it does not work in the reverse. More testing...
  8. FYI - (no help needed, this is a demonstration) - I'm in the process of developing a site for non-English speakers to learn conversational English (not grammar, as is the case with most English learning websites). While writing one of the pages I was experimenting with the radius and accordion and got some cool and unexpected results, you can see what I mean by looking at the page here - http://wiegand.org/ChipsEnglishHelp/a1-u0-intro.php Maybe some of you have already come across this, I don't know, but this is the first time I've seen this effect, anywhere. The accordion code I found on a website, then I added a radius of 10% to the <li> in the .css. Here's the code - /* * Author: Michael Raffaele <michael@mraffaele.com> * Date: 25th October 2011 * Info: http://www.mraffaele.com/blog/2011/10/25/css-accordion-no-javascript/ */ /* Shared for all accordion types */ .accordion { font-family:Verdana,Geneva,sans-serif; margin:0 auto; width:35em; padding:.5em; background:inherit; } .accordion ul { list-style:none; margin:0; padding:0; } .accordion li { margin:0; padding:0; border-radius: 10% } .accordion [type=radio], .accordion [type=checkbox] { display:none; } .accordion label { display:block; font-size:.8em; text-align:center; line-height:.8em; background:inherit; border:0; color:#542437; font-weight:600; cursor:pointer; text-transform:uppercase; -webkit-transition: all .2s ease-out; -moz-transition: all .2s ease-out; } .accordion ul li label:hover, .accordion [type=radio]:checked ~ label, .accordion [type=checkbox]:checked ~ label { background:#C02942; text-align: center; color:#FFF; } .accordion .content { padding:0 .5em; overflow:hidden; border:0; -webkit-transition: all .5s ease-out; -moz-transition: all .5s ease-out; } .accordion p { color:#333; margin:0 0 .5em; } .accordion h3 { color:#542437; padding:0; margin:.5em 0; } /* Vertical */ .vertical ul li { overflow:hidden; margin:0 0 .05em; } .vertical ul li label { padding:.5em; text-align: center; } .vertical [type=radio]:checked ~ label, .vertical [type=checkbox]:checked ~ label { border-bottom:0; } .vertical ul li label:hover { border:0; } .vertical ul li .content { height:0; border-top:0; text-align: center; } .vertical [type=radio]:checked ~ label ~ .content, .vertical [type=checkbox]:checked ~ label ~ .content { height:20em; border:0; }
  9. Here's the reference - https://www.w3schools.com/w3css/w3css_layout.asp Layout Cells Adjust to Equal Height Side-by-side w3-cell elements will also automatically self-adjust to equal height: I'm still having this problem, though it is not 100%, it might be more like 10%.
  10. Here's the reference - https://www.w3schools.com/w3css/w3css_layout.asp Layout Cells Adjust to Equal Height Side-by-side w3-cell elements will also automatically self-adjust to equal height: I'm still having this problem, though it is not 100%, it might be more like 10%.
  11. I got it working, here's the code: <style> .menubar { width: 100%; clear:both; padding:.5em; box-shadow:0 .07em .07em black; background-color:yellow; border-left:.43em solid orange; border-radius:.57em; } .h1-bar a { color:#000; background-color:yellow; box-shadow:0 .15em .15em black, 0 0 1.8em orange, 0 0 .36em indigo; border-radius:.57em; padding:.5em; margin-top:.5em; } .bar { width:100%; overflow:hidden; display:inline-block; } .btnMenu { float:left; background: orange; padding:.15em; border-radius:.57em; margin-right:.75em; -webkit-transition: background-color .5s ease-out; -moz-transition: background-color .5s ease-out; -o-transition: background-color .5s ease-out; transition: background-color .5s ease-out; } .btnMenu:hover { background-color: red; cursor: pointer; } .btnMenuReversed { float:left; background: pink; padding:.75em; margin:.5em; border-radius:.57em; -webkit-transition: background-color .5s ease-out; -moz-transition: background-color .5s ease-out; -o-transition: background-color .5s ease-out; transition: background-color .5s ease-out; } .btnMenuReversed:hover { background-color: green; cursor: pointer; } </style> <div class="bar menubar"> <div class="h1-bar"> <div class="btnMenu"><span class="btnMenuReversed"><a href="index.html">Home</a></span></div> <div class="btnMenu"><span class="btnMenuReversed"><a href="courses.html">Courses</a></span></div> <div class="btnMenu"><span class="btnMenuReversed"><a href="why.html">Why English?</a></span></div> <div class="btnMenu"><span class="btnMenuReversed"><a href="contact.html">Contact</a></span></div> </div> </div>
  12. I have a menubar that works great in Opera 49.0 but in Firefox 57.0.2(64bit) and IE11 there are no links, therefore it doesn't work at all. If I move the link urls outside the buttons they work as expected, but the buttons are completely messed up. What could possibly be the problem? The html looks like this: <div class="w3-bar menubar "> <div class="h1-bar"> <button class="btnMenu"><a href="index.html">Home</a></button> <button class="btnMenu"><a href="courses.html">Courses</a></button> <button class="btnMenu"><a href="why.html">Why English?</a></button> <button class="btnMenu"><a href="contact.html">Contact</a></button> </div> </div> And the .css looks like this: .menubar { width: 100%; clear:both; padding:1em; box-shadow:0 .07em .07em black; background-color:yellow; border-left:.43em solid orange; border-radius:.57em; } .h1-bar a { color:#000; background-color:yellow; box-shadow:0 .15em .15em black, 0 0 1.8em orange, 0 0 .36em indigo; border-radius:.57em; padding:.5em; margin-top:1em; }
  13. hmm, yeah, those do not sound familiar at all, but for some reason, in the back of my mind, I just seem to recall seeing something about those two divs being automatically drawn to the same size without the use of tables. I don't like using tables for layout, they are for data.
  14. When making two side-by-side divs with different amounts of text in them, and coloring the background, the two divs are of different heights. Now, I can use the style/height to set a height in pixels for the two divs, but I seem to recall seeing something in the w3schools site that showed how to make the two divs automatically the same height without setting the height in pixels. Or am I mistaken?
  15. Yes I do, and that particular section will not change as it is for images/graphics that need a white background, rather than making all the images/graphics transparent. So for this site that is acceptable.
×
×
  • Create New...