Jump to content

andy_b_1502

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by andy_b_1502

  1. Thanks muddy. I have changed/tested new script with this: $sql="SELECT username, password FROM $companies WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); and now have this error message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb25a/b109/ipg.removalspacecom/checklogin.php on line 47 Wrong Username or Password This could be why people get all pissy about it because they are frustrated when it doesnt work :'( lol. The username and password is in the database, its looking in the right place but it's not seeing it? any idea's how to make this work for me?
  2. Hi everyone! I have the following error message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/bosweb25a/b109/ipg.removalspacecom/checklogin.php on line 47 Wrong Username or Password by using the below code: <?PHP include ('db.php'); // Define $username and $password $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $companies WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "login_success.php" session_register("username"); session_register("password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Does anyone have an idea of whats happening? from a guess it's looking for the username and password in the database, but i've made sure that this username and password in IN the correct fields in the table ect?? Thanks
  3. Hi everyone i wonder if you can help me here: I need a script for a login and check login- create cookie. Here is my form: <form method="post" action="check_login.php"> <p> <input type="submit" name="Submit2" value="go" /> </fieldset> </p> </form> that sends it to check_login (which BEFORE i deleted something by accident, used to take me to a username and password box) But now all it does is send me straight to the memebrs area??? Can i change the check_login.php script to make it work correctly: <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
  4. New topic started!
  5. In my haste i've deleted the html part. I only have the php part left, if we start over: this script is sending me straight to the members area WITHOUT asking for a username or password? How do i modify it to do this: <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
  6. So what your saying is in the login form, send them to the members area and check they have logged in on that page?
  7. This is the full contents of check_login.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> <link href="styles/modified-style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <h1>REMOVALSPACE.COM</h1></div> <div id="wrapper"> <div id="logo"></div> <div id="menu"> <h2><a href="index.php">Home</a> | <a href="login.php">Advertise with us</a> | <a href="about.php">Read about us</a> | <a href="contact.php">Contact us</a></h2> </div> </div> <div id="content"> <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </div> <div id="sidebar"> <h3>Home <br /><br /><br /> Advertise with us <br /><br /><br /> Read about us <br /><br /><br /> Contact us</h3> <h3>Removals</h3> </div> <div id="footer"></div> </body> </html>
  8. I have got rid of any white space before <?php tags that i can find, it doesn't seem to have done the trick? <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
  9. Hi, Im looking for a way of re-arranging my script(s) around to prevent headersalreadysent errors. I know i have a poor script design but since re-designing the site the script does not work where it previously had... im not sure whats gone wrong i just know that it needs to be changed somehow for it to work.. The error messages are coming from my login/check-login scripts: Login.php: Contains the form <form method="post" action="check_login.php"> <p> <input type="submit" name="Submit2" value="go" /> </fieldset> </form> Check_login.php: Proccess form data <?php // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['upassword']) { } else { header("Location: members_area.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['upassword']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['upassword'] = stripslashes($_POST['upassword']); $info['upassword'] = stripslashes($info['upassword']); $_POST['upassword'] = md5($_POST['upassword']); //gives error if the password is wrong if ($_POST['upassword'] != $info['upassword']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['upassword'], $hour); //then redirect them to the members area header("Location: members_area.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="316" height="120" border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="upassword" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> Exact error messges read: Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php:11) in /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php on line 81 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php:11) in /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php on line 82 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php:11) in /hermes/bosweb25a/b109/ipg.removalspacecom/check_login.php on line 85 What do i have to do to change the script check_login around and make it work correctly? Thank you in advance
  10. I just changed the call function bit to this: <?php /* CALL THE FUNCTION HERE */ call_user_func($Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)); { } ?> It did get rid of a lot of error messages but i have two left that need elliminating: Notice: Undefined variable: Resize_Image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Fatal error: Function name must be a string in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86
  11. <a href="index.php">Click here to go back to the homepage </a> <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("", "", "") or die(mysql_error()) ; mysql_select_db("") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim("/images/thumbs"); $o_path = trim("images/COMPANIES"); $save = $upload . $save; $file = $upload . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; } else{ $size = $t_h/$height; } } else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return;} /* END OF RESIZE FUNCTION */ //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { /* CALL THE FUNCTION HERE */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { "$save, $file, $t_w, $t_h, $s_path, $o_path"; } //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?>
  12. Yeah that did make things a bit clearer, after properly calling the Resize_Image function according to the link i get this: Fatal error: Cannot redeclare resize_image() (previously declared in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php:45) in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 why does it want to redeclare it?
  13. Okay... so... Ive now changed the paths to the original image, and for the thumbnails to read like this: // RESIZE FUNCTION */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim("/images/thumbs"); $o_path = trim("images/COMPANIES"); $save = $upload . $save; $file = $upload . $file; Then is call the function like so: /* CALL THE FUNCTION HERE */ if(Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) { //Notice that the '$' sign was removed } However the problem error messages persist: Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: upload in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 49 Notice: Undefined variable: upload in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 50 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 52 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 64 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 76 The file 166899_162370493852077_100174353405025_346144_1721195732_n.jpg has been uploaded, and your information has been added to the directory
  14. why the hell isn't this sinking in!? i just dont get this, im sorry!
  15. Isn't there a way of calling $file a generic name? as i won't know the name of every file uploaded each time will i?? same with the resized image? it should be done all automatically shouldn't it? $s_path = trim("/images/thumbs"); $o_path = trim('images/COMPANIES'); $save = $s_path . $save; $file = $o_path . $file; $s_path = trim("/images/thumbs"); $o_path = trim('images/COMPANIES'); $save = thumbs . $save; $file = COMPANIES . $file;
  16. if(Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) { //Notice that the '$' sign was removed } and is this all i need to define it? im slightly confused
  17. As i've posted the whole script previously; it knows where the image is, as the image is sent to the main folder then it resizes it. I thought that this piece of code here is "at the end" of the script that drops the image into the image folder. So shouldnt it just do this: 1. Upload the image 2. Drop it into the folder 3. Resize it 4. Display newly re-sized image when called from server "So what I mean is that when you call the function, you have to be passing it the information it desires." What information should it need, thats preventing it from working at present?
  18. yes... they are as part of my resize function function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim($s_path); $o_path = trim($o_path); $save = $s_path . $save; $file = $o_path . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; } else{ $size = $t_h/$height; } } else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return;} /* END OF RESIZE FUNCTION */ do i have to define each one??
  19. Thanks guinBro BUT it doesnt seem to have worked changing that. I'm still getting error messages to define the variable: Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 52 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 64 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 76 The file img02.jpg has been uploaded, and your information has been added to the directory So going back to my question, why isnt it working when i define it???? lol
  20. /* CALL THE FUNCTION HERE */ if($Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) ; Notice: Undefined variable: Resize_Image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Fatal error: Function name must be a string in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 if() defines the variable right? why am i getting an undefined variable error message litebearer?
  21. im getting a lot of error's with that: Array ( [upload] => Array ( [name] => company%20logo(5).jpg [type] => image/jpeg [tmp_name] => /tmp/phpVlRTx1 [error] => 0 => 24713 ) ) Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 51 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 63 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 74 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 74 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 The file company%20logo(5).jpg has been uploaded, and your information has been added to the directory
  22. <?php $database=""; mysql_connect (""; @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "\n\n\nThere are $num_rows records.<P>"; echo "<table><tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>";// store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "<tr><td>{$row['company_name']}</td>"; echo "<td>{$row['location']}</td>"; echo "<td>{$row['postcode']}</td>"; echo "<td>{$row['basicpackage_description']}</td>"; echo "<td>{$row['premiumuser_description']}</td>"; echo "<td><img src=\"http://www.removalspace.com/images/COMPANIES{$row['upload']}\" alt=\"logo\" /></td></tr>";} echo "</table>"; ?> include resize_function? or select resize_function?
  23. it's not working, the resize function...?
  24. I have got the form <form enctype="multipart/form-data" action="basicpackage-send.php" method="POST"> Compnany Name:<br /> <input type="text" name="company_name" id="company_name"><br> Company Description:<br /> <input type="text" name = "basicpackage_description" id="basicpackage_description"><br> Location:<br /> <input type="text" name = "location" id="location"><br> Postcode:<br /> <input type="text" name = "postcode" id="postcode"><br> Company Logo/Photo:<br /> <input type="file" name="upload" id="upload"><br> <input type="submit" value="Add to our directory"> </form> i have got the get imagesize functions and resize funtctions: <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim($s_path); $o_path = trim($o_path); $save = $s_path . $save; $file = $o_path . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; } else{ $size = $t_h/$height; } } else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return;} /* END OF RESIZE FUNCTION */ //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> My question is, what is going wrong in this code to make it fail/ or why isnt this working? it only uploads the image BUT doesnt resize them. Could you please shed some light on to this for me? it should work but it doesnt? many 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.