Jump to content

Ancoats

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Ancoats's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys I have a problem, basically I have a content area which spits out some PHP code from a database (name and picture) and the code I have used for this which shows the results <?php //call name and member pic from memberprofile table $sql = "SELECT * FROM memberprofile ORDER BY memberID"; $result = mysql_query($sql); $rows = mysql_num_rows($result); $i = 0; //get all rows while ($i < $rows) { $memberID = mysql_result($result, $i, "memberID"); $firstname = mysql_result($result, $i, "firstname"); $lastname = mysql_result($result, $i, "lastname"); $userPic = mysql_result($result, $i, "imagefile"); //echos the results echo "<h3>$firstname $lastname</h3>\n"; //echo "<p>Last Name: $lastname</p>\n"; echo "<p><a href=\"viewprofile.php?profile=$memberID\"><img src=\"$userPic\" border=\"0\"></a></p>\n"; //echo $userPic; $i ++; } ?> Now, using increments, the data is displayed on individual lines and puts my page pagination out of whack, and I want a row of '3 individual' profiles to be displayed before a next row of 3 profiles, rather the current one row of one profile. How would I do this? is this a CSS or PHP issue?
  2. the rest of the lines are html code... however the full page code is: <?php //start the session session_start(); if(!isset($_SESSION['isloggedin'])){ header("Location:index.php"); } //connect to database include ('includes/db.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <a href="loggedin.php">Back to Main Page</a><br /> <a href="profile.php">View Profile</a><br /> <a href="logout.php">Logout</a><p> This is where you can edit your profile <?php echo $_SESSION['isloggedin']; ?>! </head> <body> <?php //reference the ismember session $memberID = $_SESSION['ismember']; // form validation if (isset($_POST['psubmit'])){ $firstname = trim($_POST['firstname']); if (strlen($firstname) < 3 || strlen($firstname) > 20) { $error[] = 'name must be between 3 and 20 characters.'; } $lastname = trim($_POST['lastname']); if (strlen($lastname) < 3 || strlen($lastname) > 20) { $error[] = 'last name must be between 3 and 20 chars'; } $userDOB = trim($_POST['userDOB']); if (strlen($userDOB) < 3 || strlen($userDOB) > 20) { $error[] = 'date of birth must be between 3 and 20 chars'; } $userGend = trim($_POST['userGend']); if (strlen($userGend) < 3 || strlen($userGend) > 20) { $error[] = 'Gender must be between 3 and 20 chars'; } $userLoc = trim($_POST['userLoc']); if (strlen($userLoc) < 3 || strlen($userLoc) > 255) { $error[] = 'Location must be between 3 and 255 chars'; } $userInt = trim($_POST['userInt']); if (strlen($userInt) < 3) { $error[] = 'Interests must be more than 3 characters'; } $userDesc = trim($_POST['userDesc']); if (strlen($userDesc) < 3) { $error[] = 'Description must be more than 3 characters'; } // if validation is ok, carry on if(!isset($error)) { //post form data $firstname = trim($_POST['firstname']); $lastname = trim($_POST['lastname']); $userDOB = trim($_POST['userDOB']); $userGend = trim($_POST['userGend']); $userLoc = trim($_POST['userLoc']); $userInt = trim($_POST['userInt']); $userDesc = trim($_POST['userDesc']); //escapes data is magic quotes are disabled on the server if(!get_magic_quotes_gpc()) { $firstname = addslashes($firstname); $lastname = addslashes($lastname); $userDOB = addslashes($userDOB); $userGend = addslashes($userGend); $userLoc = addslashes($userLoc); $userInt = addslashes($userInt); $userDesc = addslashes($userDesc); } //update the member profile already contained in the database $query = "UPDATE memberprofile SET firstname = '$firstname', lastname = '$lastname', userDOB = '$userDOB', userGend = '$userGend', userLoc = '$userLoc', userInt = '$userInt', userDesc = '$userDesc' WHERE memberID = '$memberID' "; mysql_query($query) or die('Error : ' . mysql_error()); echo "<p>member profile updated</p>"; } //close errors } //close if form has been sent //display any errors errors($error); $result = mysql_query("SELECT firstname, lastname, userDOB, userGend, userLoc, userInt, userDesc FROM memberprofile WHERE memberID = '$memberID' ")or die(mysql_error()); $Rows = mysql_num_rows($result); while ($row = mysql_fetch_object($result)) { ?> <form action="<?php echo $dir;?>editprofile.php<?php echo $row->memberID;?>" method="post"> <input type="hidden" name="memberID" value="<?php echo $row->memberID;?>" /> <legend>Edit Member Profile</legend> <p><label>First Name:</label> <br /> <input name="firstname" type="text" maxlength="20" VALUE="<?php echo $row->firstname;?>"/> </p> <p> <label>Last Name:</label> <br /> <input name="lastname" type="text" maxlength="20" VALUE="<?php echo $row->lastname;?>"/> </p> <p> <label>Date of Birth:</label> <br /> <input name="userDOB" type="text" maxlength="20" VALUE="<?php echo $row->userDOB;?>"/> </p> <p> <label>Male / Female:</label> <label> <br /> <select name="userGend" id="userGend" VALUE="<?php echo $row->userGend;?>"> <option>Male</option> <option>Female</option> </select> </label> </p> <p> <label>Location:</label> <br /> <label> <input name="userLoc" type="text" maxlength="20" VALUE="<?php echo $row->userLoc;?>"/> </label> </p> <p><label>Interests:<br /> </label> <label> <textarea name="userInt" id="userInt" cols="45" rows="5" VALUE="<?php echo $row->userInt;?>"></textarea> </label> <br /> </p> <p><label>Short Description:</label> <br /> <label> <textarea name="userDesc" id="userDesc" cols="45" rows="5" VALUE="<?php echo $row->userDesc;?>"></textarea> </label> </p> <p><label></label> <br /> <label></label> <br /> </p> <p> <input type="submit" name="psubmit" value="Edit Profile"> </p> </form> </body> </html> line 188 refers to the line after </html> hope this helps
  3. Hey all, I am trying to work on a form that will allow a user to edit/update the information that is contained within thier individual member profile via the use of a form. However, I have run into an error of which I cannot seem to find the variable that may be causing this problem... any help? error is code is: <?php //start the session session_start(); if(!isset($_SESSION['isloggedin'])){ header("Location:index.php"); } //connect to database include ('includes/db.php'); ?> <?php //reference the ismember session $memberID = $_SESSION['ismember']; // form validation if (isset($_POST['psubmit'])){ $firstname = trim($_POST['firstname']); if (strlen($firstname) < 3 || strlen($firstname) > 20) { $error[] = 'name must be between 3 and 20 characters.'; } $lastname = trim($_POST['lastname']); if (strlen($lastname) < 3 || strlen($lastname) > 20) { $error[] = 'last name must be between 3 and 20 chars'; } $userDOB = trim($_POST['userDOB']); if (strlen($userDOB) < 3 || strlen($userDOB) > 20) { $error[] = 'date of birth must be between 3 and 20 chars'; } $userGend = trim($_POST['userGend']); if (strlen($userGend) < 3 || strlen($userGend) > 20) { $error[] = 'Gender must be between 3 and 20 chars'; } $userLoc = trim($_POST['userLoc']); if (strlen($userLoc) < 3 || strlen($userLoc) > 255) { $error[] = 'Location must be between 3 and 255 chars'; } $userInt = trim($_POST['userInt']); if (strlen($userInt) < 3) { $error[] = 'Interests must be more than 3 characters'; } $userDesc = trim($_POST['userDesc']); if (strlen($userDesc) < 3) { $error[] = 'Description must be more than 3 characters'; } // if validation is ok, carry on if(!isset($error)) { //post form data $firstname = trim($_POST['firstname']); $lastname = trim($_POST['lastname']); $userDOB = trim($_POST['userDOB']); $userGend = trim($_POST['userGend']); $userLoc = trim($_POST['userLoc']); $userInt = trim($_POST['userInt']); $userDesc = trim($_POST['userDesc']); //escapes data is magic quotes are disabled on the server if(!get_magic_quotes_gpc()) { $firstname = addslashes($firstname); $lastname = addslashes($lastname); $userDOB = addslashes($userDOB); $userGend = addslashes($userGend); $userLoc = addslashes($userLoc); $userInt = addslashes($userInt); $userDesc = addslashes($userDesc); } //update the member profile already contained in the database $query = "UPDATE memberprofile SET firstname = '$firstname', lastname = '$lastname', userDOB = '$userDOB', userGend = '$userGend', userLoc = '$userLoc', userInt = '$userInt', userDesc = '$userDesc' WHERE memberID = '$memberID' "; mysql_query($query) or die('Error : ' . mysql_error()); echo "<p>member profile updated</p>"; } //close errors } //close if form has been sent //display any errors errors($error); $result = mysql_query("SELECT firstname, lastname, userDOB, userGend, userLoc, userInt, userDesc FROM memberprofile WHERE memberID = '$memberID' ")or die(mysql_error()); $Rows = mysql_num_rows($result); while ($row = mysql_fetch_object($result)) { ?> <form action="<?php echo $dir;?>editprofile=<?php echo $row->memberID;?>" method="post"> <input type="hidden" name="memberID" value="<?php echo $row->memberID;?>" /> <legend>Edit Member Profile</legend> <p><label>First Name:</label> <br /> <input name="firstname" type="text" maxlength="20" VALUE="<?php echo $row->firstname;?>"/> </p> <p> <label>Last Name:</label> <br /> <input name="lastname" type="text" maxlength="20" VALUE="<?php echo $row->lastname;?>"/> </p> <p> <label>Date of Birth:</label> <br /> <input name="userDOB" type="text" maxlength="20" VALUE="<?php echo $row->userDOB;?>"/> </p> <p> <label>Male / Female:</label> <label> <br /> <select name="userGend" id="userGend" VALUE="<?php echo $row->userGend;?>"> <option>Male</option> <option>Female</option> </select> </label> </p> <p> <label>Location:</label> <br /> <label> <input name="userLoc" type="text" maxlength="20" VALUE="<?php echo $row->userLoc;?>"/> </label> </p> <p><label>Interests:<br /> </label> <label> <textarea name="userInt" id="userInt" cols="45" rows="5" VALUE="<?php echo $row->userInt;?>"></textarea> </label> <br /> </p> <p><label>Short Description:</label> <br /> <label> <textarea name="userDesc" id="userDesc" cols="45" rows="5" VALUE="<?php echo $row->userDesc;?>"></textarea> </label> </p> <p><label></label> <br /> <label></label> <br /> </p> <p> <input type="submit" name="psubmit" value="Edit Profile"> </p> </form> Any ideas whats generating the error? im sure its something really simple ive missed but ive been stuck for the past few hours on it cheers for the help in advance
  4. Hi all, I have a page/form which is a member profile page, where the basic idea is that the user, once logged in, will be able to create a personal member profile, and have the option to select an image they wish to upload... all this works fine (the image selected gets uploaded and moved to the specified folder I have set for it.) However, I am currently having problems getting the uploaded image to 'resize' to 150 px 150px (ignore the example in this code, I know its set to half the image size... but even this doesnt work) but this doesnt seem to be working... as the original image size is on the server. Been trying to work out where I am going wrong and assume that maybe its something to do with the overall code, not just the actual bit that resizes? Anyway, any help or pointers would be helpful. (I am not a PHP guru so go easy, lol) Code is <?php //start the session session_start(); //connect to database include ('includes/db.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php //FORM CODE //function to generate errors function errors($error){ if (!empty($error)) { $i = 0; while ($i < count($error)){ echo "<p><span class=\"warning\"><b>".$error[$i]."</b></span></p>\n"; $i ++;} } // close if empty errors } //close function //code that runs if the form has been submitted if (isset($_POST['submit'])) { //check fields are not empty $firstname = trim($_POST['firstname']); if (strlen($firstname) < 2) { $error[] = 'first name must be between 2 and 20 chars'; } $lastname = trim($_POST['lastname']); if (strlen($lastname) < 3) { $error[] = 'last name must be between 3 and 20 chars'; } $userDOB = trim($_POST['userDOB']); if (strlen($userDOB) < 3) { $error[] = 'date of birth must be between 3 and 20 chars'; } $userGend = trim($_POST['userGend']); if (strlen($userGend) < 3) { $error[] = 'Gender must be between 3 and 20 chars'; } $userLoc = trim($_POST['userLoc']); if (strlen($userLoc) < 3) { $error[] = 'Location must be between 3 and 255 chars'; } $userInt = trim($_POST['userInt']); if (strlen($userInt) < 3) { $error[] = 'Interests must be more than 3 characters'; } $userDesc = trim($_POST['userDesc']); if (strlen($userDesc) < 3) { $error[] = 'Description must be more than 3 characters'; } //checks for allowed file type (jpg, gif or png) switch ($_FILES['userPic']['type']) { case $_FILES['userPic']['type'] == 'image/jpg': break; case $_FILES['userPic']['type'] == 'image/jpeg': break; case $_FILES['userPic']['type'] == 'image/gif': break; case $_FILES['userPic']['type'] == 'image/png': break; default: $error[] = 'wrong file type'; } //checks if file size is over 2mb, and if it is, refuse switch ($_FILES["userPic"]["size"]) { case $_FILES["userPic"]["size"] > 2097152: $error[] = 'Image size cannot be bigger then 2MB!'; break; } if(!$error) { //moves uploaded file from temp folder to set folder (which will be ../images/userpics folder) move_uploaded_file ($_FILES['userPic']['tmp_name'], "images/userpics/".$_FILES['userPic']['name']) or die ("Could not move"); //Assign the paths needed to variables for use in the script $filePathFull = "images/userpics/".$_FILES["userPic"]["name"]; $filePathThumb = "images/userpics/"; //Assign the files TMP name and TYPE to variable for use in the script $tmpName = $_FILES["userPic"]["tmp_name"]; $imageType = $_FILES["userPic"]["type"]; //Use a switch statement to check the extension of the file type. If file type is not valid echo an error switch ($imageType) { case $imageType == "image/gif": move_uploaded_file($tmpName,$filePathFull); break; case $imageType == "image/jpeg": move_uploaded_file($tmpName,$filePathFull); break; case $imageType == "image/pjpeg": move_uploaded_file($tmpName,$filePathFull); break; case $imageType == "image/png": move_uploaded_file($tmpName,$filePathFull); break; case $imageType == "image/x-png": move_uploaded_file($tmpName,$filePathFull); break; default: echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.'; } // Get information about the image list($src_width, $src_height, $type, $attr) = getimagesize($filePathFull); //Create the correct file type based on imagetype switch( $type ) { case IMAGETYPE_JPEG: $starting_image = imagecreatefromjpeg( $filePathFull ); break; case IMAGETYPE_PNG: $starting_image = imagecreatefrompng( $filePathFull ); break; case IMAGETYPE_GIF: $starting_image = imagecreatefromgif( $filePathFull ); break; default: return false; } //Get the image to create thumbnail from $starting_image; //Get image height and width $width = imagesx($starting_image); $height = imagesy($starting_image); //Create the dimesnsions for the thumbnail $thumb_width = $width/2; $thumb_height = $height/2; //Create the thumbnail with true colours $thumb_image = imagecreatetruecolor($thumb_width, $thumb_height); //Generate the resized image image imagecopyresized($thumb_image, $starting_image, 0,0,0,0, $thumb_width, $thumb_height, $width, $height); //Generate a random number to append the filename. $ran = "thumb_".rand () ; $thumb2 = $ran.".jpg"; //global $thumb_Add_thumb; //Create the path to store the thumbnail in. $thumb_Add_thumb = $filePathThumb; $thumb_Add_thumb .= $thumb2; //Create the new image and put it into the thumbnails folder. imagejpeg($thumb_image, "" .$filePathThumb. "$thumb2"); //escapes data is magic quotes are disabled on the server if(!get_magic_quotes_gpc()) { $firstname = addslashes($firstname); $lastname = addslashes($lastname); $userDOB = addslashes($userDOB); $userGend = addslashes($userGend); $userLoc = addslashes($userLoc); $userInt = addslashes($userInt); $userDesc = addslashes($userDesc); $userPic = addslashes($userPic); } //escape any harmful code and prevent sql injection attacks $firstname = mysql_real_escape_string($firstname); $lastname = mysql_real_escape_string($lastname); $userDOB = mysql_real_escape_string($userDOB); $userGend = mysql_real_escape_string($userGend); $userLoc = mysql_real_escape_string($userLoc); $userInt = mysql_real_escape_string($userInt); $userDesc = mysql_real_escape_string($userDesc); $userPic = mysql_real_escape_string($userPic); //prevents escaped code showing $firstname = strip_tags($firstname); $lastname = strip_tags($lastname); $userDOB = strip_tags($userDOB); $userGend = strip_tags($userGend); $userLoc = strip_tags($userLoc); $userInt = strip_tags($userInt); $userDesc = strip_tags($userDesc); $userPic = strip_tags($userPic); //reference the ismember session $memberID = $_SESSION['ismember']; //insert data into the memberprofile table $sql = mysql_query("INSERT INTO memberprofile (firstname, lastname, userDOB, userGend, userLoc, userInt, userDesc, userPic) VALUES('$firstname', '$lastname', '$userDOB', '$userGend', '$userLoc', '$userInt', '$userDesc', '".$_FILES['userPic']['name']."') WHERE memberID='$memberID'"); //if data has been inserted echo "<p>Thank you. Your member profile has been created</p>"; }//if no error }//close form if sumbit //print any errors errors($error); ?>
  5. So, use memberID for the memberprofile table? How do I go about referencing the key too?
  6. Hi guys, hope you're all well this morning. I have looked on the internet regarding the problem I currently have (which is that I have little idea on how to go about it!) Basically, I am creating a website using PHP for a final year college project, and the basic idea of it is that like social networking sites, users will be able to register to the site, and create a member profile which will be displayed. I have set up two tables for this process, one of which is members (registration), and the other memberprofile (where the user will be able to fill out profile information once registered and logged into the site) The tables look like this: MEMBERS MEMBERPROFILE Now, I know from investigation, that to make the information that the user sends when entering in the MEMBERPROFILE information (using a form) there has to be a thing called table referencing, where basically I want each user's member profile information to be relevant to the unique memberID that is set in the MEMBER table, but how do I go about this? Any help, or specific tutorials that will tell me how to do this? My current memberprofile form code that will be used to send the data to the MEMBERPROFILE table is: (I'm aware that it is not complete, but it might help if pointing out where exactly i need to reference the fields to) Cheers for the help Ben
  7. doh, thanks always the most simple thing you find thanks again
  8. Hey guys, running into problems when trying to create a basic login script. The script seems to run fine but doesnt acknowledge any of the usernames etc in the tables when I go to login? Was wondering what I've done wrong. The table details (as entered in when creating it is:) (this table example works fine with the registration script which successfully enters a registered member into the table so I assume this is not the problem) My login code is: The Login box code where the user would enter in the code is: The error I am getting is that the script runs til the end and when the data has been entered into the login boxes, the echo of "Your a fake" comes up. So where am I going wrong?? ??? Help would be appreciated, thanks
×
×
  • 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.