-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
The math operation needs to be done outside the string print "<br>" . (278909887*4) . "</br>"; Anything within a quotes is treated as-is. Only variables are expanded within double quoted strings. If you need to calculate/perform a function and use the result in a string you need to concatenate. Explained here http://php.net/manual/en/language.operators.string.php
-
Listing Categories and Sub categoris with PHP and Mysql
Ch0cu3r replied to thara's topic in PHP Coding Help
Whats lev3 set to when there is no sub category? Your query should be returning NULL and so checking to see if $lev2_categories is not empty should work. -
Listing Categories and Sub categoris with PHP and Mysql
Ch0cu3r replied to thara's topic in PHP Coding Help
Build a multidimensional array from the query result, using lev1 and lev2 values as the keys $categories = array(); while($row = mysqli->fetch_assoc()) { $categories[ $row['lev1'] ][ $row['lev2'] ][] = $row['lev3']; } Now you can use a series of foreach loops to create the unordered list, echo '<ul class="list-unstyled categorychecklist ">'; foreach($categories['pets'] as $lev2_category => $lev2_categories) { echo ' <li><input type="checkbox" value="" />' . $lev2_category . ' <ul class="children">'; foreach($lev2_categories as $lev3_value) { echo '<li><input type="checkbox" value="" />'.$lev3_value.'</li>'; } echo ' </ul> </li>'; } echo '</ul>'; -
$S_POST should be $_POST on this line $selectCat = $S_POST["updateCategoria"];
-
Using fgetcsv you would use the semi-colon as the delimeter. As you loop over the lines when $data[0] starts with BRD, $data[3] will contain the value for the temperature column. The following code will build an array of temperatures, the board column (BRD 0, BRD 1) etc will be used as the index for the array. <?php $temps = array(); if (($handle = fopen("data.txt", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { if(substr(trim($data[0]), 0, 3) == 'BRD') { $board = trim($data[0]); $temp = $data[3]; $temps[ $board ] = $temp; } } fclose($handle); } Change data.txt to the filename your data is stored in. To show the temperature for board 1 (BRD 1) you would use echo $temps['BRD 1'];
-
Sorry that line should be if(!$inConvoy && isset($_POST['addConvoyUser']))
-
Help with my functions.php coding to create a logout link
Ch0cu3r replied to pmcg911's topic in PHP Coding Help
That functions returns the footer menu as a string, so you cant use echo. You need to concatenate the logout link if the user is logged in. Something like this maybe function my_omega_footer_insert( $settings ) { $year = date( 'Y' ); $siteurl = get_bloginfo( 'url' ); $sitename = get_bloginfo( 'name' ); $footer = ''; // prepend logout link to footer if(is_logged_in()) $footer .= '<a href="' . wp_logout_url(get_permalink()) . '" title="Logout">Logout</a> | '; $footer .= "<a href='http://bibliophone.com/about/'>About</a> | <a href='http://bibliophone.com/terms-of-use/'>Terms of Use</a> | <a href='http://bibliophone.com/privacy-policy/'>Privacy Policy</a><br>© <a href='$siteurl'>$sitename</a> $year</p>"; return $footer; } -
Sorry, $result->rowCount() should of been $stmt->rowCount()
-
So $result is used in a different page from where it is being set? If that the case then variables are not remembered between pages. The easiest option is to add the result to a session. You can then get the value from the session variable on the other page. In both pages make sure you are calling session_start() at the very top. When setting the result use if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $_SESSION['result'] = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $_SESSION['result'] = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } } Then in your other page use <div class="form-group"> <?php if(isset($_SESSION['result'])) echo $_SESSION['result']; // get result from session ?> </div>
-
Form isn't working, goes to action-page.php
Ch0cu3r replied to MurielBuis's topic in PHP Coding Help
Blank white page usually means PHP encountered an error. Either check your severs error logs or enable error reporting either in your php config or add the following lines before line 1 <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> NOTE: Please wrap code in tags when posting code. I have edited your post for you. -
Is this code in newpass.php? It appears this code is from a different file. The undefined variable error is coming from newpass.php on line 81.
-
$user2 needs to be wrapped in quotes in the query $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = '$user2' AND password = sha1('$old') ";
-
Can you clarify where this code is being called from. if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $result = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $result = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } }
-
Apply a WHERE clause to your select query (I am guessing the username/userid field name and variable) $sql="SELECT * FROM admin WHERE user = '$user'";
-
There does not appear to be anything wrong with that code you provided. Are you saying that this code is within a function your have defined yourself? if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $result = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $result = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } } eg function foo($bar...) { // your code here } And you are using/echo'ing $result outside of the function? If that is the case then functions have there own variable scope, meaning variables defined within the function is only available to that function, likewise variables defined outside the function cannot be used within the function. Please see the following documentation on the subject http://php.net/manual/en/language.variables.scope.php Read it but do not use GLOBALS as the solution! What you should do is have your function return the value of $result at the end of the function, eg function foo($bar...) { // your code return $result; // return the value of $result } When you call the function you assign it to a variable so you can capture the return value $result = foo($bar...); // call foo and capture the returned value Now $result will contain the value returned by your function.
-
If you are not running PHP5.5 then you cannot use trim with empty Quote from php.net/empty So you need to first trim the data and then pass the data to empty $APPLICANT_SOCIAL_SECURITY = trim($_POST['applicant_social_security']); // trim applied here $APPLICANT_SOCIAL_SECURITY = strip_tags($APPLICANT_SOCIAL_SECURITY); if (empty($APPLICANT_SOCIAL_SECURITY)) { $APPLICANT_SOCIAL_SECURITY = "No answer entered"; }
-
You are almost there. A couple of issues On line 13 you do not want to use basename. $id = $_POST['id']; basename was used on $_POST['Filename'] so only the filename is returned if someone had typed in a filepath into the filename field. Line 34 should be an if statement not an else if statement if(empty($_POST['id'])) The previous if and else if statements is used for validating the filename. On line 34 the if statement is the start of validating the id On line 47 you want check $stmt->rowCount() is equal to 1, meaning has one row been returned from the query if($stmt->rowCount() == 1)
-
If $row[name'] contains a string then the value for the bname javascript variables needs to be wrapped in quotes not parenthesises var bname = \''.$row['name'].\''; // or var bname = "'.$row['name'].'";
-
Yea you can add that variable back in I removed it. Did not realize $id was used in your form only saw $filename being used.
-
Before querying the table to see if the user is in the convoy define a variable such as this $inConvoy = false; Then when you check your query has returned a result. Set that variable to true if($result->rowCount() > 0) { $inConvoy = true; } Change the if statement for checking if $_POST['addConvoyUser'] exists to if(!$inConvoy && if(isset($_POST['addConvoyUser'])) Then wrap your sign up form in a if statement so it only shows the form if $inConvoy is false <?php if(!$inConvoy)): ?> <form class="form-signin" role="form" action="convoy.php" method="post"> <button class="btn btn-lg btn-primary btn-block" name="addConvoyUser" type="submit">Sign up for this convoy</button> </form> <?php else: ?> You have already signed up for the convoy. <?php endif; ?>
-
I forgot the echo before implode. You may need to change line 117 to <td colspan="2"><?php echo implode('<br />', $error); ?></td></tr><tr> Otherwise the error messages will be all squished into one column in your table. Also change line 33 to be a else if statement and delete line 53 $error = true;
-
Dont use die use echo See the documentation on die http://php.net/die
-
Rename $errors to $error on line 117