Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
have you checked that you are not missing any fields and/or that they are named correctly? If you are missing one of the fields, that would explain why my code would not work. I did test the code and it worked for multiple brackets in multiple rounds. Here is a test page that utilizes the script I provided with fields for four rounds (8 teams to start) and the fields named according to your parameters above. It all works fine for me. If I leave any field empty the vaidation fails. <html> <head> <script type="text/javascript"> function getFieldObj(round, bracket) { if(document.forms['bracket'].elements['pick'+round+'_'+bracket]) { return document.forms['bracket'].elements['pick'+round+'_'+bracket]; } return false; } function validate_form() { var round = 1; var bracket = 1; while (fieldObj = getFieldObj(round, bracket)) { if (fieldObj.value=='') { alert("Please pick a winner for every game"); return false; } bracket++; if(!getFieldObj(round, bracket)) { round++; bracket = 1; } } return true; } </script> </head> <body> <form name="bracket"> <h1>Round 1</h1> Pick 1: <input type="text" name="pick1_1" /><br /> Pick 2: <input type="text" name="pick1_2" /><br /> Pick 3: <input type="text" name="pick1_3" /><br /> Pick 4: <input type="text" name="pick1_4" /><br /> Pick 5: <input type="text" name="pick1_5" /><br /> Pick 6: <input type="text" name="pick1_6" /><br /> Pick 7: <input type="text" name="pick1_7" /><br /> Pick 8: <input type="text" name="pick1_8" /><br /> <h1>Round 2</h1> Pick 1: <input type="text" name="pick2_1" /><br /> Pick 2: <input type="text" name="pick2_2" /><br /> Pick 3: <input type="text" name="pick2_3" /><br /> Pick 4: <input type="text" name="pick2_4" /><br /> <h1>Round 3</h1> Pick 1: <input type="text" name="pick3_1" /><br /> Pick 2: <input type="text" name="pick3_2" /><br /> <h1>Round 4</h1> Pick 1: <input type="text" name="pick4_1" /><br /> <br /> <button onclick="validate_form()">Submit</button> </form> </body> </html>
-
It is good practice to separate your logic (PHP code to get and prepare the results) from the presentation (the HTML ouput). That is the process I illustrated above. The logic at the top of the script queries the database to get the data. I then used htmlentities() on those values the prevent against content corrupting the output and/or CSS attacks (explained more below). One that is done, then I populate the data into the pre-formatted HTML ouput. regarding htmlentities(), that function will change certain characters into their equivalent HTML escape characters. This prevents those characters from being interpreted by the browser. For example, if a user entered "<b>Bobby</b>" as their name, then their name would be displayed as Bobby because the bold tags would be interpreted by the browser. htmlentities() will convert the lessthan/greaterthan tags to < and > so what will be displayed is EXACTLY what the user entered: "<b>Bobby</b>". Of course, bold tags is a minor consequence. If you do not protect the output, users can inject JavaScript to make some really bad things happen: redirect the user to another site, crash the browser, load a virus, etc.
-
I don't see where you are defining $to. It would have to be defined BEFORE you define $error[2]
-
This is ALL you need. $monthName = date('F', strtotime($_POST['DATE OF REPORT'])); If the input ($_POST['DATE OF REPORT']) = "03/21/10", then $monthName will be "March". Will work for any valid date.
-
Well, I tested it out and it worked fine for me. The logic starts with round = 1 and bracket = 1. It then checks the field for that round and bracket. if that passes it increments bracket by 1. If that field exists it checks it. If not it increments round by 1 and sets bracket to 1. If at any time it finds a field with no value it will return false. If it continues through all available rounds and brackets (all having values) it will return true.
-
function getFieldObj(round, bracket) { if(document.forms['bracket'].elements['pick'+round+'_'+bracket]) { return document.forms['bracket'].elements['pick'+round+'_'+bracket]; } return false; } function validate_form() { var round = 1; var bracket = 1; while (fieldObj = getFieldObj(round, bracket)) { if (fieldObj.value=='') { alert("Please pick a winner for every game"); return false; } bracket++; if(!getFieldObj(round, bracket)) { round++; bracket = 1; } } return true; }
-
No need for IF statements at all: $d = '02/%'; echo date('F', mktime(0,0,0, preg_replace("/[^\d]/", '', $d))); //Output: February
-
As I stated, text needs to be passed enclosed in quotes. Try this: print "<a href=\"javascript:void(0);\" onClick=\"zz(1,1,'$ico',0,'$price',4)\" >"; If that does not work, then I don't know what to tell you. Text need to be enclosed in quotes in a function call. If that is fixed, then I would assume that the function zz() is expecting a number for some of the parameters that you are passing text.
-
You should have a separate table to record each instance of an activity that adds to their points with: userID, date, points, activity. You can then get a user's total points by doing a JOIN between the user table and the points table. You can then also get a users points by some arbitrary value (such as a date span) or by activity via the WHERE clause example: SELECT u.name, u.id, SUM(p.point) as totalPoints FROM users u JOIN points p ON u.id = p.user_id WHERE u.id = {$userID} AND p.date > {$startDate} AND p.date < {$endDate}
-
OK, I was trying to lead you to the answer instead of just blurting it out. You state in Reply #2 But, in the last reply you state So, it would appear that is the output when $ico is '1' (when it works) and not 's', when it does not work. Also, where did 'Manna Biscuit' come from? You previous code showed that parameter as being hard coded with a 1. I already posted above what the output would look like when the value is 's'. The problem is that you cannot pass text in a function call unless it is enclosed in quote marks. Incorrect: onClick='zz(s,1,1,1,1,1)' Correct: onClick="zz('s',1,1,1,1,1)"
-
"Doesn't work" doesn't provide any useful information. Did you check the error that were generated, because there would be one, what were they? Did you LOOK at the output created? If you had, I would think the problem would be obvious. You didn't state originally that the value could be anything other than a number. If the value is 's', the resulting code output to the browser would be: <a href='javascript:void(0);' onClick='zz(s,1,1,1,1,1)' > See anything wrong with that 's' now?
-
str = str.replace(/[^a-z0-9-\n\r]+/g, '-');
-
Doesn't work how? What is the value of "$row2['icon']" and what does the resulting code look like?
-
preg_replace() to the rescue: $text = "Bob Thomas,Bill Sampson , Ted Ginn , Greg Mood"; $newText = preg_replace("/\s*,\s*/", ",", $text); echo $newText . "<br>"; //Output: Bob Thomas,Bill Sampson,Ted Ginn,Greg Mood
-
In the code I provided, the function is storing the grid data in a session value. If you modified the code to store in a local variable then you need to ensure the variable is created in the proper scope. Again, II assume you would want to use the grid in a subsequent page load if you are doing some type of game, so a session variable would make sense.
-
That's typicaly a problem with a missing closing paren ), bracket ], semi-colon, etc. I copied the last function into the code and it worked fine.
-
I always create my forms to populate the post data for when validation fails. Not sure what you mean by "if it fails validation here, next time it returns to this same page it doesnt have submit or submit2". If validation fails on page 2 don't you reload page 2? What are you doing with the data from page 1 when validation passes? All you need to do is detemine how you will store the data when validation passes and then pull that data as needed. Here is what I would do. When validation passes for form 1, load form 2 with hidden fields to capture all the data from form 1. Then when validation fails for form 2, redisplay the form entering all the previous user submitted values (including the hidden fields). So you will then maintain the data previously submitted.
-
I would use logic similar to this <?php if(isset($_POST['submit']) { //Form 1 was submitted, validate data $valid = true; if(empty($_POST['name'])) { $valid = false; } if(!$valid) { //Form 1 validation failed, redisplay the form $include = 'form1.php'; } else { //Form 1 data is valid. //Save the data somewhere and display form 2 $include = 'form1.php'; } } else if(isset($_POST['submit2']) { //Form 1 was submitted if(!$valid) { //Form 2 validation failed, redisplay the form $include = 'form2.php'; } else { //Form 2 data is valid. //Save the data somewhere and display confirmation page $include = 'thank_you.php'; } } else { //No data was, submitted display form 1 $include = 'form1.php'; } ?> <html> <body> <?php include($include); ?> </body> </html>
-
Have no idea where you are having a problem. I would assume that the Form 2 validation occurs in this section else if(isset($_POST['submit2']) { deal with form 2 } So, if validation fails, display form 2. The line of code you displayed above has nothing to do with what form is displayed. That apparently happens later. Personally I would have the actual forms as separate files so you can include() whichever one you need based upon what was submitted and the validation.
-
while($record=mysql_fetch_array($result)) { $selected = ($record['leadname']==$_SESSION['leadname']) ? ' selected="selected"' : ''; echo "<option value=\"{$record['leadid']}\"{$selected}>{$record['leadname']}</option>\n"; }
-
I assume you will need the grid saved to seesion, or something similar, so you can access it on subsequent page loads function checkergridtable($tableHeight, $tableWidth) { //Height and width of the cells $cellHeight = '5pt;'; $cellWidth = '5pt;'; $grid = array(); $cellStyle = "height:{$cellHeight};width:{$cellWidth};"; $tableHTML = "<table border=\"0\" style=\"font-size:1pt;\">\n"; for ($row=0; $row<$tableHeight; $row++) { $tableHTML .= "<tr>\n"; for ($col=0; $col<$tableWidth; $col++) { $grid[$row][$col] = rand(0,1); $cellColor= ($grid[$row][$col]==1) ? "FFFFFF" : "000000"; $tableHTML .= " <td width=\"10\" style=\"{$cellStyle}background-color:{$cellColor};\"> </td>\n"; } $tableHTML .= "</tr>\n"; } $tableHTML .= "</table>\n"; //Save the grid to session $_SESSION['grid'] = $grid; //Return the table content return $tableHTML; }
-
You are defining the string "$query", but then trying to run a query against the string "$selectLeadQuery" - which, presumably, does not exist. <select name="leadid" onchange="showLeadName()"> <?php $userID = mysql_real_escape_string($_SESSION['userid']); $query = "SELECT `leadid`, `leadname` FROM `lead` WHERE userid = '{$userID}' ORDER BY `leadname`"; $result = mysql_query($query) or die(mysql_error()); while($record=mysql_fetch_array($result)) { echo "<option value=\"{$record['leadid']}\">{$record['leadname']}</option>\n"; } ?> </select>
-
There's some inefficency and invalid HTML in the code above Also, as stated before, you should not be using GLOBAL. Instead, pass the height/width in the function call. The reason you cannot make the cell height smaller is that the code is using a single space character. Since that character has a size, the cell will only shrink to the size of the content of the cell. You can either change the font-size or use a transparent image. In the code below I gave the font a size of 1 pt and set the size of the cells within the function. <?php function checkergridtable($tableHeight, $tableWidth) { //Height and width of the cells $cellHeight = '5pt;'; $cellWidth = '5pt;'; $cellStyle = "height:{$cellHeight};width:{$cellWidth};"; $tableHTML = "<table border=\"0\" style=\"font-size:1pt;\">\n"; for ($row=0; $row<$tableHeight; $row++) { $tableHTML .= "<tr>\n"; for ($col=0; $col<$tableWidth; $col++) { $cellColor= (rand(0,1)==1) ? "FFFFFF" : "000000"; $tableHTML .= " <td width=\"10\" style=\"{$cellStyle}background-color:{$cellColor};\"> </td>\n"; } $tableHTML .= "</tr>\n"; } $tableHTML .= "</table>\n"; return $tableHTML; } ?> <html> <head> <h1>Make a grid</h1> <?php echo checkergridtable(10, 10); ?> </body> </html>
-
Well, I'm not quite sure why you are getting "those" results. I get different errors, but I know why - daylight savings time. If that is your problem you can fix this by setting the time to the middle of the day. And you can get the correct results with one function using a more "natural" conversion of "-2 day". echo Date("Y-m-d", strtotime("2010-03-30 12:00:00PM -2 day"));
-
I made some modifications to that code to help in readability and to make more efficient. You shouold really avoid GLOBAL if at all possible. And this is not one where it is needed - at all <?php function makegrid($rows, $cols) { $grid = array(); for($row=0; $row<$rows; $row++) { for($col=0; $col<$cols; $col++) { $grid[$row][$col] = rand(0,1); } } return $grid; } function gridtable($grid) { $tableHTML = "<table border=\"0\">\n"; foreach($grid as $row) { $tableHTML .= "<tr>\n"; foreach($row as $col) { $tableHTML .= " <td width=\"10\">{$col}</td>\n"; } $tableHTML .= "</tr>\n"; } $tableHTML .= "</table>\n"; return $tableHTML; } $gridArray = makegrid(10, 10); $puzzle = gridtable($gridArray); ?> <html> <body> <h1>Make a grid</h1> <?php echo $puzzle; ?> </body> </html> Although, unless you need to use the grid array for other purposes, I would suggest combining the funtions into one. function makegrid($rows, $cols) { $tableHTML = "<table border=\"0\">\n"; for($row=0; $row<$rows; $row++) { $tableHTML .= "<tr>\n"; for($col=0; $col<$cols; $col++) { $cellContent = rand(0,1); $tableHTML .= " <td width=\"10\">{$cellContent}</td>\n"; } $tableHTML .= "</tr>\n"; } $tableHTML .= "</table>\n"; return $tableHTML; }