-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
That depends. If "long_name" comes from a checkbox or radio button, for example, the POST variable may not be set. If the page is ever called without the form submission, the POST variables won't be set.
-
Huh, good point.
-
No problem For what it's worth, the regular expression would have needed to look something like the code below. The "/" character is the delimiter. Square brackets need to be escaped with "\" since they have special meaning in regular expressions. <?php $body = preg_replace("/\[date\]/", $showDateS, $body); ?> Note: str_replace() is a better option in this case since it doesn't require the power of regular expressions.
-
You're actually using preg_replace() which uses regular expressions. Basically, the square quotes in "[date]" are being used as the delimiter. So they're not technically part of the search. Instead, try str_replace(): <?php $body = str_replace("[date]", $showDateS, $body); ?>
-
generating drop down menus with PHP and MySQL
cyberRobot replied to gec100's topic in PHP Coding Help
If you're changing how the form submits, may I suggest switching to a regular submit button since it doesn't depend on JavaScript. If you decide to use onchange, be aware that it won't work if the option is already selected. For example, let's say someone selects "FINA" from the drop down and the form submits. If they hit the back button and "FINA" is still selected, they won't be able to select "FINA" again unless they choose another option...or refresh the page. Note that you could also consider using JavaScript to show and populate the second menu. -
Check that word begins with specific letters
cyberRobot replied to simonjk's topic in PHP Coding Help
Hint: <?php //... echo CheckWord('Ewok') ? 'Yes' : 'No'; // Yes echo CheckWord('word') ? 'Yes' : 'No'; // No //... ?> -
generating drop down menus with PHP and MySQL
cyberRobot replied to gec100's topic in PHP Coding Help
Did you try fixing the error mentioned by the validator? Another issue I noticed is the <body> tag isn't complete. <body -
generating drop down menus with PHP and MySQL
cyberRobot replied to gec100's topic in PHP Coding Help
The first <select> tag doesn't appear to have been closed. For what it's worth, I would recommend running the code through a validator like the following: http://validator.w3.org/ -
I would recommend str_replace() since it doesn't require regular expressions: http://php.net/manual/en/function.str-replace.php
-
Check that word begins with specific letters
cyberRobot replied to simonjk's topic in PHP Coding Help
I would suggest adding strtoupper() to make the solution case insensitive: <?php function CheckWord($word) { return in_array(strtoupper($word[0]), array('E', 'L', 'B')); } echo CheckWord('Ewok') ? 'Yes' : 'No'; // Yes echo CheckWord('word') ? 'Yes' : 'No'; // No echo CheckWord('enough') ? 'Yes' : 'No'; // Yes ?> Unless you only want to match uppercase letters. -
Shouldn't that be "Num" with an upper-case "N"? $total_pages[Num] For future reference, turning on all errors and warnings provides clues as to what's wrong: error_reporting(-1); ini_set('display_errors', 1); Also note that the "Num" part should be in quotes: $total_pages['Num']
-
I would recommend checking out the manual entry for header(): http://php.net/manual/en/function.header.php
-
You'll also want to be mindful of the semi-colon. Do you notice any issues with the following code? <?php $RandNum = rand(0, 100); $Body = "": $counter = 0; ?> FYI, the code for starting the session may work as expected. But it will break if anything gets added to that PHP code block. For example, the code breaks if you do something like <?php session_start() print 'here'; ?> Adding a semi-colon in the correct position will prevent the code from breaking.
-
For what it's worth, it's actually JavaScript. Java is a totally different programming language. I know picky, picky.
-
One way is to merge both the PHP and JavaScript code. For example, here's a simplified code snippet from a Google Map I created earlier in the year. <?php $sql = "SELECT id, name, latLong FROM tableName ORDER BY name"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { ?> //ADD MAP MARKER FOR CURRENT ENTRY var marker<?php print $row['id']; ?> = new google.maps.Marker({ position: new google.maps.LatLng(<?php print $row['latLong']; ?>), map: map, title:"<?php print $row['name']; ?>" }); <?php } ?> If you prefer to add the markers with XML, the above code could be modified to meet those needs. Instead of loading the map after the submit button is clicked, you would load it when the PHP part is done using something like this: https://developers.google.com/maps/documentation/javascript/tutorial#asynch
-
It looks like your form goes straight to JavaScript. To use PHP code, the form data needs to be sent back to the server for processing.
-
No problem. There's one last thing I wanted to mention, but I thought I would wait until the initial question was answered. It's highly recommended that you avoid using PHP_SELF as the form action. <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > You could hard code the value instead. PHP_SELF should be avoided for security reasons. For more information, see: http://seancoates.com/blogs/xss-woes
-
Does your database table (service_info) have a column named "comments"?
-
First, the code could be easier to maintain if you used mysql_fetch_array() instead of mysql_result(). Instead of this <?php $i=0; while ($i < $num) { $field1=mysql_result($result,$i,"id"); $field2=mysql_result($result,$i,"name"); $field3=mysql_result($result,$i,"number"); $field4=mysql_result($result,$i,"location"); $field5=mysql_result($result,$i,"status"); $field6=mysql_result($result,$i,"rts"); $field7=mysql_result($result,$i,"odomread"); $field8=mysql_result($result,$i,"odomdate"); $field9=mysql_result($result,$i,"date_next_maint"); $field10=mysql_result($result,$i,"issues_reported"); $field11=mysql_result($result,$i,"date_reported"); $field12=mysql_result($result,$i,"scheduled_service_date"); $field13=mysql_result($result,$i,"service_performed"); $field14=mysql_result($result,$i,"date_service_performed"); $field15=mysql_result($result,$i,"date_of_followup"); $field16=mysql_result($result,$i,"service_in_progress"); $field17=mysql_result($result,$i,"date_return_use"); $field18=mysql_result($result,$i,"time_return_use"); $field19=mysql_result($result,$i,"issues_nonrepairable"); $field20=mysql_result($result,$i,"date_nonrepairable_issues"); $field21=mysql_result($result,$i,"parts_cost"); $field22=mysql_result($result,$i,"hours"); $field23=mysql_result($result,$i,"comments"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field6; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field8; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field9; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field10; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field12; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field13; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field14; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field15; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field16; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field17; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field18; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field19; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field20; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field21; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field22; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $field23; ?></font></td> <td><a href="maint_update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php $i++; } ?> You could do this: <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['id']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['name']; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['number']; ?></font></td> <!-- You can do the rest ;-) --> <td><a href="maint_update.php?id=<?php echo $row['id']; ?>">update</a></td> </tr> <?php } ?> If you do that, does the ID show up as expected in the following portion? <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['id']; ?></font></td> <!-- ... --> <td><a href="maint_update.php?id=<?php echo $row['id']; ?>">update</a></td>
-
If you haven't done so already, the form page needs to be updated to pass the ID for the row being updated. The update page needs to read in that ID so it can be used in the query. Sorry, I didn't see there was a third page of responses.
-
Unless I'm missing something, the OP doesn't want to update all entries. That's why we suggested the WHERE clause be added.
-
Hmm...where are you getting that quote from?
-
The form needs to pass the ID of the row being updated and you need to a WHERE clause in the update query (like ChristianF suggested).
-
It's highly recommended that you avoid using PHP_SELF as the form action. <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>"> You could hard code the value instead. PHP_SELF should be avoided for security reasons. For more information, see: http://seancoates.com/blogs/xss-woes If you haven't done so already, you should look into using htmlentities() to help prevent code injections. <td><input name="task" type="text" id="task" value="<? echo htmlentities($row['task'], ENT_QUOTES); ?>"/></td>
-
Just in case you're still looking for help, have you tried displaying the session variable to make sure it contains what's expected as the loop executes? <?php //... $key2 = array_rand($_SESSION['sesscards']); $pick9 = $_SESSION['sesscards'][$key2]; unset($_SESSION['sesscards'][$key2]); var_dump($_SESSION['sesscards']); //see what the session variable looks like after unset() //... ?> Displaying the session variable should let you know if the value is being removed as expected.