Jump to content

techkid

Members
  • Content count

    12
  • Joined

  • Last visited

About techkid

  • Rank
    Forum Newcomer
  • Birthday June 20

Users Experience

  • Experience
    Beginner
  • Area of Expertise
    I'm Learning

Profile Information

  • Gender
    Male
  • Location
    Sydney, Australia
  • Interests
    Building and fixing computers, reading, watching anime
  1. Multiple PHP actions on one form

    I actually ended up scrapping the pages and rebuilding from scratch, trying to split the HTML from the PHP, and have made a great deal of progress. While the end result is not exactly what I want, the proof of concept is done! Here is my final code: review.php <!DOCTYPE html> <html> <head> <title>Soul's Fire - Visitor Contributions</title> </head> <body background="Images/background.png"> <center><img src="Images/heading.png"></center> <h1 align="center"><font color="#cc9900">Soul's Fire - Visitor Contributions</font></h1> <p align="center">Words go here</p> <?php error_reporting(E_ALL & ~(E_WARNING)); $dbconnect=mysqli_connect("127.0.0.1", "David", "D15cw0rld", "poems"); $result=mysqli_query($dbconnect, "SELECT * FROM submissions WHERE Approved='N' ORDER BY Time_submit LIMIT 1"); $row=mysqli_fetch_array($result); ?> <form action="adddel.php" method="post"> <p align="center">You are reviewing entry: <input type="text" name="HEntry" value="<?php echo $row['ID']; ?>"> <table width="80%" border="1" align="center"> <caption align="bottom"><p><input type="submit" name="AppDel" value="Submit Approval"></caption> <tr> <th width="10%">Author</th><th width="15%">Title</th><th width="15%">Time Submitted</th><th width="*">Entry</th> </tr> <?php do { printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n", $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]); } while ($row=mysqli_fetch_row($result)); ?> <tr> <td colspan='4' align='center'><INPUT TYPE='radio' NAME='ConApprove' VALUE='Approve'>Approve Submission <br><INPUT TYPE='radio' NAME='ConApprove' VALUE='Delete'>Delete Submission</td></tr> </table> </form> <p align="center"><A HREF="index.php">Return to the home page</A> </body> </html> adddel.php <?php $error=""; $go=TRUE; $message=""; $dbconnect=mysqli_connect("127.0.0.1", "user", "password", "poems"); if(!$dbconnect) { die('Unable to connect to database.'); } $AppDel=$_POST["ConApprove"]; $ID=$_POST["HEntry"] if($AppDel=="Approve") { $message .="This will approve the submission. Continue?\\n"; $ApproveSet="UPDATE submissions SET Approved='Y' WHERE ID=$ID"; } elseif($AppDel=="Delete") { $message .="This will delete the submission. Continue?\\n"; $ApproveSet="DELETE FROM submissions WHERE ID=$ID"; } else { $error .="Please select before continuing\\n"; $go=FALSE; } if($go==TRUE) { (*)echo ("<script language='JavaScript'>confirm('$message');</script>"); mysqli_query($dbconnect, $ApproveSet) or die(mysqli_error()); echo "<A HREF='review.php'>Return to review page</A>\n"; } else { echo ("<script language='JavaScript'>alert('$error');</script>"); echo ("<script language='JavaScript'>javascript:history.go(-1)</script>"); } ?> The only niggling detail is that the confirm box, marked with an asterisk (*), proceeds whether you press "OK" or "Cancel", but for right now, I can live with that! Thank you very much for your help with this!
  2. Multiple PHP actions on one form

    I'm sure adding my form tags inside the PHP section of the script is a massive no-no, given how things are going for me here. And that, because of that, the added line you supplied is failing because of my poor use of quotation marks...
  3. Multiple PHP actions on one form

    I seem to be going from bad to worse. I realised a mistake in my entry on review.php, but my attempts to correct it causes it to fail. Here is my revised code (review.php): <!DOCTYPE html> <html> <head> <title>Soul's Fire - Review Submissions</title> </head> <body background="Images/background.png"> <center><img src="Images/heading.png"></center> <h1 align="center"><font color="#cc9900">Soul's Fire - Review Submissions</font></h1> <p align="center">Words go here</p> <?php error_reporting(E_ALL & ~(E_WARNING)); $dbconnect=mysqli_connect("127.0.0.1","David","D15cw0rld","poems"); $result=mysqli_query($dbconnect, "SELECT * FROM submissions WHERE Approved='N' ORDER BY Time_Submit LIMIT 1"); if ($row=mysqli_fetch_array($result)) { echo "<form action='adddel.php' method='post'>\n"; echo "<div align='center'>\n"; echo "<table border=1 width='80%'>\n"; echo "<caption align='bottom'><p><input type='submit' name='AppDel' value='Submit Approval'></caption>\n"; echo "<tr><th width='10%'>Author</th><th width='15%'>Title</th><th width='15%'>Time Submitted</th><th width='*'>Entry</th></tr>\n"; do { printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n", $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]); } while ($row=mysqli_fetch_row($result)); echo "<tr><td colspan='4' align='center'><INPUT TYPE='radio' NAME='ConApprove' VALUE='Approve'>Approve Submission <br><INPUT TYPE='radio' NAME='ConApprove' VALUE='Delete'>Delete Submission (*) <br><INPUT TYPE='hidden' NAME='whichRow' VALUE='<?php echo $row["ID"]; ?>'></td></tr>\n"; echo "</table></div></form>\n"; echo "<p align='center'><a href='#top'>Back to Top</a></p>"; } else { echo "<p align='center'>No entries to review.</p>"; } ?> <div align="center"> <A HREF="index.php">Return to the main page</A> </div> <h1 align="center"><font color="#cc9900">If you would like me to add content down here, let me know</font></h1> </body> </html> Which generates the attached error at the marked location.
  4. Multiple PHP actions on one form

    This is the revised code: review.php <!DOCTYPE html> <html> <head> <title>Soul's Fire - Review Submissions</title> </head> <body background="Images/background.png"> <center><img src="Images/heading.png"></center> <h1 align="center"><font color="#cc9900">Soul's Fire - Review Submissions</font></h1> <p align="center">Words go here</p> <?php error_reporting(E_ALL & ~(E_WARNING)); $dbconnect=mysqli_connect("127.0.0.1","user","password","poems"); $result=mysqli_query($dbconnect, "SELECT * FROM submissions WHERE Approved='N' ORDER BY Time_Submit LIMIT 1"); if ($row=mysqli_fetch_array($result)) { echo "<form action='adddel.php' method='post'>\n"; echo "<div align='center'>\n"; echo "<table border=1 width='80%'>\n"; echo "<caption align='bottom'><p><input type='submit' name='AppDel' value='Submit Approval'></caption>\n"; echo "<tr><th width='10%'>Author</th><th width='15%'>Title</th><th width='15%'>Time Submitted</th><th width='*'>Entry</th></tr>\n"; do { printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n", $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]); } while ($row=mysqli_fetch_row($result)); echo "<tr><td colspan='4' align='center'><INPUT TYPE='radio' NAME='ConApprove' VALUE='Approve'>Approve Submission <br><INPUT TYPE='radio' NAME='ConApprove' VALUE='Delete'>Delete Submission</td></tr>\n"; (*) echo '<input type="hidden" name="whichRow" value="<?php echo $row["ID"]; ?>"'; echo "</table></div></form>\n"; echo "<p align='center'><a href='#top'>Back to Top</a></p>"; } else { echo "<p align='center'>No entries to review.</p>"; } ?> <div align="center"> <A HREF="index.php">Return to the main page</A> </div> <h1 align="center"><font color="#cc9900">If you would like me to add content down here, let me know</font></h1> </body> </html> adddel.php <?php $error=""; $go=TRUE; $dbconnect=mysqli_connect("127.0.0.1", "user", "password", "poems"); if(!$dbconnect) { die('Unable to connect to database.'); } $AppDel=$_POST["ConApprove"]; (*) $whichRow = intval($_POST['whichRow']); if($AppDel=="Approve") { $message .="This will approve the submission. Continue?\\n"; $ApproveSet="UPDATE submissions SET Approved='Y' WHERE ID=$row['ID']"; } elseif($AppDel=="Delete") { $message .="This will delete the submission. Continue?\\n"; $ApproveSet="DELETE FROM submissions WHERE ID=$row['ID']"; } else { $error .="Please select before continuing\\n"; $go=FALSE; } if($go==TRUE) { echo ("<script language='JavaScript'>message('$message');</script>"); mysqli_query($dbconnect, $ApproveSet) or die(mysqli_error()); echo "<A HREF='review.php'>Return to review page</A>\n"; } else { echo ("<script language='JavaScript'>alert('$error');</script>"); echo ("<script language='JavaScript'>javascript:history.go(-1)</script>"); } ?> Still I encounter the same problem. I am reasonably sure I have the syntax (or possibly placement) wrong for the highlighted lines (I added an asterisk (*) at the start of the line to highlight my placement only).
  5. Multiple PHP actions on one form

    Unfortunately not. It still generates the same error, with or without the brackets...
  6. Hi there, I am writing a website for a friend. The goal is to allow people to write and submit poetry to help with depression and anxiety, provide messages of hope and things like that. I have created most of the website, but one section has got me stumped. What I want to implement is an approval process, where submitted poetry is segregated until reviewed and approved, given the proliferation of online trolls around such things. What I want to achieve is to have a form where a piece is reviewed with radio button selections for "approve" or "delete", and this is where I have stalled. This is what I have created: review.php <!DOCTYPE html> <html> <head> <title>Soul's Fire - Review Submissions</title> </head> <body background="Images/background.png"> <center><img src="Images/heading.png"></center> <h1 align="center"><font color="#cc9900">Soul's Fire - Review Submissions</font></h1> <p align="center">Words go here</p> <?php error_reporting(E_ALL & ~(E_WARNING)); $dbconnect=mysqli_connect("127.0.0.1","user","password","poems"); $result=mysqli_query($dbconnect, "SELECT * FROM submissions WHERE Approved='N' ORDER BY Time_Submit LIMIT 1"); if ($row=mysqli_fetch_array($result)) { echo "<form action='adddel.php' method='post'>\n"; echo "<div align='center'>\n"; echo "<table border=1 width='80%'>\n"; echo "<caption align='bottom'><p><input type='submit' name='AppDel' value='Submit Approval'></caption>\n"; echo "<tr><th width='10%'>Author</th><th width='15%'>Title</th><th width='15%'>Time Submitted</th><th width='*'>Entry</th></tr>\n"; do { printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n", $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]); } while ($row=mysqli_fetch_row($result)); echo "<tr><td colspan='4' align='center'><INPUT TYPE='radio' NAME='ConApprove' VALUE='Approve'>Approve Submission <br><INPUT TYPE='radio' NAME='ConApprove' VALUE='Delete'>Delete Submission</td></tr>\n"; echo "</table></div><br></form>\n"; echo "<p align='center'><a href='#top'>Back to Top</a></p>"; } else { echo "No entries to review."; } ?> <div align="center"> <A HREF="index.php">Return to the main page</A> </div> <h1 align="center"><font color="#cc9900">If you would like me to add content down here, let me know</font></h1> </body> </html> adddel.php <?php $error=""; $go=TRUE; $dbconnect=mysqli_connect("127.0.0.1", "user", "password", "poems"); if(!$dbconnect) { die('Unable to connect to database.'); } $AppDel=$_POST["ConApprove"]; if($AppDel=="Approve") { $message .="This will approve the submission. Continue?\\n"; $ApproveSet=("UPDATE submissions SET Approved='Y' WHERE ID=$row['ID']"); } elseif($AppDel=="Delete") { $message .="This will delete the submission. Continue?\\n"; $ApproveSet=("DELETE FROM submissions WHERE ID=$row['ID']"); } else { $error .="Please select before continuing\\n"; $go=FALSE; } if($go==TRUE) { echo ("<script language='JavaScript'>message('$message');</script>"); mysqli_query($dbconnect, $ApproveSet) or die(mysqli_error()); echo "<A HREF='review.php'>Return to review page</A>\n"; } else { echo ("<script language='JavaScript'>alert('$error');</script>"); echo ("<script language='JavaScript'>javascript:history.go(-1)</script>"); } ?> But when I select any option I only receive an error message (see attachment). I am only just recently getting back into website design after about 15 years, so my knowledge is pretty archaic and rudimentary. I have created basic forms for this website, which work with no problem, but this one is probably too ambitious for my limited knowledge. Thank you in advance.
  7. Wrapping my head around sessions and cookies

    Using Jay's example above, is it possible (and probably more importantly, safe) to use the $Username variable from 'login.php' as the validator for the session in the 'bootstrap.php' page? If no, what sort of validator should I use?
  8. Hi all, I have made a basic (very basic) webpage which I want to use to catalogue my DVD collection at home (just a bit of a personal project, and a bit of an education). I created a Dropbox account to share and store the HTML and PHP pages if you want to check them out (MySQL usernames and passwords modified, of course): https://www.dropbox.com/sh/vwqnbajo72x678u/luLhA77rQj I am happy with the results, but now I want to look into learning about sessions, cookies and authentication. At this point, I can go straight to my admin.php and user.php pages without logging in, a definite problem. I have checked the PHP.net website, and read other pages, but I am having difficulty following them, particularly given that my page splits between user and admin, depending on login credentials. I guess some questions I need to ask are: 1. I know that I need to start and register a session before any output, but where should I register my session? On my login page, in the HTML, or before parsing the PHP script? 2. How can I get it to terminate MySQL without showing data if a session has not been registered (experiments with sessions did show warnings that a session has not been started, but still allowed access and input of data)? If there are other things to consider, please let me know (but yes, I am aware that "mysql" functions have been deprecated in PHP in favour of "mysqli", but I had the devil of a time trying to get it to work, so I am keeping it as is at this point in time). Thank you in advanced.
  9. Problems with developing login page

    Thanks for the info. I had few things to read up on and no mistake! Things are running much smoother. I'm not so concerned about PCI compliance, though. I wanted to create my own code, mostly because I'm so out of practice. This is just a home project, I doubt I will create anything for live use anytime soon. Needless to say, though, I got things up and running. I have set up a somewhat smart username and password policy (minimum 5 characters username, minimum 6 characters password, username primary key and outputs a MySQL error for duplicates entry attempts). I'm going to call this done. Thanks for all the tips and info
  10. Problems with developing login page

    Well, I managed to solve the problem with the login page (after some trial and error, but having the PHP errors show helped as well), which is now working perfectly (admin, user and non-existent). My next issue is with user creation. I made a simple page for users to create an account, which apparently works, but it does not create the account in MySQL. I will attach the PHP and HTML scripts. Thank you again for your help. Update: Another problem which has arisen with the page is that it is proceeding like normal, even with blank fields. I tried changing things like the $go variable in my script to use boolean TRUE/FALSE values (which is what I used to fix my login page), but this did not work. adduser.zip
  11. Problems with developing login page

    Ah. That was probably me. I got it here. webdesigner93 - I'll check that out. That should be in the PHP.INI file, yes? login.zip
  12. Hi all, I am creating for myself a website (just a video listing website), and I have run into some problems. What I am trying to acheive is a website with administrative and standard user access, where admins can add and remove video titles, and users can view the titles in the list. Right now, I am working on the login portion of the website. The problem is, I have two user accounts, one admin and one user. When I enter the details for either one, it behaves as though I entered the wrong details (I will attach my HTML and PHP scripts so you can see). Entering incorrect or blank details (which should in fact generate the error message) goes to a blank page. The coding seems fine from my point of view, but I need some more expert opinions with this. Thank you in advanced.
×