Jump to content

angel1987

Members
  • Posts

    63
  • Joined

  • Last visited

Posts posted by angel1987

  1. I have been searching on internet for quite a while now for the query, tried many but none work, so i am resorting to asking myself.

     

    I have a table column with type varchar that stores date in format mm-dd-yyyy. I need to fetch all records from this table with the dates within next 4 days (between today and next 4 days).

     

    Also, i am using mysqli prepared statements to fetch this record.

     

    Below is the query which i tried, it works but not accurately.

    if ($stmt = $mysqli->prepare("SELECT names FROM members WHERE birthdate - INTERVAL 4 DAY > NOW() AND gender = ?")) {

    The above query displays records with dates after 4 days from today. I tried changing combinations for + - > and < like i had no idea what i was doing but each combination gave funny results.

     

    Has anyone tried this or knows how to do it? Please help me with this query, thanks in advance for your help.

  2. I noticed a bug in my script and i have been searching a lot on internet since past few hours but i could not find any information or solution. The script runs fine, no errors, but the script does not fetch last row/entry. Example, if there are 3 rows in the table, my script only pulls 2 rows. If there are 10, then only 9 are fetched. Please help me find the bug.

     

    Here is my script...

    <?php
    $query = "SELECT * FROM members WHERE $condition_res ORDER BY id DESC LIMIT $startpoint, $limit";
    $result_query = mysqli_query($mysqli, $query);  
    
    while($row = @mysqli_fetch_assoc($result_query)) {
         $mid=$row["id"];
         $member=$row["name"];
         $gender= $row["gender"];
    ?>
           <tr>
               <td><?php echo $mid; ?></td>
               <td><?php echo $member; ?></td>
               <td><?php echo $gender; ?></td>
           </tr>
    <?php } ?>

    Note: $startpoint and $limit variables are for Pagination. $condition_res is for search criteria.

  3. Hello All, I am creating an image sharing platform for our local community and i need to know if there is any standards for resizing images in PHP?

     

    I mean how does bigger image sharing websites like imgur, flickr, etc resize their images? Also, there are already many small PHP scripts/functions available on internet to generate thumbnails or resize images on the go or while uploading, but i am not sure if we can use those for a website focused solely on images, can we?

     

    I will have to resize larger dimension images into smaller images while maintaining its quality. I am also aware of ImageMagicks and GDLibrary

     

    So, can anybody guide me or give me some information or suggest me on how to go about it? Thanks in advance for advice.

  4. Hello all, I have been searching for hours on google for answer but i couldnt find anything. So i have this "edit your post" form which is a set of text fields, text area, radio buttons and two datepicker calendar fields.

     

    I am getting the data from the MySql table to display it in these form fields and the submit button will simply fire Update query. But the problem is that when i add datepicker JQuery to this form, it does not display any values in the text fields from database but only in textarea box.

     

    Below is the JQuery script that i am using...

     

    <link rel="stylesheet" href="css/themes/base/jquery-ui.css" />
    
    <script src="js/jquery-1.9.1.js"></script>
    <script src="js/ui/jquery-ui.js"></script>
    
    <script>
    $(function() {
    $( "#datepicker" ).datepicker();
    $( "#datepicker2" ).datepicker();
    });
    </script>
    

    This is the form that is supposed to display values from database table. When i remove the above Javascript, it works. And when i use the above script, it shows values as Undefined for all the textfields.

    <form name="frmPost" method="post" action="">
    	<table border="0" cellpadding="5" cellspacing="5">
    		<tr><td>Title : </td></tr>
    		<tr><td><input type="text" name="txttitle" size="75" value="<?php echo $title; ?>"/></td></tr>
    		
    		<tr><td valign="top">Description : </td></tr>
    		<tr><td><textarea name="txtdescription" rows="10" cols="75" ><?php echo $description; ?></textarea></td></tr>
    		
    		<tr><td>Listing End date : </td></tr>
    		<tr><td><input type="text" name="txtenddate" value="<?php echo $enddate; ?>" id="datepicker"/></td></tr>
    			
    		<tr><td>Project Completion Dead line : </td></tr>
    		<tr><td><input type="text" name="txtdeadline" value="<?php echo $deadline; ?>" id="datepicker2"/></td></tr>
    		
    		<?php if($ptype=='w') { ?>
    		<tr><td>
    			<input type="radio" name="txttype" value="w" checked> Web Based
    			<input type="radio" name="txttype" value="s">Desktop Based
    		</td></tr>
    
    		<?php } else if($ptype=='s') { ?>
    		<tr><td>
    			<input type="radio" name="txttype" value="w">Web Based
    			<input type="radio" name="txttype" value="s" checked>Desktop Based
    		</td></tr>
    
    		<?php } else { ?>
    		<tr><td>
    			<input type="radio" name="txttype" value="w">Web Based
    			<input type="radio" name="txttype" value="s">Desktop Based
    		</td></tr>
    		<?php }	?>
    
    		<tr><td><input type="submit" name="btnupdate" value="Update" class="button" /></td></tr>
    	</table>
    </form>
    

     

    I need some help in fixing this.

     

  5. Thanks for the support teynon, i had already tried using your first fix but it didnt work but yes the problem was with the javascript.

     

    I was hashing the password by javascript before sending it to the PHP script but it seems that works only if your PHP processing script is on another file and not on the same page.

     

    So i removed onclick attribute from submit button and hashed the password using PHP and it worked perfectly.

  6. Hello all, i have a change your password feature on one of my websites. It works perfectly in FF and Chrome but it is not working in IE 8. I have used MySQLi prepared statements and the script is fairly straight forward. In IE 8 when i click on submit button, it kills the session and gives "you are not authorized to view this page message". So I need some help in solving it.

     

    Below is the HTML form.

    <form name="frmcp" method="post" action="#">
    	<table border="0" cellpadding="5" cellspacing="5">
    		<tr><td>Old Password</td></tr>
    		<tr><td><input type="password" name="password" id="password" /></td></tr>
    		<tr><td>New Password</td></tr>
    		<tr><td><input type="password" name="txtpass1" /></td></tr>
    		<tr><td>Confirm Password</td></tr>
    		<tr><td><input type="password" name="txtpass2" /></td></tr>
    		<tr><td><input type="submit" name="btncp" value="Change Password" class="button" onclick="formhash(this.form, this.form.password);" /></td></tr>
    	</table>
    </form>
    

    Below is the PHP Script which is on the same page above the html open tag.

     

    <?php
    // Include database connection and functions here.
    include '../php/config.php';
    include 'php/functions.php';
    
    //Securely Start Session
    sec_session_start();
    
    //Check if user is logged in or not
    if((login_check($mysqli) == true) && $_SESSION['usertype'] == 0) { 
    $userid = $_SESSION['user_id'];
    
    	// Check if the button was clicked or not.
    	if(isset($_POST['btncp'])){  
    	
    		//Check if all fields are filled.
    		if(isset($_POST['txtpass1']) && !empty($_POST['txtpass1']) AND isset($_POST['txtpass2']) && !empty($_POST['txtpass2'])){  	
    
    		$newpass = htmlspecialchars(strip_tags($_POST['txtpass1']));
    		$newpass = hash('sha512', $newpass);
    		
    		$newcpass = htmlspecialchars(strip_tags($_POST['txtpass2']));
    		$newcpass = hash('sha512', $newcpass);
    		
    		//Check if new password matches the confirm password or not.
    		if($newpass == $newcpass){
    		
    		$password = $_POST['p'];
    		
    			//Check if the old password entered is correct or not.
    			if ($stmt = $mysqli->prepare("SELECT username, password, usertype, salt FROM active_users WHERE user_id = ? LIMIT 1")) { 
    			 $stmt->bind_param('i', $userid); // Bind "$email" to parameter.
    			 $stmt->execute(); // Execute the prepared query.
    			 $stmt->store_result();
    			 $stmt->bind_result($username, $db_password, $usertype, $salt); // get variables from result.
    			 $stmt->fetch();
    			 $password = hash('sha512', $password.$salt); // hash the password with the unique salt.
    			    
    				if($stmt->num_rows == 1) { 
    					if($db_password == $password) { 
    
    						//Hash the new password with a new randomly created salt.
    						$new_random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));		
    						$new_db_password = hash('sha512', $newcpass.$new_random_salt);
    								
    						//Update new password in the table.
    						if ($stmt = $mysqli->prepare("UPDATE active_users SET password = ?, salt = ? WHERE user_id = ?")) {
    					   		// Bind the variables to the parameter as strings. 
    						    	$stmt->bind_param("ssi", $new_db_password, $new_random_salt, $userid);
    						    	// Execute the statement.
    						    	$stmt->execute();
    						    	// Close the prepared statement.
    				    			$stmt->close();
    			 			}
    
    						//Redirect if password was changed and ask the user to login again using new password.									
    						header('Location: error.php?error=5');
    									
    					}
    					else {
    						$msg = 'Old password entered is incorrect.';
    					}
    				}
    				else {
    					$msg = 'User Does Not Exist.';
    				}
    			}
    		}
    		else {
    			$msg = 'New Password and Confirm Password does not match.';
    		}
    	}
    	else {
    		$msg = 'All fields are mandatory.';
    	}
    
    }  
    
    ?>
    
    

    The problem appears to be in the line where PHP checks if the button was clicked or not or in the line where it checks if user is logged in or not. But it works in FF and Chrome, just not in IE 8.

  7. I have a web page that lets user upload their profile photo. The PHP script works, but sometimes it just wont upload the photo. It will even give you a success message that the image was uploaded but it wont add the filename to the database nor will it save the file on the server. If you keep trying to upload the same image for couple more times then it will work and upload the photo. So i need some help in debugging it. Where am i going wrong? I am also using this thumb_function.php file which i got from internet, it basically saves thumbnails in a seperate folder, it works fine.

     

    Here is the PHP script that i am using.

     

    // Check if the button was clicked or not and process the profile updation
    if(isset($_POST['btnphoto'])){
    
    include('php/thumb_function.php');
    
    $filename = $_FILES["txtphoto"]["name"];
    $newfilename = sha1($userid.$email);
    $extension = substr(strrchr($filename,'.'),1);
    $newfilename = $newfilename.".".$extension;
    $allowedExts = array("jpg", "jpeg", "gif", "png");
    
    if ((($_FILES["txtphoto"]["type"] == "image/gif")
    || ($_FILES["txtphoto"]["type"] == "image/jpeg")
    || ($_FILES["txtphoto"]["type"] == "image/png"))
    && ($_FILES["txtphoto"]["size"] < 1048576)
    && in_array($extension, $allowedExts)){
    
     if ($_FILES["txtphoto"]["error"] > 0){
     $msg = "Error: " . $_FILES["file"]["error"] . "<br>";
     }
     else {
    $path="../photos/".$newfilename; // the path with the file name where the file will be stored, upload is the directory name.
    
     if(move_uploaded_file ($_FILES["txtphoto"]["tmp_name"],$path)){
    
     if ($stmt = $mysqli->prepare("UPDATE student_profile SET photo = ? WHERE user_id = ?")) {
    	 // Bind the variables to the parameter as strings.
    	 $stmt->bind_param("si", $newfilename, $userid);
    	 // Execute the statement.
    	 $stmt->execute();
    	 // Close the prepared statement.
    	 $stmt->close();
     }
    
     $msg = 'Your Photo has been updated... ';
    }
    
    else {
     $msg = 'Failed to upload file Contact Site admin to fix the problem';
     exit;
    }
    
     $file = $newfilename;
     $save = $file;
     $t_w = 100;
     $t_h = 100;
     $o_path = "../photos/";
     $s_path = "../photos/thumbnails/";
     Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);
    }
    
    }
    else {
    $msg = 'File is of a wrong type or too heavy.';
    }
    }
    

     

    Here is the HTML form code..

     

    <form name="frmphoto" method="post" action="" enctype="multipart/form-data">
    <table border="0" cellpadding="5" cellspacing="5">
    <tr><td>Upload Profile Photo : </td></tr>
    <tr><td><input type="file" name="txtphoto" size="45"></td></tr>
    <tr><td><input type="submit" name="btnphoto" value="Update Photo"></td></tr>
    </table>
    </form>
    

  8. I tried searching on google but couldn't find any relevant information, please redirect me to relevant source or help me with the code.

     

    I want to pass a domain name in text field which will be scanned and then the script will display entire site map.

     

    Not external links or links on a page. Sorry it is not easy for me to explain.

     

    Eg. if i pass abc.com

     

    Script will display

     

    abc.com/12/adn.php

    abc.com/asd/asd/

    etc

     

    Whatever their url format is.

     

    All the links on that domain.

  9. I know the regular database connection, but this time i am provided with the SSH details.

     

    This guy game me the IP address of the database server to connect and 2 login details.

     

    SSH: Username and Password

     

    DB: Username and Password

     

    And i am using XAMPP for trying out the code.

     

    Is there any plugin i need to download for SSH connections?

     

    Could you please give me the connection snippet for SSH because i don't really know how to do that, i am also searching elsewhere on internet.

     

    Thanks in advance for help...

  10. No, the table column is not of DATE TIME type, i had set it as text because when i do it, it stores the date value as 0000-00-00 00:00:00 and it also replaces the previously stored values of date into 0000-00-00 00:00:00.

     

    I may be going wrong, i think i need to set a correct format for

    $subon = date("F j, Y, g:i a");

    do i?

     

    Can you please help me with it?

     

    And this may be a bit dumb to say but since its a PHP function for date and time, it should work whatsoever right?

     

    Thanks again,

  11. I need to display the last 30 days entries from database in PHP and here is the code that i am currently using, but its not working.

     

    While entering the data in database, the date format that i am using is this...

    $subon = date("F j, Y, g:i a");

     

    And to display the code i am using this query...

    $start_date = date("F j, Y, g:i a", strtotime('-30 days'));
    $curr_date = date("F j, Y, g:i a");
    $sql = "SELECT * FROM table WHERE status = 'approved' AND subon BETWEEN '$start_date' AND '$curr_date' ORDER BY ID DESC LIMIT 0, 5";

     

    And then i am using the usual stuff to display the data but its not working.

     

    Somebody please help me... Thanks in advance.

  12. I have been searching on google for a while, but i couldn't find it. So i thought may be you could direct me to some tutorial or steps if you knew.

     

    Basically, i am working on a articles directory and the big text area where the main article will be entered, i want to allow all the links (link tag) on it but not any other html tags.

     

    Currently i am using strip tags and so its cutting down the tags and all the links are being displayed naked on it.

     

    So can you please tell me how do i do it?

     

    Thanks..

  13. Hello all, i am a newbie in php and i am trying to learn things from internet and this forum. I already did a search and read some things on arrays but i am unable to fix this small script.

     

    Here is the script.

     

    <?php
        $sourceURL = $link;
        $metaData = get_meta_tags($sourceURL);
    while (list($key, $val) = each($metaData))
      {
      echo "$key => $val<br />";
      }
        var_dump($metaData);
    ?>

     

    The above code gets the meta section of the link passed to it.

     

    And it displays the results as...

     

    title => The Internet Movie Database (IMDb)

    description => IMDb: The biggest, best, most award-winning movie site on the planet.

    keywords => movies,films,movie database,actors,actresses,directors,hollywood,stars,quotes

    application-name => IMDb

    msapplication-tooltip => IMDb Web App

    msapplication-window => width=1500;height=900

    msapplication-task => name=Sign-in;action-uri=/register/login;icon-uri=http://i.media-imdb.com/images/SFff39adb4d259f3c3fd166853a6714a32/favicon.ico

    array(7) { ["title"]=> string(34) "The Internet Movie Database (IMDb)" ["description"]=> string(69) "IMDb: The biggest, best, most award-winning movie site on the planet." ["keywords"]=> string(77) "movies,films,movie database,actors,actresses,directors,hollywood,stars,quotes" ["application-name"]=> string(4) "IMDb" ["msapplication-tooltip"]=> string(12) "IMDb Web App" ["msapplication-window"]=> string(21) "width=1500;height=900" ["msapplication-task"]=> string(126) "name=Sign-in;action-uri=/register/login;icon-uri=http://i.media-imdb.com/images/SFff39adb4d259f3c3fd166853a6714a32/favicon.ico" }

     

    So instead of all the data showing up above, how can i just display the clean values for keywords, title and description in three different text fields respectively? Please help.

  14. Hello,

     

    I am trying to create article directory for learning PHP MySql and i want to write a script for recording number of views for an article and store it in Database. Can anyone please direct me to a nice simple tutorial or help me with the steps or algorithm?

     

    Suppose the link for an article is http://www.domain.com/article.php?id=123

    Do i need to put extra variables and create a tracking PHP file for it?

  15. Thanks for the answers,

    htmlspecialchars()

    worked.

     

    But is there anything else that i need to know? Just as an information to prevent issues related to other special characters that might be used for HTML or SQL injections or just to mess with the applications?

     

    I need the script to function perfectly, so is there anything i need to add while adding or displaying the data? Thanks again.

  16. Ok, Here is the HTML output of the script

     

    <div id="menu14">
    <ul>
    
    <li>
    <div style="float: left; vertical-align: middle; padding-top: 8px; padding-left: 8px;">
    <img src="img/842199223art%20.jpg" border="0"> 
    </div>
    <a href="category.php?id=44" title="Link 1">Arts and Print</a>
    </li>
    
    <li>
    <div style="float: left; vertical-align: middle; padding-top: 8px; padding-left: 8px;">
    <img src="img/877000559auto%20car.jpg" border="0"> 
    </div>
    <a href="category.php?id=48" title="Link 1">Auto and Car</a>
    </li>
    
    <li>
    <div style="float: left; vertical-align: middle; padding-top: 8px; padding-left: 8px;">
    <img src="img/514979454bank.jpg" border="0"> 
    </div>
    <a href="category.php?id=45" title="Link 1">Bank and Finance</a>
    </li>
    
    </ul>
    </div>
    

  17. This is more like a PHP and CSS based question for a very simple application i am trying to create for learning php.

     

    Basically, i am adding categories from admin section and it also has a file upload thing to upload a small icon for that category.

     

    These categories are displayed vertically on left sidebar along with its icon image just like on yahoo homepage.

    I am using a CSS menu script for that which i got from internet. The problem is, at first it displayed perfectly, icon on left and text next to it.

     

    But then it suddenly got messed up and nothing is showing up correctly. Here is the CSS code for how the list is displayed.

     

    <div id="menu14">
    <ul>
    
    <?php
    $sqlcat = "SELECT * FROM categories WHERE type = 'main' ORDER BY name";
    $resultcat = @mysql_query($sqlcat) or die(mysql_error());
    while($rowscat = @mysql_fetch_array($resultcat)){
    ?>
    
    <li>
    <div style="float:left; vertical-align:middle; padding-top:8px; padding-left:8px;">
    <img src="img/<?php echo $rowscat['icon']; ?>" border="0" /> </div>
    <a href="category.php?id=<?php echo $rowscat['ID']; ?>"><?php echo $rowscat['name']; ?></a>
    </li>
    
    <?php } ?>
    
    </ul>
    
    </div>
    

     

    I am attaching before and after screenshots of the menu.

     

    I don't know what is wrong because at first on localhost it displayed perfectly, just fine.

    Can you pleaseeeeeee help me get it correct...

     

     

     

    [attachment deleted by admin]

×
×
  • 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.