PHP - Help Need Simple Noob Code For School Project
Hi guys and girls im a new guy on this forums and im here to beg for a favor, for my school assignment i have to make a simple php script and i have no idea how to do that so, here i am what i need is basically a video store rental application that store staff would use. Nothing fancy just that it works. We also got sakila-db to work with and use witch is 30% of my problem if a got to make my own db i would not be quite as confused right now. Can any1 help me because im starting to panic.
i apologize if i posted in the wrong place. im including small dijagram of how this thing is supposed to look any help would be appreciated. [attachment deleted by admin] Similar TutorialsExperienced, skilled and perfectionist coded needed for a small, minimal application.
Skills
- Skilled using raw PHP (no framework), utilising PHP5, in OOP structure
- Experienced designing optimised and clean MYSQL schemas
- Concious of both performance and security
- Understanding of Jquery
Perfered
- Knowledge of stripe
- Knowledge of sending emails with third party (SMTP etc)
- Basic HTML / CSS
Personal Qualitied
- Perfectionist
- Enjoys writing clean, clear and efficient code
Edited by jameswillson, 03 September 2014 - 08:47 AM. Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> There is only one thing I want to know. How to I fill out a text box, click submit and make that information go to a msql database? This is very simple but I am very new to php. This is all I want to learn. Also showing the value on a table after I submitted would be great. Thanks and I hope someone can help. Hey all, I've been programming with php for about 3 months now and am still out to lunch on a lot of it. I was hoping someone could help me clear up a problem I'm having with my script. It's a simple script that takes a user selection from the previous page ($StarterPackGroup) and executes a list of randomized functions based on the users selection. (There are 4 races to choose from, here's the url to the page that provides the info for $StarterPackGroup for my script. http://www.eardrumvalley.com/backdoor/MINI_TACTICS/Starter_Pack.php Once the user has selected one of 4 races, it takes them to this php script and rolls for their first "pack". I currently only have the "aqua elves" responding, so click on them. Now, I have the page setup so it generates random numbers, and I know the numbers ARE generating, because I see them with an echo command (you will too, they are at the top of the page). However, the problem I'm having, is trying to utilize these random generated numbers in my other functions. ie: I create $UncommonUnit[$i], $CommonUnit[$i], $RareUnit[$i] and $MonsterUnit in the NewStarterPackRoll function.... however, i can't seem to utilize them in my other functions. How do I pass this info to another function? The echo returns the random numbers from $CommonUnit, $UncommonUnit, $RareUnit and $MonsterUnit just fine WITHIN the StarterPackRoll function, but not later on in the AquaElfStarterPack function. Anytime I try to echo the return value of these holders, I get a blank value... I also know the value isn't being passed between functions because none of my if statements are working either. All the units receive a default allocation (Trooper, Hero, Champion, Skel Sprite), if the randomized numbers were passing, these would be giving me other values as well. Please help, I'm convinced there's a simple answer, and I'm just an idiot when it comes to PHP. Lend me a hand! CODING INFO ----------------- THE DATE ENTREE SCREEN - "http://www.eardrumvalley.com/backdoor/MINI_TACTICS/Starter_Pack.php" (BE SURE TO PICK AQUA ELVES, THEY ARE THE ONLY RACE THAT SENDS VALUES) This will bring you to the script page after you submit the selection: THE SCRIPT CODE ON "Open_First_Pack.php" after the data is sent is as follows: (please browse to webpages to see results of code). <?php function RaceCheck($StarterPackGroup) { if ($StarterPackGroup=="AquaElves") { AquaElfStarterPack(); } } function NewStarterPackRoll() { $i = 0; while ($i < 9) { $i = $i + 1; $CommonUnit[$i] = rand(1, 100); echo "" . $CommonUnit[$i] . " "; } $i = 0; while ($i < 4) { $i = $i + 1; $UncommonUnit[$i] = rand(1, 100); } $i = 0; while ($i < 2) { $i = $i + 1; $RareUnit[$i] = rand(1, 100); } $MonsterUnit = rand(1, 100); } function AquaElfStarterPack() { $i=0; echo "<p><b>Commons:</b><br>"; while ($i < 9) { $i=$i + 1; if ($CommonUnit[$i] <= 20) { $OpenedCommon[$i] = "Trooper"; } else if ($CommonUnit[$i] <= 40) { $OpenedCommon[$i] = "Bowman"; } else if ($CommonUnit[$i] <= 65) { $OpenedCommon[$i] = "Sentinal"; } else if ($CommonUnit[$i] <= 80) { $OpenedCommon[$i] = "Horseman"; } else if ($CommonUnit[$i] <= 100) { $OpenedCommon[$i] = "Evoker"; } echo "" . $CommonUnit[$i] . " "; echo "" . $OpenedCommon[$i] . "<br>"; } echo "</p><p><b>Uncommons:</b><br>"; $i=0; while ($i < 4) { $i=$i + 1; if ($UncommonUnit[$i] <= 20) { $OpenedUncommon[$i] = "Hero"; } else if ($UncommonUnit[$i] <= 40) { $OpenedUncommon[$i] = "Archer"; } else if ($UncommonUnit[$i] <= 65) { $OpenedUncommon[$i] = "Courier"; } else if ($UncommonUnit[$i] <= 85) { $OpenedUncommon[$i] = "Knight"; } else if ($UncommonUnit[$i] <= 100) { $OpenedUncommon[$i] = "Conjurer"; } echo "" . $UncommonUnit[$i] . " "; echo "" . $OpenedUncommon[$i] . "<br>"; } echo "</p><p><b>Rares:</b><br>"; $i=0; while ($i < 2) { $i=$i + 1; if ($RareUnit[$i] <= 15) { $OpenedRare[$i] = "Champion"; } else if ($RareUnit[$i] <= 35) { $OpenedRare[$i] = "Sharp Shooter"; } else if ($RareUnit[$i] <= 55) { $OpenedRare[$i] = "Herald"; } else if ($RareUnit[$i] <= 80) { $OpenedRare[$i] = "Eagle Knight"; } else if ($RareUnit[$i] <= 100) { $OpenedRare[$i] = "Enchanter"; } echo "" . $RareUnit[$i] . " "; echo "" . $OpenedRare[$i] . "<br>"; } echo "</p><p><b>Monster:</b><br>"; if ($MonsterUnit <= 25) { $OpenedMonster = "Skeleton Sprite"; } else if ($MonsterUnit <= 45) { $OpenedMonster = "Tako"; } else if ($MonsterUnit <= 75) { $OpenedMonster = "Coral Giant"; } else if ($MonsterUnit <= 100) { $OpenedMonster = "Gryphon"; } echo "" . $MonsterUnit . " "; echo "" . $OpenedMonster . "</p>"; } NewStarterPackRoll(); RaceCheck($_REQUEST['StarterPackGroup']); ?> <td> <button onclick="alertdialog()"><span class="glyphicon glyphicon-trash"> </span></button></td> <script> function alertdialog(){ window.confirm("Are you sure you want to delete this post?"); } </script> This is my code. I need to have a callback to a PHP script when a user decides to delete a post. I think html POST is the most unobtrustive way to do this. What's the easiest / most robust way to send data to a script when the user clicks OK? Appreciated. Mark I'm trying to figure out how I can reduce as much functionality as possible and still keep it doing what it needs to do. What I mean by functionality is the number of queries being performed or any of the other code for that matter. I do show at the bottom of my post what I have so far, however that doesn't cover all the queries. Code: [Select] <?php if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id FROM characters"; $result = mysqli_query ($dbc,$query); $total_num_characters = mysqli_num_rows($result); $query = "SELECT user_characters.id FROM user_characters INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id"; } else { $query = "SELECT user_characters.id FROM user_characters INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."'"; } $result = mysqli_query($dbc,$query); echo $num_available_characters = mysqli_num_rows($result); if (($num_available_characters > "1") || (($access_level_id == 2 || $access_level_id == 3) && (isset($total_num_characters)) && ($total_num_characters > "0"))) { ?> <form method="POST" id="change_default_character"> <select class="dropdown" name="new_default_character_id" id="new_default_character_id" title="Select Character"> <?php if ($default_character_id > "0") { print "<option value=".$default_character_id.">".$default_character_name; } else { print "<option value=0>- Select -"; } if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id, characters.character_name FROM characters WHERE characters.id <> '".$default_character_id."' AND characters.status_id = '1' ORDER BY characters.character_name"; } else { $query = "SELECT characters.id, characters.character_name FROM characters INNER JOIN user_characters ON characters.id = user_characters.character_id INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."' AND user_characters.character_id <> '".$default_character_id."' AND characters.status_id = '1' ORDER BY characters.character_name"; } $result = mysqli_query ($dbc,$query); $num_rows = mysqli_num_rows ($result); if ($num_rows > 0) { if ($access_level_id == 2 || $access_level_id == 3) { print "<optgroup label=\"** Active Characters **\">"; } while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character_name']."</option>\r"; } } if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id, characters.character_name FROM characters WHERE characters.id <> '".$default_character_id."' AND characters.status_id = '2' ORDER BY characters.character_name"; } else { $query = "SELECT characters.id, characters.character_name FROM characters LEFT JOIN user_characters ON characters.id = user_characters.character_id LEFT JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."' AND user_characters.character_id <> '".$default_character_id."' AND characters.status_id = '2' ORDER BY characters.character_name"; } $result = mysqli_query ($dbc,$query); $num_nows = mysqli_num_rows($result); if ($num_rows > "0") { print "<optgroup label=\"** Inactive Characters **\">"; while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character_name']."</option>\r"; } } ?> </select> </form> <?php } else { print "<h1>".$default_character_name."</h1>\n"; } ?> Code: [Select] <?php /** * Get roster list * * @return object/NULL */ function getRosterList() { $this->db->from('rosterList'); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; } /** * Get list of roster by user ID * * @return object/NULL */ function getRosterByUserID() { $this->db->from('rosterList'); $this->db->where('userID', $userID); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; } ?> I hope no one rolls their eyes at me, lol, but I literally, just made my first PHP script, but I ran into a snag.
Okay so the code I did was
<!DOCTYPE html> <html> <body> <?php echo <h1>"my First PHP script"</h1>; ?> </body> </html> but in firefox the outcome is always "my first PHP script?> I had added the h1 tags because it wouldn't print at all before I did. I'm trying to figure out what I did wrong. Short of deleting, how do I comment out code like this : <!-- IF not S_DISPLAY_RECENT --> <!-- INCLUDE portal/block/recent.html --> <!-- ENDIF --> Nesting <!-- --> /*...*/ // do not work. Thanks Hi, I'm trying to fetch rows of data from a mysqli table and display them in the browser in categories. I have the while loop working fine, but I want to break the results down into categories, instead of one big list sorted by a field using ORDER BY. So for example, let's say I have a database table containing people's names, email address, phone numbers, etc. and I want to display them in the browser in separate tables by the city in which they live (each city name would be a h1 or h2 tag) and the appropriate rows would be displayed under each heading, sorted by the person's name. I can do it by using multiple while loops, separating each city into it's own array and then repeating my html table code a bunch of times, but I know there has to be a much cleaner way. Can anyone point me in the right direction? Thanks! Hello,
I want to create and display school time table like
timetable.jpg 45.66KB
2 downloads
I have created my database like this
CREATE TABLE IF NOT EXISTS `time_table` ( `id` int(10) NOT NULL AUTO_INCREMENT, `class` varchar(20) NOT NULL, `section` varchar(10) NOT NULL, `subject` varchar(20) NOT NULL, `teacher` varchar(30) NOT NULL, `monday` varchar(10) NOT NULL, `tuesday` varchar(10) NOT NULL, `wednsday` varchar(10) NOT NULL, `thursday` varchar(10) NOT NULL, `friday` varchar(10) NOT NULL, `saturday` varchar(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;Columns' Monday', 'Tuesday' will store starting hour of a period But i don't know how to display it as above format. I even do not know whether i am using proper format of table. Somebody please suggest me how can i create this time table My school is running PHP 4.3.2 on its network, and I'm running PHP 5.3.1 on my localhost machine using Xampp/Apache. My login system works perfectly at school, however $_SESSION["LoggedIn"] does not register, recognise nor acknowledge on my home system. It's not the script itself as I've copied the files across, so in theory it should work exactly the same? I've compared phpinfo()'s and within the session category all values are the same. The database/MySQL works fine on both networks so it's not a problem to do with this. Any ideas? Thanks. Hello house, I am new to coding, I have a project about generating school terminal results and using pin to check results in codeigniter framework. Any help will be appreciated. Thanks
Hello, I'm a cs student (2nd year) this year has been a disaster for us the students(studying over zoom and shit), I have a tiny tiny project that a have to finish in the next 24 hours, we made a small sample website using html and js, and now we need to switch it to php language and make the site responsive and later on add SQL. I would very much appreciate if someone can help me for couple of minutes over zoom and help me complete it. All I have left is echo the products from an array with a loop and make a php table that will put my items to my cart. It's my first time here..hope there is some good people here Edited July 21, 2020 by requinixadded thread title Hi, this is my first time posting here. I am just delving into PHP and I am learning about foreach loops. I have written code in Notepad++ EXACTLY the way I saw it in a tutorial video I watched (I wish I could show the tutorial video to you, but it is on Lynda.com and you have to pay to watch) I attached the file with my code. The example 1 code works just fine. The example 2 code is the one that is not working for some reason. However, it worked for the guy that wrote it in the video, so I am not sure where I am going wrong? *The comments in green are mainly for myself, I explain things to myself so that I don't forget what the code does forloops.php 1.74KB 2 downloads I would appreciate some help. Thank you!!! err, dunno if i managed to put it in the right thread but if i didn't, please tell me. thank you.
getting back on topic, my father asked me to create a website for a school. i know how to make a website but the problem is, how do i start? should i ask about their objectives or something? color of the webpage etc? in short, i don't know the practicalities and processes used in making a website for a certain client. you could say this would be my first time in doing this (kind of like an on-the-job training) so...any ideas? i would very much appreciate any help given.
Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you.
Hello I do not know anything about php this is the code <?php echo do_shortcode( “[covid19 country=‘Pakistan’ title=‘Pakistan’]” ); echo do_shortcode( “[covid19 country=‘India’ title=‘India’]” ); echo do_shortcode( “[covid19]” ); ?>
can anyone help me to center the numbers of cases death recovered:
Hi!
I'm new to php so, please forgive if this is a really simple question or if it doesn't make sense.
I have an www.domain.com web site and then I have an microprocessor at home connected to the internet also hosting and simple page. That page is acessible from the internet.
When I'm browising on my www.domain.com i want to add an botton that sends an request to the microprocessor, right now what i do is when the button is clicked, it opens the microprocessor page like : microprocessor.ddns.net/?update=1.
How can i make the www.domain.com send the "?update=1" to the microprocessor without the user have to see the microprocessor page.
The main purpose is to hide the microprocessor address so it's harder to be hacked..
Thanks for the help!
Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this... if grade_type >=100 $final_grade = A Idk, im new to php and need help doing this... here is my code... Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_points']); $statement->execute(); $statement->closeCursor(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> <input type="submit" name="update" value="Update" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> Code: [Select] <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'grade has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $update_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html> |