Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. P.S. You should be learning php, developing php code, and debugging php code on a local development system. You will lose a lot of time uploading code just the see the result of each change or to troubleshoot each error.
  2. Now would be the time to learn data driven designs, where you have a data structure (array, database table, ...) that defines what your code does for sets of related data. Then you have simple code that you don't need to change when the amount, content, order, .. of the data changes. The defining data structure is then used for producing the form and processing/validating the result from that form. Doing this also eliminates repeated code and data - DRY (Don't Repeat Yourself) and actually results in the simplest code. Sample code showing a data driven design - <?php // $data[x][y] = x is the question #, y are the entries. 0 is the question/legend, 1,2,... are the choices $data[1][0] = 'Are you pro-life (against abortion) or pro-choice (for abortion)?'; $data[1][1] = array('legend'=>'I am pro-life','type'=>1); $data[1][2] = array('legend'=>'I am pro-choice','type'=>2); $data[2][0] = 'Do you believe that gun rights are necessary to preserve safety, freedom and to protect us from tyranny, or do you believe unarmed citizens are safer citizens?'; $data[2][1] = array('legend'=>'I support gun rights','type'=>1); $data[2][2] = array('legend'=>'I believe citizens should be unarmed','type'=>2); $data[3][0] = 'Do you believe in free markets (limited regulation on business) or do you believe the government should regulate business\' to any extent necessary?'; $data[3][1] = array('legend'=>'I support free markets','type'=>1); $data[3][2] = array('legend'=>'I support regulating to any extent necessary','type'=>2); ?> <form action="results.php" method="post"> <?php // produce the questions/choices foreach($data as $question=>$array){ echo "<h4>$question. {$array[0]}</h4>\n"; $num = count($array); for($x=1;$x<$num;$x++){ echo "<input type='radio' name='question[$question]' value='$x'/> : {$array[$x]['legend']}<br />\n"; } } ?> <br /> <input type='hidden' name='submit' /> <input type="submit" value="Tell me if I'm a Republican or Democrat!" /> </form> <?php // $data[x][y] = x is the question #, y are the entries. 0 is the question/legend, 1,2,... are the choices $data[1][0] = 'Are you pro-life (against abortion) or pro-choice (for abortion)?'; $data[1][1] = array('legend'=>'I am pro-life','type'=>1); $data[1][2] = array('legend'=>'I am pro-choice','type'=>2); $data[2][0] = 'Do you believe that gun rights are necessary to preserve safety, freedom and to protect us from tyranny, or do you believe unarmed citizens are safer citizens?'; $data[2][1] = array('legend'=>'I support gun rights','type'=>1); $data[2][2] = array('legend'=>'I believe citizens should be unarmed','type'=>2); $data[3][0] = 'Do you believe in free markets (limited regulation on business) or do you believe the government should regulate business\' to any extent necessary?'; $data[3][1] = array('legend'=>'I support free markets','type'=>1); $data[3][2] = array('legend'=>'I support regulating to any extent necessary','type'=>2); $types[0] = 'This is an undecided view.'; $types[1] = 'This is a republican/conservative view.'; $types[2] = 'This is a democrat/liberal view.'; // form processing code if(isset($_POST['submit'])){ // loop though the expected question data and display any results foreach($data as $question=>$array){ echo "Your answer to question {$question} is: "; if(!isset($_POST['question'][$question]) || $_POST['question'][$question] < 1){ // no radio selected echo "NONE. {$types[0]}<br />"; } else { $answer = (int)$_POST['question'][$question]; $type = $data[$question][$answer]['type']; echo "{$data[$question][$answer]['legend']}. $types[$type]<br />\n"; } } } ?>
  3. number_format
  4. For the code that doesn't work, have you set the mb_internal_encoding anywhere in the script?
  5. This is the description line from the forum section you posted in - What code have you written and what error, symptom, or problem did you have when you ran it? If you are stuck at trying to figure out how you might do this, take a piece of paper and list out the steps you would do to accomplish this task in person, because programming is like writing a math-word-problem and then solving it - A person walks up at a timed-voting place, you write down the starting time, the id number you assigned (auth code), a description of the person (ip address/user agent) so that you can identify the person to make sure s/he didn't trade their id number with someone else; then when s/he comes back to vote, you check the id number/description to find the start time you previously wrote down and compare it with the current time and decide if s/he can vote.
  6. Since this is a third-party php script, moving this thread to the appropriate forum section...
  7. Two == signs is a equal comparison operator. One = sign is an assignment operator.
  8. That statement is actually incorrect. The code is using the mysql password() function. There are two problems with using that function - 1) The size of the hash changed between mysql versions, breaking any data that used it, 2) -
  9. Here's the error message in a readable font (you cannot edit your post without messing up the posted code) - Parse error: syntax error, unexpected $end in /public/sites/build2.mccity.org/Register.php on line 237
  10. After you make your database connection, add the following line of code and see if it corrects the problem - mysqli_set_charset($connection, "utf8"); Also, $row[2] in the fetched $row array doesn't exist (unless you also altered your query for the post), since you are only selecting the syllabilized column. Try $row[0].
  11. If you mean the original script at the start of this thread? I wouldn't bother. I browsed through all the .php files making up that application and none of them are validating/escaping data being put into database queries or the data going into the mail() parameters. At least two of the 'admin' .php files aren't effectively testing if the current visitor is even logged in and allows anyone to add/delete or update user information. The script is also doing things like storing the user's password in plain text in a cookie and is relying on register_globals (turned off by default over 10 years ago and has been completely removed in php5.4) to get cookie values into program variables. There's also an inconstant usage of both short and full opening php tags (and a lot of other inconstant coding in it.) And several more things, I not going to take the time to write up... In short, that application is doing a number of things we are constantly telling noob programmers not to do. It looks like the author probably did this as a school project, got a passing grade on it, thought he had accomplished something useful, and posted it on the Internet.
  12. The simplest and most straight-forward method, if you want individual 'add to basket' links/buttons, one per product, and a quantity text box per product, would be to make a form for each product and change the existing link into a submit button for the form. The submitted text box would be the quantity and you would pass the id value as a hidden field in the form.
  13. The problem with the submit button usually occurs when you don't click on the button, but use the enter key to submit a form or submit the form using javascript.
  14. ^^^ Your mysqli_error() statement isn't coded correctly. It requires the mysqli link as a parameter.
  15. You should have display_errors OFF, log_errors ON, and error_reporting set to E_ALL so that any php detected errors will be logged in the environment where the script is running so that you can find and fix any problems occurring in that environment.
  16. Unless you are doing something simple like finding dates great-than/less-than or between a range, storing data as a Unix Timestamp doesn't directly work for any Human related processing by year, month,week number, day, day of year, full date, or time of day periods, because you must first convert it to a human readable format. It's best to store it in a human readable format in the first place. You can always add a new DATE or DATETIME column to your table and populate it from your existing data using the FROM_UNIXTIME() statement that Barand showed. Then modify/test your scripts to use that new column. Finally drop your existing unix timestamp column. Edit: plus, once your data is stored as a DATE or DATETIME value, you can directly use the few dozen mysql data/time functions on it to do neat things in your query.
  17. Define: But it's not functioning? What result are you getting? What output or symptom occurred in front of you that leads you to believe it's not functioning? If you are getting a 'Success' message, but the rows are not being deleted, the only thing your conditional code at the end is doing is testing if the queries ran without any errors. That doesn't mean they actually deleted anything, which would occur if the WHERE clause is FALSE (i.e. the $sperson variable is empty or doesn't match any entry in the table(s).) You would need to both test if the queries executed without any error and use mysql_affected_rows to determine if any row(s) were actually deleted before outputting a 'Success' message.
  18. You forgot to ask a question. What error or symptom are you getting or what problem do you need help with?
  19. You do realize that no one likes visiting a web site with a dark background with dark text on it and no one here wants to try and read an error message with a dark background with dark text on it. Just copy/paste the text of the output you are getting into a post in this thread so that someone could help you with it.
  20. Literal dates in a query are strings and must be enclosed by single-quotes, otherwise they are a subtraction math expression. 2012-12-05 = 1995.
  21. Yes. See the following line from my post above - $show = isset($_GET['show']) ? strtolower(trim($_GET['show'])) : ''; This tests if $_GET['show'] is set and does some filtering/conditioning of the value and assigns the result to $show.
  22. In your .sql backup file, there are lines like - CREATE DATABASE IF NOT EXISTS db_name; USE db_name; Just enter a new name for the db_name. You will also need to assign a database user permissions to use that new database.
  23. Here's a slightly different slant on the problem. You should not allow visitors to type in entire dates, even if you display the expected format(s) right next to where they are entering the dates, because you will end up with some visitors that originally came from different locations or that don't/didn't read the expected format(s), entering dates with the months/days transposed. You should use three separate drop-down select menus and/or a javascript pop-up datepicker that would submit the year, month, and day in one known format.
  24. It's not actually a php problem. The control characters - \r\n (and \t) aren't html and don't render on a html page (they actually format the source of the page.) Run your content through nl2br when you output it onto a web page.
  25. This has nothing to do with your assignment (and you probably shouldn't turn in code that works like this), but when you operate on a set of related data values, you should not write out repetitious code that only differs in the values each section contains. You should use a data structure of some kind (array, database table) - <?php $data['regan'] = array('title'=>'Ronald Reagan','image'=>'reagan.gif','content'=>'Text1'); $data['kennedy'] = array('title'=>'John F. Kennedy','image'=>'kennedy.gif','content'=>'Text2'); $data['roosevelt'] = array('title'=>'Franklin Roosevelt','image'=>'roosevelt.gif','content'=>'Text3'); $data['lincoln'] = array('title'=>'Abraham Lincoln','image'=>'lincoln.gif','content'=>'Text4'); ?> <html><head><title>Lab</title></head> <body> <table> <tr><td> <h3>Menu</h3> <ul> <?php foreach($data as $key=>$arr){ echo "<li><a href='lab.php?show=$key'>{$arr['title']}</a></li>"; } ?> </ul> </td><td class="content"> <?php $show = isset($_GET['show']) ? strtolower(trim($_GET['show'])) : ''; if(isset($data[$show])){ // show exists echo "<h3 class=\"topHeading\">{$data[$show]['title']}</h3><br />"; echo "<img src=\"{$data[$show]['image']}\" align=\"left\" /><p>{$data[$show]['content']}</p>"; } else { // default echo "<center><h1>Presidential Quotes</h1><br /><h3>Text5</h3>"; } ?> </td></tr> </table> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.