Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. Where you have $lu2; it doesnt actually call the function you assigned to the variable earlier on. That function will be called immediately when you assigned it to a variable. As the all the lvl functions do the same thng you should consider making them a generic function. Where you pass in the level and XP values that needs to be updated function updateUsersLevelXP($mysqli, $user_id, $level, $xp) { $result = $mysqli->query("UPDATE members SET level = $level, xp = $xp WHERE id = $id LIMIT 1"); // no need for a prepare query as you are setting the values, not the user if ($result && $mysqli->affected_rows > 0) { return true; } return false; } The uXL function is not needed, you'd place the code in that function after if(isset($_POST['lvlup']) { if(isset($_POST['lvlup'])) //If button is clicked, { $xp = getXp($mysqli); // get current XP $lvl = getLvl($mysqli); // get current level // error messages $nolvl = "You don't have enough experiance points!"; $maxlvl = "You are allready maximum level!"; $validXPLevel = true; // If user does not have valid XP it will be set to false if($lvl < 10) { //level 10 or more or 0 shows that ur maximum level allready. // now update xp based on level if ($lvl == 1 && $xp >= 200 ){ $xp -= 200; }else if ($lvl == 2 && $xp >= 500 ){ $xp -= 500; }else if($lvl == 3 && $xp >= 1000 ){ $xp -= 1000; }else if($lvl == 4 && $xp >= 1700 ){ $xp -= 1700; }else if($lvl == 5 && $xp >= 2500 ){ $xp -= 2500; }else if($lvl == 6 && $xp >= 3200 ){ $xp -= 3200; }else if($lvl == 7 && $xp >= 4000 ){ $xp -= 4000; }else if($lvl == 8 && $xp >= 5000 ){ $xp -= 5000; }else if($lvl == 9 && $xp >= 6200 ){ $xp -= 6200; } else{ $validXPLevel = false; } // if user still has valid xp, then update xp and level in database if($validXPLevel) { // pass in db, user id, level and xp values if(updateUsersLevelXP($mysqli, $_SESSION['user_id'], $lvl + 1, $xp)) { echo "You have gained a level!"; } else { // if Not, then not. echo "some prob!"; } } else { echo $nolvl; // not enough xp error } } else { echo $maxlvl; // max level error } }
  2. PHP has if/elseif/else statements just like Javascript. What is the error you are getting? What is the code for getLvl() function?
  3. Remove the PHP tags within your string. Variables are expanded within double quotes. However more complicated variables, such as associative arrays need to be wrapped in braces Also functions cannot be called within strings, so you need to use the concatenation operator. echo "<td class='left'><a href='member.php?id={$dnn['id']}'>$username".htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8')."</a></td>";
  4. Use a foreach loop, to loop over the arrays in $myarray. Add each item in that array to separate arrays $myarray =$this->_db->loadRowList(); $tables = array(); $places = array(); foreach($myarray as $array) { $tables[] = $array[0]; $places[] = $array[1]; } printf('<pre>Tables %s</pre>', print_r($tables, true)); printf('<pre>Places %s</pre>', print_r($places, true));
  5. You need to change project url to http://localhost instead of http://localhost/NewPhpProject/ Or save your project files in C:\Program Files (x86)\Zend\Apache2\htdocs\NewPhpProject\. Your should be able to change the project paths/urls when you right click the project and choose project properties.
  6. strlen returns the length of the string you pass to it. You could use this as you mentioned to check a username matches a certain length. if(strlen($username) < 5) { echo 'Your username is too short. 5 Characters minimum'; } strpos is used for finding the position of a character within a string. A weak example of this would to check if an email address is valid by checking for the @ char if(strpos($emailAddress, '@') === false) { echo 'Your email address is invalid'; }
  7. What do you mean by this?
  8. What problem remains?
  9. Maybe doing something like this. Creating a popup on the fly with JavaScript http://jsfiddle.net/jhB6G/1/
  10. Your use of radio buttons is incorrect. Radio buttons are used for listing a group of options, but only one option can be selected from that group. To define a group of options each radio button should be named the same and have a unique value. The problem is you have given all radio buttons their own unique name. For example for choosing the baseball category you have named each radio button uniquely as baseball_type. The radio button name should just be set to baseball, but the type should be the value. <input type="radio" name="baseball" value="tball"/> <input type="radio" name="baseball" value="rookie"/> <input type="radio" name="baseball" value="mosquito"/ > <input type="radio" name="baseball" value="peewee"/> <input type="radio" name="baseball" value="bantam"/ > When the form is submitted $_POST['baseball'] will contain the chosen option. However if no option was selected then $_POST['baseball'] will not exist when the form is submitted. What you need to do is go through your HTML and set each group of options to the same name.
  11. The while loop wont show the first row because you are calling mysqli_fetch_assoc() on line #2. This is because each time you fetch a row with mysqli_fetch_*() it'll return the next row in the result set. What is the purpose of this code? Is so you can edit multiple records at the same time? If this is the case then you'd setup your form differently. I'd set the record id as the key to foto[]. Example code $sql = mysqli_query($link, "SELECT * FROM foto"); echo "<form method=\"POST\">"; while ($row = mysqli_fetch_assoc($sql)) { echo "<p>#{$row['id']} <input type=\"text\" name=\"foto[{$row['id']}]\" value=".htmlspecialchars($row['foto'])." /></p>"; } echo "<input type=\"submit\" name=\"submit3\" value=\"update\" /> </form>"; To update all records your code would be if(isset($_POST['submit3'])) { $stmt = mysqli_prepare($link, 'UPDATE foto SET foto=? WHERE id=?'); mysqli_stmt_bind_param($stmt, 'is', $row_id, $row_value); // bind id and foto value foreach($_POST['foto'] as $row_id => $row_value) { mysqli_stmt_execute($stmt); // update row } }
  12. @adam I agree with points 1, 3 and 4. But point2 I do not see your comment about oop being relevant to the OP's code. @Augury. You are defining a function within a condition. The checkinput() function will only be defined when a POST request is made. If no post request is made then your code will produce a fatal error as it is calling a function which is not defined. Your logic here is reversed. What you should be doing is defining the function first, but only call that function when a POST request is made // define function function checkinput($args...) { // function code } // call function on post request if ($_SERVER["REQUEST_METHOD"] == "POST") { checkinput($args...); } As adam mentioned you are using return incorrectly and using it without understanding its behaviour. If you use a variable with return, it does not mean it returns that variable and then allows you to use that variable outside of the function. What it will do is return the value of that variable. It'll also immediately terminate the execution of that function at the point it is used. Also I dont think using a regex pattern for matching urls is a good idea for validating passwords. As soon as you get the users password you should be encrypting it.
  13. This code here sets the text for the body of the email $email_message .= "Full Name: ".clean_string($name)."\n\n"; $email_message .= "Address: ".clean_string($address)."\n\n"; $email_message .= "Email ID: ".clean_string($email)."\n\n"; $email_message .= "Contact No.: ".clean_string($contact)."\n\n"; $email_message .= "File: ".clean_string($upload)."\n\n"; Place $email_message .= "your email disclaimer text\n\n"; Where the client wants the disclaimer to appear. So if it is after the Address, then add the line of code above after the Address line. What? I do not understand.
  14. Look at ignaces code again. You have not called http_json_post(). You should be passing $url as the first argument and then $data as the second argument. $result should then contain the json returned from your api. To convert the json into an array use json_decode
  15. We cannot help you if you do not provide information on the API you are trying to use. Maybe you should ask your work colleage for this information. Spamming this thread with random bits of code which you obviously have no idea what they do is not helping your situation.
  16. You only want to perform a search on a the database when a POST request is made. if($_SERVER['REQUEST_METHOD'] == 'POST') { // get user input // perform database search // check for results if(mysql_num_rows($result) > 0) { // display results } else { // no results display message here } } // display search form You'll need to output the relevant html for this. Example code for a simple JavaScript alert window echo "<Script>alert('No results to display');</script>";
  17. You need wrap it within an anchor tag. Also note variables are expanded within double quotes so you dont need to concatenate them echo "<tr> <td>$University</td> <td>$NameOftheProgram</td> <td><a href=\"$Website\">$Website</a></td> <td style='width: 100px;'>$state</td> <td style='width: 300px;'>$city</td> <td>$career</td> <td>$graduatelevel</td> </tr>"; Use mysql_num_rows to check how many results where returned if(mysql_num_rows($result) > 0) { // code for displaying results } else { // no results display message here echo 'No results to display'; }
  18. Dont pass $results to mysql_error(). echo mysql_error();
  19. Thought of using the HTML5 placeholder attribute instead. But to answer you question you need to call the blankTrackingNumber on the focus event not keydown event <script> function displayTrackingNumber() { console.log(document.getElementById('cboOrderStatus').value); if (document.getElementById('cboOrderStatus').value == 'Shipped') { document.getElementById('txtTrackingNumber').style.display = ''; document.getElementById('txtTrackingNumber').focus(); } else { document.getElementById('txtTrackingNumber').style.display = 'none'; } } function blankTrackingNumber(elm) { if(elm.value == elm.defaultValue) { elm.value =''; } } function checkTrackingNumber(elm) { if(elm.value == undefined || elm.value =='' || elm.value == elm.defaultValue) { alert("Please enter a Tracking Number!"); elm.value = elm.defaultValue; } } </script> <body onload="displayTrackingNumber()"> <form> <input type="text" id="cboOrderStatus" name="cboOrderStatus" value="Shipped" /> <input name="txtTrackingNumber" id="txtTrackingNumber" value="Tracking Number" style="display:none" onfocus="blankTrackingNumber(this)" onblur='checkTrackingNumber(this)' /> </form> </form>
  20. You haven't applied strtolower to $tintensity[$k] for the switch condition // pass in storm intensity for current storm switch($tintensity[$k]) // it should read switch(strtolower($tintensity[$k])) EDIT Just looked at your data file, try applying trim too. White space maybe included switch(strtolower(trim($tintensity[$k])))
  21. See Handling file uploads in the PHP manual Copy the disclaimer text and assign it to a variable, and then concatenate that onto $email_message $diclaimerText = 'your disclaimer'; ... $email_message .= "--------------------------------\n\n$disclaimerText"; // append disclaimer to email
  22. Instead of using document.<?=$counter?> in OnMouseOver/Out use this <a href=" my file..." target="popup" onclick="msgopen('my file ...'); return false;" /> <img src="<?=$pic_name?>" name="<?=$counter?>" onMouseOver="this.src='<?=$pic2name ?>'; return escape('Image is of Parent Stock Only';" onMouseOut="this.src='<?=$pic_name?>';"> </a>
  23. @Texan78 Looking at your code in post #10. You need to use the switch statement for choosing the color of the storm intensity within the foreach loop on line 148, You'd pass strtolower($tintensity[$k]) as the condition and do a string replacement on the value of $intStyle replacing color: #FFF with color: $stormIntensity to colorize the storm intensity text Code for the foreach loop (line 133) // create your loop foreach($tid as $k => $v){ // pass in storm intensity for current storm switch(strtolower($tintensity[$k])) { case 'weak': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 0, 0)'; break; case 'severe': $stormIntensity = 'rgb(217, 0, 126)'; break; } // replace default color with $stormIntensity $intStyleCSS = str_replace('color: #FFF;', "color: $stormIntensity;", $intStyle); $tracreport .= "<tr> <td style='{$tr2Style}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . " °</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intStyleCSS}'>" . strtolower($tintensity[$k]) /* $intSyleCSS applies the css for each storm */ . "</td> <td style='{$tr2Style}'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . trim(strtolower($tactivity[$k])) . "</td> </tr>"; } // close your loop Also remove color: ' . $stormIntensity . ' from line18 so it is $intStyle = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;";
  24. What is $_POST['donor_id']? There does not appear to be field with that name in your form. If it is an auto-increment field then you do not need to reference it in the insert query. You only need to reference the fields you're adding the values to.
  25. I wouldn't of thought so. Just make sure in events.php it is strickly outputting the json, and not any text/html as well. To check this open up http://localhost/events/events.php and right click > view source what is displayed? There should only be the json encoded array and nothing else.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.