-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Help with my first super simple "Hello World" Wordpress plugin
cyberRobot replied to Cp1's topic in Applications
Yep, the messages showed up in both places. -
Help with my first super simple "Hello World" Wordpress plugin
cyberRobot replied to Cp1's topic in Applications
For what it's worth, the plugin code worked for me. Have you tried changing the file/folder/plugin name? Perhaps the name you're using conflicts with another plugin, like Hello Dolly. -
If you output the value of $i in your for loop, you'll notice that the loop is being executed for every seat available. for($i=0;$i<$visitors;$i++){ echo "<div>here ($i)</div>"; $val['seatAvailable'] = 'x'; } To only suggest seats based on the number of visitors you, could replace the for loop with something like this: <?php //... //If available elseif($val['seatAvailable'] == '1'){ //IF THERE ARE STILL VISITORS TO PROCESS, MARK THE SUGGESTED SEAT if($visitors > 0) { $val['seatAvailable'] = 'x'; $visitors--; } } //... ?> Then once all the $visitors have been processed, you could break out of the loop. Here is all the code in context: <?php $visitors = 2; $seats = array( array( 'seatAvailable' => '0', 'seatNumber' => '1' ), array( 'seatAvailable' => '0', 'seatNumber' => '2' ), array( 'seatAvailable' => '1', 'seatNumber' => '3' ), array( 'seatAvailable' => '1', 'seatNumber' => '4' ), array( 'seatAvailable' => '1', 'seatNumber' => '5' ), ); echo "Visitors: ".$visitors; echo "<ol>"; foreach($seats as &$val){ //If not available if($val['seatAvailable'] == '0'){ //echo "<li>not available</li>"; } //If available elseif($val['seatAvailable'] == '1'){ //IF THERE ARE STILL VISITORS TO PROCESS, MARK THE SUGGESTED SEAT if($visitors > 0) { $val['seatAvailable'] = 'x'; $visitors--; } } //IF THERE ARE NO MORE VISITORS, EXIT LOOP if($visitors == 0) { break; } } echo "</ol>"; echo "<pre>"; print_r($seats); echo "</pre>"; ?>
- 2 replies
-
- 1
-
- for loop
- array validation
-
(and 2 more)
Tagged with:
-
You could try using mssql_get_last_message() to see if the database server is throwing an error. More information can be found here: http://php.net/manual/en/function.mssql-get-last-message.php Also note that you don't need to call mssql_query() twice. The following line is trying to process $query which will only contain "true" or "false": mssql_query($query) or die ('Error Updatating Database');
-
Topic locked. If you want to reply, Boxerman re-created the post here: http://forums.phpfreaks.com/topic/300363-changing-the-output/
-
Also note that you are missing a semi-colon here: $titleok = "les-huit-salopards" "{id}" and "{titleok}" seem to be a placeholder. Inside the foreach loop, "{id}" is supposed to be replaced with the value of $i. But snoVop doesn't seem to do anything with "{titleok}". With that said, I'm having a difficult time understanding the question also... It might help to know where $nbArticle comes from. Also, you are overwriting $urlAScroller in the following for loop: for($i=1; $i<=$nbArticle; $i++) { $urlAScroller = str_replace('{id}', $i, $urlok); } The rest of your code will only be working with the last value that $urlAScroller is set to.
-
Does your code look like this require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php"; Or this require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php"; Note that the ".." isn't needed when you're already in the document root and your accessing a folder in the document root.
-
So are you looking to create form input fields for each name? If so, you can do something like this: <?php foreach($names as $currName) { echo '<input name="name[]" value="' . $currName . '">'; } ?>
-
You could try DOCUMENT_ROOT? require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php";
-
Include Checkbox in Simple PHP Calendar Script
cyberRobot replied to Gazzahbay's topic in PHP Coding Help
Could you provide a little more information as to where you're stuck? Based on a cursory look, I didn't see a <form> tag in the above code. If you want the visitor to submit a value to PHP by clicking a check box, you'll need a <form> tag...and a way to submit the form. Side note: displaying the raw value of PHP_SELF to the screen makes your script vulnerable to XSS attacks. You could change lines like this <td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> ...to this <td width="50%" align="left"><a href="<?php echo "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> -
Is user.php being imported into the script? Perhaps that's being done in init.php. Is PHP set to display all errors and warnings? Note that you can add the following to the top of your script during the debugging process: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?>
-
There is a rogue quote after the call to CURRENT_DATE(). Try changing this $query="INSERT INTO earlyreg VALUES (playernick,'" . $checkBox . "',.,CURRENT_DATE()')"; To this $query="INSERT INTO earlyreg VALUES (playernick,'" . $checkBox . "',.,CURRENT_DATE())"; Also, strings need to be surrounded by quotes. So I imagine you'll need to do something like this $query="INSERT INTO earlyreg VALUES ('playernick', '" . $checkBox . "', '.', CURRENT_DATE())";
-
You're missing an open curly bracket before the else. And the else needs to be closed with a curly bracket. You could try something like this: if( $game['hs'] > $game['vs'] ){ ?><li><?= $homeTeam ?> <font color=red><?= $game['hs'] ?></font> <br /><?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } } else { ?><li><?= $homeTeam ?> <?= $game['hs'] ?> <br /><?= $visitingTeam ?> <font color=red><?= $game['vs'] ?></font> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } }
-
Having you tried adding a From header? More information can be found under the "additional_headers" option here: http://php.net/manual/en/function.mail.php See the second note under that section. Also, is PHP set to show all errors and warnings? To do so, you could add the following to the top of your script during the debugging process: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?>
-
Have you tried removing all the PHP code at the top and then adding it back a little at a time? This should help you track down the offending code.
-
Basically, you would change lines like this if ($row = "ELYOS") { To this if ($row[1] == "ELYOS") { For what it's worth, you could use mysql_fetch_assoc() to make the code a bit more readable. More information about the function, including examples, can be found here: http://php.net/manual/en/function.mysql-fetch-assoc.php
-
Are you looking to create a keyword highlighter like you find in search engines? If so, you could look into using something like str_ireplace(). More information can be found here: http://php.net/manual/en/function.str-ireplace.php Note that there's an example keyword highlighter in the user-contributed notes here http://php.net/manual/en/function.str-ireplace.php#87417
-
The database connection needs to be made before you can use mysql_real_escape_string(). http://php.net/manual/en/function.mysql-real-escape-string.php Also, there is a syntax error here: $result = mysql_query("SELECT * FROM predict WHERE first = '$first' AND second = '$second'"); or die ("Failed to query database".mysql_error()); There shouldn't be a semi-colon before "or". $result = mysql_query("SELECT * FROM predict WHERE first = '$first' AND second = '$second'") or die ("Failed to query database".mysql_error()); And in case you're not aware, mysql_* functions have been deprecated and will be removed in PHP 7. More information can be found here: http://php.net/manual/en/mysqlinfo.api.choosing.php
-
Sorry I rushed my response. For some reason I thought get_the_category() returned an array of category names...not an array of objects. I'm glad to see you were able to put something together out of that! Your code looks good to me!
-
Since get_the_category() returns an array, you could use implode(). More information can be found here: http://php.net/manual/en/function.implode.php
-
clone set of form fields and append number to name based on variable
cyberRobot replied to SF23103's topic in PHP Coding Help
You could do something like this: <?php $numOfPeople = $_GET['number']; for($i=1; $i<=$numOfPeople; $i++) { echo "<div style='margin-top:3em;'>Persion $i</div>"; ?> <p><label>Home Phone: <input name="home_phone_<?php print $i; ?>" type="text" value="" size="16" maxlength="18" placeholder="555-555-5555" /></label><span style="font-size:11px">(Required)</span></p> <p><label for="cell_phone_<?php print $i; ?>">Cell Phone:</label> <input name="cell_phone_<?php print $i; ?>" id="cell_phone_<?php print $i; ?>" type="text" value="" size="16" maxlength="18" placeholder="555-555-5555" /><span style="font-size:11px"></span></p> <?php } ?> Note that I fixed the <label> tags. For <label> tags to work, they either need to wrap around the label and the corresponding form field. Or the for attribute for the <label> tag needs to match up with the id attribute of the form field. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label -
You could try something like this: $matchingIndex = ''; foreach($yourArray as $currIndex => $subArray) { if($subArray[1] == 'Zurich Life') { $matchingIndex = $currIndex; break; //break out of the loop, since you found Zurich Life } }
-
Did you see my response above (Response #4)?
-
Sending a hashed password isn't going to be very useful for the person requesting their password. You'll need to generate a new random password and send them a plain-text version. Or better yet, send them an email to make sure they want to reset their password. If they click on the confirmation link, you can generate the new password and send it to them.