-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Comma separated list converted to ordered list...
cyberRobot replied to Jim R's topic in PHP Coding Help
Should be: ... echo str_replace(',', '</li>\n<li>', $line['committed']); ... -
I recently had a customer say that one of my forms isn't working. For some reason the ID number is getting lost when she submits the form. The form code looks like: ... print "<form method='post' name='form' action='update.php'>"; ... print "<input type='hidden' name='id' value=\"$id\" />"; print "<input type='submit' name='submit' value=\"Save Session\" />"; print "</form>"; ... And the PHP code that gets executed looks like: ... //GET SESSION ID if(isset($_GET['id'])) { //ID from HTML link, before updates have been made $id = $_GET['id']; } elseif(isset($_POST['id'])) { //ID from form, after updates have been made $id = $_POST['id']; } else { $id = ''; } //IF SESSION ID IS VALID if(preg_match("/^\d+$/", $id)) { ... //ELSE, INVALID ID } else { $msg = "<span class='errorText'>Session ID not found or invalid.</span>"; } ... For some reason she usually gets the "Session ID not found..." error when submitting the form. Do you see any problems with the above code? Note that she has been able to sucessfully use the form before (in the same day); we have nearly 1,800 records submitted using these forms; and I am unable to duplicate the issue. So I'm at a loss on what to do next. Also, she talked with her IT person about the form. The IT person was able to submit data on his computer. So he reset her Internet options which seemed to fix the problem on her end temporarily. Note that she is using IE 7. She also said that she doesn't have access to any other browsers. I'm tempted to chalk this up as a personal computer issue, but wanted to get your input first.
-
Looking at the query: SELECT * FROM `usertable` WHERE `userid`= It looks like $u doesn't contain any data which causes the query to fail. If you echo $u before querying the database, does it show anything? ... function check_user( $u ) { echo "<div>User ID: $u</div>"; $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`=$u"); ...
-
email not sent on post data/ submit button
cyberRobot replied to diasansley's topic in PHP Coding Help
When submitting the form, does the URL change when you enter data vs leaving the field blank? In other words, when you hit the submit button in both senerios does the URL stay the same? Is this form on a WordPress website? If so, you may want to also ask the WordPress forum: http://wordpress.org/support/ Note that I'm not very familiar with WordPress yet. I have attempted to do some PHP things with WordPress that work for a "normal" website, but for whatever reason they didn't work in the WordPress environment. -
If the ID should always be a number, you could check to make sure it's a number before querying the database. ... if(preg_match("/^\d+$/", $_GET['id'])) { ... This will stop queries for things like: index.php?id=a
-
I'm not sure what you mean. Doesn't this: $id = $_GET['id']; declare the variable. If the variable exists, why would if($id != "") generate an error?
-
I don't see any problems with using if($id != ""); that's what I typically use. Note that if you chose to use the empty() function make sure you're aware that $id=0 will be considered empty. It shouldn't matter, you'll just need to have a page called "home.php". The id part just passes a variable.
-
Problem appending data to a $ in a while loop
cyberRobot replied to ActaNonVerba1's topic in PHP Coding Help
Yep, thanks for pointing those issues out. -
Problem appending data to a $ in a while loop
cyberRobot replied to ActaNonVerba1's topic in PHP Coding Help
I'm not sure what's going on with "LeftThumb" and "RightThumb". But if you're trying to display one thumbnail per loop, you want to utilize the $cd variable in the loop. For example: for($cd=0; $cd < $numberofthumbnails; $cd++) { $displaythumbs . '<div class="ThumbnailHolder">'; $displaythumbs . '<div><a class="group" href="../../../Images/Lighthouses/Beachy-Head/' . $cd . '.png"><img src="../../../Images/Lighthouses/Beachy-Head/Mini/Thumbnail-' . $cd . '.png" width="430" height="200" alt="Thumbnail ' . $cd . '"></a></div>'; $displaythumbs . '</div>'; } -
New to php, is there a way to simplify this code?
cyberRobot replied to munchkinz's topic in PHP Coding Help
Based on the snippet the form fields look to be the same from product to product. So you could look into creating an associative array for all the different products. Then use a loop to display them. -
This should work: <?php ... if ($bf->owner == "$username" || $bank->owner == "$username" || $casino_slots->owner == "$username" || $casino_roul->owner == "$username" || $bj->bjowner == "$username" || $airport->owner == "$username") { echo"<tr><td><a class='menuLink' href='myproperties.php' onMouseDown='return false;' target='main'>• My Properties</a></td></tr>"; } ?>
-
Unable to remove the comma at the last value
cyberRobot replied to genzedu777's topic in PHP Coding Help
First we created a variable called "$separator" and made sure it was blank. $separator = ''; Then in the loop, we display whatever "$separator" holds along with the "subject_name". Note that the first time through the loop "$separator" will be blank. Every other time it will contain ', ' which is assigned after the echo statement. ... echo $separator . $row3['subject_name']; $separator = ', '; ... Hopefully that makes sense, let me know if it doesn't. -
Unable to remove the comma at the last value
cyberRobot replied to genzedu777's topic in PHP Coding Help
And yet another option: $separator = ''; while($row3 = mysqli_fetch_array($data3)) { if($row3['level_id'] == 2) { echo $separator.$row3['subject_name']; $separator = ', '; } } -
So basically, you want the values from all the boxes that are checked? If so, the first problem is that you'll need to change the checkbox code. Your current code has four checkboxes with the same name. So when the data is sent back to the server you'll only have one value if more than one is checked. <input type="checkbox" name="genre" id="genre" value="fighting" />fighting <input type="checkbox" name="genre" id="genre" value="school life" />school life <input type="checkbox" name="genre" id="genre" value="king" />king <input type="checkbox" name="genre" id="genre" value="him" />him Instead you'll want the checkboxes to have different names and ids. <input type="checkbox" name="genre1" id="genre1" value="fighting" />fighting <input type="checkbox" name="genre2" id="genre2" value="school life" />school life <input type="checkbox" name="genre3" id="genre3" value="king" />king <input type="checkbox" name="genre4" id="genre4" value="him" />him Now you'll have four different variables to work with in your script: echo $_GET['genre1'] . ', '; echo $_GET['genre2'] . ', '; echo $_GET['genre3'] . ', '; echo $_GET['genre4'] . ', '; Note that if your form is set to method="post" you'll need to change the above variables to $_POST['genre1'], etc.
-
You could use some Javascript and CSS to hide the <div>. Add some CSS to the page: <style type="text/css"> .active { display:block; } .inactive { display:none; } </style> If you're <div> doesn't already have an ID, create one. You'll also need to default the class to "active" if you want it to be shown by default. For example: <div id="contentToBeHidden" class="active">...</div> Now you just need to create a JavaScript funtion to deal with the onclick (Example: <a href="#" onclick="changeRecentPosts()">Test</a>): <script type="text/javascript"> function changeRecentPosts() { //IF THE DIV IS CURRENTLY SHOWING, HIDE IT if(document.getElementById('contentToBeHidden').className == 'active') { document.getElementById('contentToBeHidden').className='inactive'; //ELSE...THE DIV IS HIDDEN, SHOW IT } else { document.getElementById('contentToBeHidden').className='active'; } } </script> Here my entire test script: <!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>Untitled Document</title> <script type="text/javascript"> function changeRecentPosts() { //IF THE DIV IS CURRENTLY SHOWING, HIDE IT if(document.getElementById('contentToBeHidden').className == 'active') { document.getElementById('contentToBeHidden').className='inactive'; //ELSE...THE DIV IS HIDDEN, SHOW IT } else { document.getElementById('contentToBeHidden').className='active'; } } </script> <style type="text/css"> .active { display:block; } .inactive { display:none; } </style> </head> <body> <p><a href="#" onclick="changeRecentPosts()">Test</a></p> <div id="contentToBeHidden" class="active">Content to be hidden</div> </body> </html> Let me know if you have any questions.
-
You could remove the link based on the location of the http:// (or https://) and the location of the first space after the position of the http:// part. Note that this will fail if there is a space in the link. http://www.example.com/my page.html
-
What is "changeRecentPosts()" supposed to do?
-
Sorry about that, for the error 404 page we use: getenv("REQUEST_URI")
-
In addition to what was already suggested, is there a reason you're displaying this information in the <head> section of the page?
-
Using "\s" seems to works for me; I just added it before and after the "[-/.]" parts: if(preg_match("~^(0?[1-9]|1[012])\s[- /.]\s(0?[1-9]|[12][0-9]|3[01])\s[- /.]\s(19|20)[0-9][0-9]$~", $_GET['date'])) { echo 'match'; } else { echo 'no match'; }
-
@MrAdam - good point
-
No problem. If you're looking for a quick reference for regular expressions, I find the following resource useful: http://weblogtoolscollection.com/regex/regex.php
-
Just to clarify, with the following code: if(preg_match('/nprezident/,/prezident/', $ex)){ Are you looking for "nprezident" or "prezident" in $ex? If so, you'll want to change the code to: if(preg_match('/(nprezident|prezident)/', $ex)) {
-
Newbie - PHP Booking Form - What am I doing wrong?
cyberRobot replied to 122lettie's topic in PHP Coding Help
O' ya, I remember those days. Thanks for the clarification. -
Newbie - PHP Booking Form - What am I doing wrong?
cyberRobot replied to 122lettie's topic in PHP Coding Help
@dragon_sa Just curious, why is it good practice to check the request method? Isn't it enough that data was passed through $_POST? if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['email'])) {