PHP - Homework Debug
I need help debugging some homework.I have narrowed the problem down to the switch. when it gets to the switch it is spitting out the default everytime, also in the default the $score in both echo statment is not showing. Its probably something small killing me I just can't see it and dont have enough experience with php yet.
<body> <?php $faceNamesSingular = array("one", "two", "three", "four", "five", "six"); $faceNamesPlural = array("ones", "twos", "threes", "fours", "fives", "sixes"); function checkForDoubles($die1, $die2) { global $faceNamesSingular; global $faceNamesPlural; $returnValue = false; if ($die1 == $die2) { //Doubles echo "The roll was double ", $faceNamesPlural[$die1-1], ".<br />"; $returnValue = true; } else { // Not Doubles echo "The roll was a ", $faceNamesSingular[$die1-1], " and a ", $faceNamesSingular[$die2-1], ".<br />"; $returnValue = false; } return $returnValue; } function displayScoreText($scores, $doubles) { switch ($score) { case 2: echo "You rolled snake eyes!<br />"; break; case 3: echo "You rolled a loose deuce!<br />"; break; case 5: echo "You rolled a fever five!<br />"; break; case 7: echo "You rolled a natural!<br />"; break; case 9: echo "You rolled a nina!<br />"; break; case 11: echo "You rolled a yo!<br />"; break; case 12: echo "You rolled boxcars!<br />"; break; default: if ($score % 2 == 0) {//any even number if ($doubles) { echo "You rolled a hard $score!<br />"; } else { //Not Doubles echo "You rolled an easy $score!<br />"; } } break; } } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $score = $dice[0] + $dice[1]; echo "<p>"; echo "The total score for the roll was $score.<br />"; $doubles = checkForDoubles($dice[0], $dice[1]); displayScoreText($score, $doubles); echo "</p>"; ?> </body> </html>Attached Files DiceRoll.php 1.94KB 0 downloads Similar TutorialsI got stuck with one question of my php homework. Hope u guys can help and advise the step by step codings. About the subject, There is no PHP that can be selected in Course Hero
please see below question
Question 1:
Following is the implementation of date time function in php:
<?php $dateString = date("Y/m/d h:i:s"); //current date with format echo "Today is $dateString<br>"; //mktime(hour,minute,second,month,day,year) $mydate = mktime(13, 34, 46, 12, 24, 2017); $dateString = date("Y/m/d h:i:sa", $mydate); echo "My Date is $dateString<br>"; $errordate = mktime(25,25,-1,15,32,1900); $dateString = date("Y/m/d h:i:sa", $errordate); echo "Error Date is $dateString<br>"; ?>
To get simple date, you have one of the parameters format in date(). Few characters need to be specified within the parameter.
'd' for the day of month (1-31) 'm' for month number (1-12) 'y' stands for year(it should be 4 digit) 'h' shows 12 hour format (01 - 12) 'I' shows minutes with zeroes(00-59) 's' denotes seconds (00-59) 'a' denotes am or pm.
The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date.
The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.
Without the parameter, mktime() will return the current timestamp of your server.
However, you will find that there will have an error on display the date or time if users pass some value which do not follow the rule of date and time, e.g. month is 13.
You are required to write new function with name validDate($month, $day, $year) which will return an error message "Invalid parameter(s) for the date!" if passing an invalid parameters to this function. If no error found, return the date in string with "Y/m/d" format.
Example codes:
<?php $dateString = validDate(13,32,1969); echo "My Date is $dateString<br>"; $dateString = validDate(12,31,2018); echo "My Date is $dateString<br>"; ... ?> Hi, Trying to build a simple homework manager for the school I am Head of ICT in, using PHP and MySQL. Currently at the design stage - so no code to share yet. But I will share with you how I intend to get it working, and the issue I have... I anticipate having 5 tables Table 1 Student_ID | Student_name Table 2 Class_ID | Teacher_name Table 3 Student_ID | Class_ID Table 4 Class_ID | Class_name Table 5 Class_ID | Activity | Date_set | Date_due | Visible So, at its simplest it should be possible to select from the database all classes that match your student_id and show the homework set for those. Also, I have a visible tag set so that teachers can pseudo delete homeworks using a small control panel. But what I would like to do, is allow the students to set whether or not they have done the homework (kind of like a task in remember the milk) - but obvioulsy they cant have access to the database. Anyone got any idea how this could be achieved? Here is my hierarchy: data -logs folder-debug.log htdocs -index.php include -Contollers,Smarty,Templater,Zend templates Now when I launch index.php from htdocs, I get this un-seeming error: "Fatal error: Uncaught exception 'Zend_Log_Exception' with message '"/var/htdocs/Books/practical_Web2.0/data/logs/debug.log" cannot be opened with mode "a"' in C:\xampp\php\PEAR\Zend\Log\Writer\Stream.php:69 Stack trace: #0 C:\xampp\htdocs\Books\practical_Web2.0\chapter-02\htdocs\index.php(11): Zend_Log_Writer_Stream->__construct('/var/htdocs/Boo...') #1 {main} thrown in C:\xampp\php\PEAR\Zend\Log\Writer\Stream.php on line 69 " I went to the zend folder in xampp, php, pear, zend, log, writer.php dir and I found this: /** * Class Constructor * * @param streamOrUrl Stream or URL to open as a stream * @param mode Mode, only applicable if a URL is given */ public function __construct($streamOrUrl, $mode = 'a') { if (is_resource($streamOrUrl)) { if (get_resource_type($streamOrUrl) != 'stream') { require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Resource is not a stream'); } if ($mode != 'a') { require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Mode cannot be changed on existing streams'); } $this->_stream = $streamOrUrl; } else { if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) { require_once 'Zend/Log/Exception.php'; $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\""; throw new Zend_Log_Exception($msg); } } $this->_formatter = new Zend_Log_Formatter_Simple(); } line 69 is =>throw new Zend_Log_Exception($msg); What could be wrong? Hint: settings.conf [development] database.type = pdo_mysql database.hostname = localhost database.username = root database.password = database.database = phpweb20 paths.base = /var/htdocs/Books/practical_Web2.0 paths.data = /var/htdocs/Books/practical_Web2.0/data paths.templates = /var/htdocs/Books/practical_Web2.0/templates logging.file = /var/htdocs/Books/practical_Web2.0/data/logs/debug.log Any pointer as to why there is a fatal error? I don't know how to debug this. The if is being executed and I want to have the else be executed. How can I find out what $_POST['id'] is? Code: [Select] if (isset($_POST['id']) === false) { echo 'Invalid user id.'; } else { partner_request($_POST['id']); echo "A request has been sent to the user"; } Hi all, Well new to the forum. And New to PHP. I have a quick question. I'm trying to figure out what the best pratice would be to get familier with a php installation. More specificly how to discover what php is specificly producing a specific part of the final rendered HTML. I have a MyBB Forum me and my cuzin are setting up and for the life of me i can find the right place to add our own HTML to change a specific Div in the Final page output. here is the link to our URL http://destroyrebuilduntilgodshows.net/forum/ I specificly want to find out where i can edit the contents of the "wrapper_container" Div. I have searched for the source on my local machine. but all i can find is the CSS responsible for the styling and as it turns out the images being held in that div. My end goal is to replace the "advertise here" image with come JS that does our ad managment. So, I guess my question is How would you find it. How would you find the responsible php for that section of the HTML. Thanks All. Cheers I have a simple INSERT statement that isn't inserting anything into one of the columns: coin_name I've gone over everything and can't figure out why. All other columns get data. HTML form passes everything fine. Is there a good way to debug this? I've triple checked everything and there are no type-o's that I see. Driving me mad... $query = "INSERT INTO Coin (coin_name, coin_value, coin_condition, year_minted, face_value, purchase_price) VALUES ('$coin_name', '$coin_value', '$coin_condition', '$year_minted', '$face_value', '$purchase_price');"; I am new to PHP and trying to debug some old code. How am I to read the following: $properties = $GLOBALS['Props']; I am guesisin that it is saying: Create a string variable named $porperties and set it equal to the Global variable of 'Props'. But I assume my interpretation is wrong since I get some weird results. I'm stuck trying to figure out why when I make a selection in drop down list of a php form, the selection does not stay when form is refreshed or re-displayed due to an pattern error of another field. My array is state_province = array(list of the states, and provinces) field name in the label array is: "state" => "State", Here is the code that I'm using: echo "<form action='$_SERVER[PHP_SELF]' method='POST'>"; foreach($labels as $field => $label) { if($field == "state") { echo "<div class='province_state'><label for='state' size='15'>* Province/State</label><select>"; foreach($state_province as $state) { echo "<option value=$state"; if(@$_POST['state'] == $state) { echo "selected='selected'"; } echo ">"; echo $state; echo "</option>\n"; } echo "</select></div>\n"; } I'm trying to debug a sporadic 500 error which users occasionally get when filling out form sections on my site. Whenever it happens, I try to recreate their environment and fill out the form exactly as they have done, but can never recreate the issue. I have checked my application logs for the framework I am using, but they report nothing related to the error. I'm hoping someone here might be able to help me catch this. This is where the 500 error is sometimes happening and this triggers the error which users report: Code: [Select] //In jquery AJAX function, which submits data to PHP form for processing error: function(data,transport){ $.validationEngine.debug("error in ajax response: "+data.status+" "+transport) } Is there a way for me to try and catch what the exact error is here? The problem is I can't recreate the error, either using an AJAX call or not to call the PHP script. I need to catch the error response from the PHP script being called, but I never get an error when trying to recreate the user issue, i.e same OS/browser/form answers. The Apache error logs for the site have very little - unless I'm looking in the wrong place. I'm on CentOS, ran locate error_log and got an error_log.txt file in my vhosts directory for my site, but this just contained a 302 message log, nothing else. I also tried locate error | grep mysite. I need some advice on how to debug in the middle of other code I want to change a file. This file gives no direct output and contain a load of functions What I want to do is make changes to this file and trace values - how do I do this? - Can I give a popup with a message? - Could I write values to a file? (Can I write to some sort of standard log file? Maybe the error log file?) - Or is it possible to still give output to a web page, even though the code is not part of the code that outputs to the browser? What's the standard practice of debugging as mentioned above? Any help would be really appreciated Thanks! OM Hi, I've inherited a website with a problem! Basically the site runs pommo mailing list, which has worked fine for years. Recently though the website domain name changed. Since then - or at least at a similar time - pommo has just stopped working completely. It does nothing but outputs blank pages. I've never done any php development so I've no idea where to start in terms of debugging this. I've checked that the files etc all exist on the server: they do. I've uploaded a test html page which works. I've uploaded a test php page containing: <?php phpinfo( ); ?> and it works. But when I visit any page in the pommo application, the browser just renders a totally empty white page - no source HTML at all, just nothing! Can anyone suggest how to debug this? Even an error message would be somewhere to start. Thanks all! So I have been printing out some debug information, and now I am trying to instead save it to a string, which I will print out at the end of the page. Here is some specific problematic code: $myplugin_debug_test.= "\n[GETTING COOKIES...\n"; $myplugin_debug_test.= print_r($myplugin_all_cookies);//THIS IS LINE 38 $myplugin_debug_test.= "\n... DONE]<br/>\n"; However, when I do this I get the following error: Quote Warning: Cannot modify header information - headers already sent by (output started at ...:38 So my question is how can I output the array data into a string, so that I can print it out later. Like what am I doing wrong? Is there a better way to do this? Thanks! I'm a new PHP users needing some help. I've got two code snippets that run a CURL post to a syslog server grabbing specific records that I then parse with regex. Both are similar differing in the specific CURL URL and Regex. One works does not. The failing program seems to fail the regex parse creating a null array. What I've done thus far. Tested the regex on regex101 (works fine, using PCRE). Dumped and echoed the CURL created variable and then rechecked against regex101. ( again all good) Created a static variable in the code of the CURL return string (regex works fine). So the CURL is working, the variable string is working appearing as expected and the regex works. But the variable feels like's it null when passed directly from the CURL to the regex. No error logs, but this is where I'm stuck I don't know what to pick at next. Here's a version of the code. Appreciate any thoughts. <?php
$str = curl_exec($ch); // curl steps ends
//$str = '_bkt _cd _indextime _kv _raw _serial _si _sourcetype _time dhcp_type host index linecount source sourcetype splunk_server Configuration initialization for /opt/splunk/etc took 17ms when dispatching a search (search ID: 1591198882.902292) Your search was restricted by ( ( index=nat OR index=network OR index=radius ) OR ( source=/data/syslog/security/ipblocker ) ) base lispy: [ AND 66 82 8a 9c dhcpack e4 f8 sourcetype::infoblox:dhcp [ OR index::nat index::network index::radius source::/data/syslog/security/ipblocker ] ] search context: user="testuser", app="search", bs-pathname="/opt/splunk/etc" Your timerange was substituted based on your search string network~978~07708B5A-37B1-4315-8EFA-70B96D12856C 978:118251396 1591198398 1 Jun 3 11:33:15 128.230.100.36 dhcpd[21353]: DHCPACK on 10.1.0.19 to e4:f8:9c:82:66:8a (ITS-NDD-BOA-T01) via bond0 relay bond0 lease-duration 7200 0 its-splunk-idx2.syr.edu network infoblox:dhcp 2020-06-03 11:33:15.000 EDT DHCPACK 128.230.100.36 network 1 /data/syslog/network/dhcp infoblox:dhcp its-splunk-idx2.syr.edu'; |