Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. I assume you are using this echo "<option value=''>$title</option>"; to have the users title selected by default. Although you may think this works what is infact happening is because you have used an empty value='' attribute in that option tag it will be overriding the title value to null when the form is submitted. Thus why the title is being changed to null in the database This is not the correct way of setting a default value for a drop down. What you should do apply the selected attribute to the option tag where the title matches the value in the database. The following is is how I would of generated the title options (I assume $rE['cust_title'] contains the users title returned by your query). <select id="custitle" name="custitle" style="height:30px;width:188px"> <?php // define each title in an array $titles = array('', 'MS', 'Mrs', 'Mr', 'Miss', 'Master'); // loop over the array of titles foreach($titles as $title) { // if the current title matches the title in the database then apply the selected attribute to the option // this will have that option selected by default when the form loads $selected = (isset($rE['cust_title']) && $rE['cust_title'] == $title) ? ' selected="selected"' : ''; // generate the html option tag dynamically echo '<option'.$selected.'>'.$title.'</option>'; } ?> </select>
  2. Set the value attribute for the input field to your date value, examples <input type='text' class="form-control" value="05/09/2015" /> <input type='text' class="form-control" value="<?php echo $your_date_variable_here" /> To format the date to use $('#datetimepicker1').datetimepicker({ format: 'DD/MM/YYYY', }); if you still want the the time then append the format string with ' HH:mm:ss' (without the quotes)
  3. Define the user array at the start of the function. Then overwrite the $user array with the result from the database if one was returned public function editRecord() { // default user array $user=array('id'=>0,'firstname'=>'','lastname'=>'','username'=>'','access_id'=>10); $id= isset($_GET['id']) ? $_GET['id'] : null; if(!is_null($id)) { $sql='SELECT id,firstname,lastname,username FROM users WHERE id=? AND sites_id=?'; $stmt = $this->db->prepare($sql); $stmt->execute(array($id,$this->site->id)); // if query returned a result, override $user array if($stmt->numCount() != 0) $user = $stmt->fetch(PDO::FETCH_ASSOC); } $this->displayPage(__DIR__.'/templates/editRecord.html',array('user'=>$user,'access'=>$this->getList('access'))); }
  4. We need to look at the code that processes the login . Usually when you have authorized a user you set a "logged in" flag in the session. Each user has their own private session (that is how PHP sessions work). To determine if the user is logged in your check to see if the "logged in" flag exists. That is the very basic for a login system.
  5. Then move your code logic that processes the login to be in index.php I assume by that you want to stay on home.php when logging out, then change window.location="../zibika/index.html"; to point to home.php
  6. My bad 'eno' in the query should off been '$eno'. In fact, if eno should be a number then validate that it is number first This is an example of how you should be sanitize/validate your data before using it in your query <?php $user_name = "ganga"; $password = "gangamma"; $database = "ganga"; $server = "localhost"; $conn = mysql_connect($server, $user_name, $password); mysql_select_db('ganga',$conn); // check a post request has been made before using $_POST values if($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // check eno isset and is has a numeric value (is a number) if(isset($_POST['eno']) && is_numeric($_POST['eno'])) { // cast value to an interger (whole number) $eno = intval($_POST['eno']); } // eno is not set, or is not a numberic value else { // set error message $errors[] = 'eno must be a number'; } // check ename isset and is not an empty value if(isset($_POST['ename']) && !empty($_POST['ename'])) { // sanitize $ename = mysql_real_escape_string($_POST['ename']); } // ename is not set, or is empty else { // set error message $errors[] = 'ename cannot be empty.'; } // if there are no errors after validation, then insert data into database if(empty($errors)) { $sql = "INSERT INTO `ganga`(`eno`, `ename`) VALUES ($eno, '$ename')"; $retval = mysql_query( $sql, $conn ); if($retval) echo "Entered data successfully\n"; } // there are are errors else { // display error message(s) echo "Invalid data provided:<br />" . implode('<br />', $errors); } }
  7. Are you saying you want to login from index.php but do not want to be redirected to home.php when the form is submitted?
  8. So you are logging into one user account then once logged in signing into another account in the same browser? Then yes this will happen. This is why websites make you logout when you want to login in as a different user. If you are testing your site with different user accounts being signed in at the same time then I suggest you use a different web browser (or computer) for each user you are signed in as.
  9. What ginerjm is referring to is this (highlighted in red) <option value="first_name:" ><?php echo($row['first_name']) , ' ', ($row['last_name']);?></option> This is given all the names in your select menu the same value when the form is submitted. If you want the persons name to be submitted then remove the value attribute from the option tag.
  10. Make sure you are calling [m]session_start[m] on all pages that use sessions. Also make sure you are starting the session before using any $_SESSION variables. Without seeing your code I cant suggest a fix.
  11. Never use raw $_POST variables in your query. You should sanitize them before using them. $eno = mysql_real_escape_string($_POST['eno']); $ename= mysql_real_escape_string($_POST['ename']); $sql = "INSERT INTO `ganga`(`eno`, `ename`) VALUES ('eno','$ename')"; Another thing you should be doing is to validate them. You should check they exists and are in the format your expect. NOTE: the mysql_* functions are deprecated, meaning they are not longer supported and could soon be removed complete from future version of PHP. I recommend you to use either PDO or MySQLi instead.
  12. Make sure you are running that command as Administrator (Right click cmd.exe run as Administrator). Note it only removes the Apache service. If you gave the Apache service a different name on install then you need to specify the service name with the -n flag httpd.exe -n "Apache Service Name" -k uninstall Otherwise to remove Apache you can safely delete the Apache install folder (provided Apache is not running)
  13. Do you mean you want to have a page range? If so check out our pagination tutorial (note needs updating to use mysqli). Example $currentpage = isset($_GET['page']) ? $_GET['page'] : 1; $results_per_page = 20; $sql = "SELECT * FROM images"; $rs_result = mysqli_query($con, $sql); $total_records = mysqli_num_rows($rs_result); $total_pages = ceil($total_records / $results_per_page); // range of num links to show $range = 3; echo "<a href='index.php?page=1'><button>First page</button></a> "; // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $total_pages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <b>$x</b> "; // if not current page... } else { // make it a link echo " <a href='index.php?page=$x'><button>$x</button></a> "; } // end else } // end if } // end for echo " <a href='index.php?page=$total_pages'><button >Last page</button></a>";
  14. $gameQuery['response'] ['total_count'] will only return the total count from here "total_count": 4, which is four To get the games you want to use $gameQuery['response'] ['games'], Preferably use a foreach loop to iterate over each game. Example $gameQuery = json_decode($gameInfo, true); echo "Total Games: " . $gameQuery['response'] ['total_count'] . "<br />\nThese are:<br />\n"; foreach($gameQuery['response']['games'] as $gameInfo) { // playtime_forever returns total time game has been played in minutes, // divided by 3600 to convert to hours $hoursPlayed = ceil($gameInfo['playtime_forever'] / 3600); echo "<p><b>" . $gameInfo['name'] . "</b> - Hours played: $hoursPlayed</p>\n"; }
  15. Locked. You already have a topic open discussing the same issue.
  16. What do you mean "a lot of data". MySQL and PHP are pretty efficient when handling lots of data. If you are getting a timeout then there is most likely something in your code which is slowing it to down, worst case being an infinite loop.
  17. It is not recommended to run two separate queries. If you have data stored in both tables which relates then you should use a join. Example SELECT s.SName, s.Symbol, c.`Primary Completion Date` FROM Stocks s LEFT JOIN Calendar as c USING(SName) Also try not to have spaces in table names, either use camelcase or underscores.
  18. Output the files in a ordered list? echo "<ol>\n"; foreach($descriptions as $fileName=>$description) { $likes = readAfterColon($description); echo "\t<li>$fileName has $likes likes</li>\n"; } echo "</ol>\n"; Or use a counter $i = 0; foreach($descriptions as $fileName=>$description) { $likes = readAfterColon($description); echo ++$i . ") $fileName has $likes likes<br />\n"; }
  19. Does you hosting package not come with emails? You should be able to create email accounts from your ISP's control panel.
  20. This in $array = ""; in unicode_string_to_array function is causing $array to be a string, not an array. It should be initialized using $array = array();
  21. Change the smpt settings, here $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'bradvisor15@gmail.com'; $mail->Password = 'password'; to use the account for contact@bradvisor.com
  22. You are getting that notice because there is not a array index 3 in $alloweddomains. This is because your for loop is most likely iterating one too many times, due to you adding one to $domains in the condition. If $alloweddomains is an array, then use a foreach loop instead // loop over each allowed domain foreach($alloweddomains as $domain) { if((stristr($_SERVER['HTTP_REFERER'], $domain))) { $allowed = 1; } } You are getting that notice because $contents is an empty string. What type of value should $contents be?
  23. On line 16 change $tag to $_POST['tag'] Line 152 send_mail should be send_email
  24. When you go to delete-customers.php are clicking the browsers back button? If so that maybe be why, the browser will be loading your listing from the browser cache. You should either have the user click a link to go back to your listing page or use header('Location: ...listingpagehere....); to redirect user back to the listing
×
×
  • 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.