PHP - Need Assistance In Php Task
EDIT: It would seem i placed this in the wrong section. Can we have a mod move this?
I'm gonna go ahead and admit that this is a task that my school left me for my course in PHP and mySQL but i won't just ask for someone to construct the code for me but just to give me advice and assistance in my code. What i'm trying to do is request a number from a user and generate random integers between 1 to 100 as many as the user specified. The task told me to place all the numbers in an array and that i can use a foreach loop to go through and indicate what numbers are lower than 50 and what is higher than 50. The output should be similar to this: All your numbers: 45 23 14 79 99 22 56 Numbers lower than 50: 45 23 14 22 Numbers higher than 50: 79 99 56 This is my code: Code: [Select] <!DOCTYPE html PUBLIC "-//w3c//DTD XHTMLm 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmnlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv"> <head> <meta http-equiv="Content-Type" content="text/html; charset="utf-8" /> <title>Task</title> </head> <body> <?php $Nummer=$_REQUEST['nummer']; for ($count=1;$count <= $Nummer; $count++){ $testSlump = rand(1, 100); echo $testSlump . "</br>"; } $testArray = array($testSlump); foreach ($testArray as $n) { if ($testArray > 50){ echo $testArray . echo 'this number is lesser than 50'; } } ?> </body> </html> I've googled, read through the litterature but none seem to help me. I thought to myself that one solution might be placing all values generated in a for loop in an array and then using the foreach loop to confirm what is what. Class notes and our schools PHP help site doesnt have anything that would help me finish this task. How do you place for loop values in an array? (if i'm on the right track) Any help etc is greatly appreciated. Similar Tutorialswanting to take a variable and use that variable to search my sql table for another variable
example : (from outside prog XXX is sent in as 'killacct')
$killacct = $_GET['killacct'];
now take 'killacct' and search table 'blahblah' for the row 'variable'
so if the table was
killacct = XXX | blahblah = YYY
so then i can pull a second variable from my first one
XXX is associated with YYY
sorry this was probably really hard to understand im very exhaused lol
hi. i want to send an email with php, but i need this email should be a task invitation in outlook. i searched at google, but i couldn't find anything that solves my problem. any ideas? thanks in advance.... Hello, I have come to a dead end. What I'm trying to do is simple: have a dynamic title for my php page (something that would be executed by, for example, Code: [Select] <title><?php echo $title; ?></title>). I'm not an experienced coder. I've tried about 15 different variations to try to achieve the result I want, and none of them have worked. I'm using a dynamic web template (DWT), which has editable regions for the Code: [Select] <title> section and for the main body of the webpage. I'm also using a Smarty template, called display_post.tpl, which, along the php file that is attached to the DWT, called display_post.php, are provided below as originally written: Smarty template: Code: [Select] <table cellpadding="8"> <tr> <td valign="top"> {section name=mysec loop=$posts} <h2>{$posts[mysec].title}</h2><br> {$posts[mysec].body|nl2br} <br> {/section} </td> </tr> </table> display_post.php: Code: [Select] <?php require_once('db_login.php'); require_once('config.php'); $conn = mysqli_connect($db_host, $db_username, $db_password, $db_database) or die ('Error connecting to MySQL'); $post_id = $_GET['post_id']; $query = "SELECT * FROM posts WHERE post_id=$post_id"; $result = mysqli_query($conn, $query); while($row = $result->fetch_array()){ $test[] = $row; } $smarty->assign('posts', $test); $smarty->display('display_post.tpl'); mysqli_close($conn); ?> Everything works as is. Part of the problem is that I don't know whether to do this through the DWT/php file or through Smarty. I've tried variations on both approaches, which I can provide for food-for-thought if need be. For now, I would love to read any possible solutions that you can come up with. Thanks bunches! Maat
Hi my name is Alexander and i am new to coding. i am in need for tommorow for this task , but i cant figure out how to make it. Can anyone explain where is my mistake and how the code should look? I have some code but its full with errors....
I have a client that has a youtube video on his page that he changes everyday. I have been wrestling with being able to allow him to login to an admin page, that returns a simple form for him to input the new video id from his youtube link which then posts to a txt file. This text file is then included in the html for to supply the correct youtube video. Basically the way it is now the html page has Code: [Select] <iframe class="youtube-player" type="text/html" width="566" height="266" src="http://www.youtube.com/embed/Video Id Here" frameborder="0"> </iframe> Now I have been completely unsuccessful just creating a form that will let him change just the "Video Id" so we have been working on copying and pasting the entire iframe code in the form. My first attempt created backslashes in the txt file where quotes are, I then added stripslashes to fwrite and that posted nothing to my txt file. So I'm not sure if the code I have is worth a spit or if I should restart with some assistance. My main goal (if achievable) is to remove the iframe code from the html page and use a php include to include the text file that has the iframe in it. Then create a page for my client to login to to paste either the video url or just the video id and have this change on the fly. Any help would greatly be appreciated! Hi there, I am working on a php project on my WAMP server where I have access to XML datafeed from xe.com once a day to get the Exchange rates. This xml datafeed is saved on my localhost as an archived copy. Now I would like to automatically access the fresh xml datafeed file from xe.com once a day and replace (or update) the xml file on my localhost to have the updated information (rates). How can I schedule this task automatically and make php access the updated xml file once a day. All comments and feedbacks are always welcomed Thank you! Hey Ok i'd say i'm pretty average with HTML, CSS and PHP I have my own website - www.leedsmethockey.co.uk and i want to develop a new section... i'll try and explain as best i can i have a database with all the players and their email address... When someone is selected for a match i wish the website to email their email address to let them know... please could someone advice me where i need to start and what sort of code i need to be looking into? Many Thanks Hi, I made a small php configuration that runs a cmd command that is designed to create a Scheduled Task on Windows. Code snippet $createTaskCmd = "schtasks.exe /CREATE /SC MONTHLY /D 15 /TN mytask /TR C:\Windows\System32\notepad.exe /ST 00:00:10 /f /RU System"; shell_exec($createTaskCmd); keep in mind I also tried using, 'exec' and I also tried out this solution. I'm trying to create a temporary task and have it be destroyed much later. I am using JWT for an API authentication and like them. Previously, I would query both some GUID and the user's ID (which wasn't their PK but a unique key per GUID), but now I just include both the account and user's DB PK in the token. Also, including something regarding the user's permissions, however, I still haven't bought into this approach as I don't know how to deal with changing permissions and still having some JWT with different permissions floating around. I suppose I could save the JWT's timestamp in the DB, but that seems to eliminate the benefit of token expirations... Sorry, back to the question at hand. I now have a need to provide emails with a reduced subset of endpoints to either view some resource or update some status. I don't want to make the user first go to some website and then include the JWT in the header, but instead just a single click action. Problem is now I have their JWT which is effectively their password in some email which isn't ideal, and their is no way to ensure that the specific user was the individual that viewed the resource or performed some action. Then I thought maybe I would make some common low access JWT and use the exact same GET routes as I would do so normally and create some new GET routes to emulate main application POST/PUT/PATCH routes. Before going down that path, I would like to investigate other solutions. Often single use tokens are used to reset passwords and other actions which should only performed once and this is not my need but maybe close. I am thinking of creating a token that includes the actual resource path with URL parameters along with the HTTP method. Since everything is in the token, I wouldn't need a typical REST path to identify the resource but would have a single endpoint to retrieve them. I searched for related information and didn't find anything which makes me concerned I am going down a rabbit hole. Any thoughts on how to implement this? Thanks if($_GET['task']=='del') { $id=$_GET['id']; $name=$_GET['new_image']; mysql_query('delete from tbl_gallery where id="'.$id.'"' ); unlink ($name); } Ok this should be straight forward but my tired brain cannot work this out. I'm creating a simple contact form and for some reason the validation isn't working. It wont go past the check fields are filled in validation. Can anyone spot what I'm doing wrong? Code: [Select] <form method="get"> <h1 class='contact_form_h'>Contact Us</h1> <div id="login_response"></div> <input type='text' name='name' id='name' class='contact_form_input' value='Name' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" /> <input type='text' name='email' id='email' class='contact_form_input' value='Email' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" /> <textarea name='enquiry' id='enquiry' class='contact_form_textarea' rows='10' cols='10' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">Enquiry</textarea> <input type='submit' name='contact' id='contact' class='contact_form_submit' value='Contact Us' /> </form> Code: [Select] <?php //Check if form is submitted if(isset($_GET['contact'])) { //Require check email function require "check_email.php"; //Variables $err_name=stripslashes($_GET['name']); $err_email=stripslashes($_GET['email']); $err_enquiry=stripslashes($_GET['enquiry']); $to="xxx@xxxx.com"; $subject="Website Contact Form"; $from = stripslashes($_GET['name'])."<".stripslashes($_GET['email']).">"; $message = $err_enquiry; $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; //Check all form fields are filled in if ($_GET["name"]!='' OR $_GET["name"]!='Name' OR $_GET["email"]!='' OR $_GET["email"]!='Email' ) { if (isValidEmail($_GET['email'])){ //Send Mail if (@mail($to, $subject, $message, $headers)) { echo "3 - sent"; } else{ echo "2 - not"; } } else { echo "1 - not valid"; } } else { echo"0 - Fill in"; } } ?> Below is the check email script. Code: [Select] <?php // This function tests whether the email address is valid function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } } ?> Can someone help me out with making a bat file. I cant find a good set of directions on google. I have window scheduler all working in running but it runs my script in note pad and not IE like I need it too. I also read something about php cgi file for doing this same thing but cant make heads of tails out of it from reading about it in the manual. Trying to run this http://localhost/gate/users/update.php This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=313115.0 This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=346879.0 Hi guys, For a project I made sort of a custom cron database. Database has 4 columns: ID (auto increment), TaskID, DateTime, Locked. I'm running a 1 minute cron in the form of a php script. The script itself starts with a query that loads a task with 'Locked != 'Y' and DateTime < NOW( ). It then locks the task (by flagging the 'Locked' field in the db) and launches another script that finishes it. That last script deletes the task when finished from the cron database. Problem is, at certain peek hours, the system would get laggy, there'd be a bunch of tasks stacking up and it would get behind on the schedule. In order to combat that, I made an extra 1 minute cron, launching the same script. Now, my problem: mysql is too slow In principle, there shouldn't be any problem: all tasks picked up by either instance of the script would be locked so the other instance wouldn't be able to pick up the same task. The problem occurs when both instances are booted at the same time (well, one after the other but with a minuscule time difference between them) and they both at the same time run the query to get a 'free' task from the database: the system will give them both the same task before either of the script instances has the time to lock it up. I'm trying to think of some solutions but I'd like your feedback on what solution would be best. - Putting an exclusive lock on the php file is not an option for me since I still want to run the script, I just need it to pick up an exclusive task. - Other option: having the script open with a random sleep of (1, 10) seconds, it will have the script instances pick up a task at a different time, giving the other instance time to lock it up. Obvious disadvantage: I'm losing time. - Using a file as a flag. Set a directory and create a file in it. Check if this is the only file in the dir, if yes: start right away. Otherwise: go to sleep for 2 seconds (should be plenty of time to run 2 queries in the other instance). What is the fastest method of doing a directory scan though, glob()? My question: what's the fastest/best way to solve this? Thanks! I have a PHP file that does some data processing work in the database and I run in from a web browser each weekend. The PHP file usually completes the job in 4 hours, but past 2 weekends, it failed to complete. Then, i need to reexecute the file. Why? And how to fix this? ok... I'm still struggling with PHP syntax, my editor's linting keeps flagging a line as incorrect. it's supposed to read as " when d1 minus 1 is less than or equal to d2 with d2 being less than or equal to d1 plus 1" so in other words its supposed to be true if d2 is between d1 minus 1 and d1 plus 1, inclusive. I don't want d2 being the previous number, the same number or the next number relative to d1. The same goes for d3, d4, and d5 (4 and 5 are un coded because why code in errors).
That being said... This isn't exactly my correct goal but I'm not sure how to code what I really want... I can't seem to find a good way to test this without the commands I know from other languages like CountIf, Iffn and RandSamp. (those are Ti-Basic commands) I know "please do it for me" is frowned upon, and hate saying it (I'd rather learn to do it myself), but if anyone can explain how to do this I'd really appreciate it. Edited March 23, 2019 by Karaethon I have an array here that looks like this: Code: [Select] Array ( [server_info] => Array ( [up] => 1 [up_since] => Sun, 23 Oct 2011 04:04:01 -0600 [up_for] => 2588 [version] => Beta 1.9 Prerelease 4 ) [players] => Array ( [0] => Pyr3x ) [server_settings] => Array ( [map] => Underworld [pvp] => 1 [pve] => 1 [max] => 50 ) [admins] => [ops] => Array ( ) ) How would I for example print the contents of the players array without having to be specific on which object within it that I wish to print, it's dynamic so it's always going to change. Example of the output I'd like is: Players: Pyr3x, SomeGuy, AnotherGuy Thank you for any help you may be able to provide. -Pyr3x Hey all, I'm currently working on a website/database system. What i'm trying to achieve atm is for a user to be able to edit current data in a database table, submit it, and for it to display the new data in the webpage. The table i'm reading from has 6 records and the fields ID(which is just auto_incremented) and courseName. Ideally, I would like the user to be able to delete a record too. The code I have written displays the courseName's in a table along with textareas and a submit button for each row. It seems to be doing nothing at the minute, so I was hoping someone could enlighten me as to what I've done wrong and if someone could provide what code i'm missing if any, i would be ever so grateful I think I might have structured it all wrong, I hope this isn't the case! My current code is below, hope to hear some feedback soon, many thanks, Aaron PS: feel free to ask any more question in case I've forgot to mention something Code: [Select] <?php session_start(); $hostname_logon = "***.*.*.*" ; $database_logon = "aal9" ; $username_logon = "root" ; $password_logon = "" ; $coursenametext = ''; $id = ''; //error_reporting (E_ALL ^ E_NOTICE); $connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unable to connect to the database" ); mysql_select_db($database_logon) or die ( "Unable to select database!" ); ?> <!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>Edit Courses</title> <link href="Aaron.css" rel="stylesheet" type="text/css" /> </head> <div class="container"> <h1><img src="logo.gif" alt="Logo" width="224" height="62" id="logo" align="left"/></a>Update Courses</h1> </div> <div class="sidebar1"> <ul class="nav"> <li><a href="homepage.php">Homepage</a></li> <li><a href="modules.php">My Modules</a></li> <li><a href="update.php">Update Database</a></li> <li><a href="googles1.php">Sem 1 Google</a></li> <li><a href="timetable2.php">Sem 2 Timetable</a></li> <li><a href="googles2.php">Sem 2 Google</a></li> <li><a href="logout.php">Logout</a></li> </ul> <p><a href="javascript:window.print()">Print This Page</a></p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. </p> <p>Welcome To Timetable Management. Please Find All Necessary Links Above.</p> </div> <div class="content"> <form action="editcourses.php" method="post"> <table border="1" cellspacing="1" align="center" bordercolor="#FFFFFF"> <tr> <td>Course Name</td> <td>Edit</td> <td>Submit</td> <td>Delete</td> </tr> <?php $query = "SELECT * FROM Courses "; $result = mysql_query ($query); if(mysql_num_rows($result)>0){ while($row = mysql_fetch_array($result)) { echo('<tr>' . '<td>' . $row['CourseName'] . '</td>' . '<td><input type="hidden" name="id" value="' . $row['ID'] . '"/><textarea name="coursenametext" rows="2"></textarea>' . '</td>' . '<td>' . '<input type="Submit" name="Submit" value="Submit">' . '</td>' . '</tr>'); } } if(isset($_POST['Submit'])) { $query1 = "UPDATE courses SET courseName = '".$_POST['coursenametext']."' WHERE ID = '".$_POST['id']."'"; $result1 = mysql_query ($query1); } ?> </table> </form> <br> </div> <div class="footer"> <p><a href="mailto:***@**.**.**" class="Email">Click Here To Email For Help With Faults</a></p> </div> </div> </body> </html> I have a html/php i am creating but getting the following error:
[10-May-2019 09:42:13 UTC] PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php:88
<?php $server = htmlentities($_SERVER['PHP_SELF']); if (isset($_POST['submit'])) { $result = create_eng(); } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Add A New Engineer | DDS Dashboard</title> <meta charset="utf-8" /> <link rel="icon" type="image/png" href="../images/favicon-16x16.png"/> </head> <body> <?php include('nav.php'); include('ConnectionDB.php'); ?> <div class="jumbotron"> <div class="container"> <h1><br><img src="../images/clipboard-customer.png"/> Add New Engineer:</br></h1> </div> </div> <form class="form-horizontal" role="form" id="add_eng" action="<?php $server ?>" method = "post"> <div class="form-group"> <!--<?php //display_msg($msg);?>--> <label for="EngineerName" class="col-sm-2 control-label">Engineer Name:</label> <div class="col-sm-6"> <input type="text" class="form-control" id="EngName" name="EngineersName" placeholder="Enter Engineer's Name"></input> <small class="form-text text-muted"> Enter the new engineer's name above to enter them into the database. </small> </div> <input name="submit" type="submit" value="Create Engineer" class="btn btn-primary default"></input> <input name="reset" type="Reset" value="Reset Form" class="btn btn-primary default"></input> </div> </form> <br><br> </body> </html> <?php $sql = "Select * from [Engineers] where [Engineer] not like '%\_%' Escape '\' order by [Engineer] asc"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="containerenglist"> <div class="col-sm-5"> <table id="alleng" class="table table-bordered"> <tr> <th>Active Engineer's Names:</th> </tr> <?php foreach ($results as $row) { echo "<tr><td>"; echo $row['Engineer']; echo "</td>"; echo "</tr>"; } ?> </table> </div> </div> </body> </html> <?php Function create_eng(){ global $msgID; global $msg, $conn; include('ConnectionDB.php'); $conn = null; $msgID = 0; //Get POST from submit $eng_name = $_POST['EngineersName']; //SQL Query $sql_count = "select count(*) as num from [Engineers] where [Engineer] = :eng_name"; //Query SQL Statement //echo $eng_name; $stmt = $conn->prepare($sql_count); $stmt->bindValue(':eng_name', $eng_name); //Execute SQL Statement $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); If($results['num'] > 0){ echo $msg = "Engineer $eng_name exist's in the database"; $msgID = 1; }else{ $sql_insert = "insert into [Engineers](Engineer) values '$eng_name'"; //Prepare SQL Statement $stmt = $conn->Prepare($sql_insert); //Execute SQL Statement $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); echo $msg = "Engineer $eng_name added to the database"; $msgID = 2; } } ?> Everything works correctly until i try submitting a name to the DB the line that is being pulled is $stmt = $conn->prepare($sql_count);
|