Jump to content

scmeeker

Members
  • Posts

    153
  • Joined

  • Last visited

    Never

Everything posted by scmeeker

  1. I'm working on a user page that will add/edit information. Once the user is satisfied with addind/updating their details they move on to a new page where they will upload an image. I'm able to upload the image just fine but I'm trying to get the file name of the image to be inserted into the associated product record in the table. When I click it, it returns my image to the browser (good) and uploads it (good) but does not put the name in the product record. Here is the form action code for this page <?php session_start (); ?> <?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?> <?php mysql_connect("localhost", "", "", "") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); $item_image = $_FILES['image_upload_box']['name']; $item_id = mysql_real_escape_string($_POST[id]); $sql="UPDATE product SET image_upload_box='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { header("Location: add_new_product4.php?id={$item_id}=success&show_image=".$_FILES["image_upload_box"]["name"]); exit; } else{ header("Location: add_new_product.php4?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error"); exit; } } } ?>
  2. Okay, I got the other part I posted previously working. Now once the user is satisfied with addind/updating their details they move on to a new page where they will upload an image. I'm able to upload the image just fine but I'm trying to get the file name of the image to be inserted into the associated product record in the table. When I click it, it returns my image to the browser (good) and uploads it (good) but does not put the name in the product record. Here is the form action code for this page: <?php session_start (); ?> <?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?> <?php mysql_connect("localhost", "", "", "store") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); $item_image = $_FILES['image_upload_box']['name']; $item_id = mysql_real_escape_string($_POST[id]); $sql="UPDATE product SET image_upload_box='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,bmp,x-png and 4 MB max if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000)) { // some settings $max_upload_width = 500; $max_upload_height = 500; // if user chosed properly then scale down the image according to user preferances if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){ $max_upload_width = $_REQUEST['max_width_box']; } if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){ $max_upload_height = $_REQUEST['max_height_box']; } // if uploaded image was JPG/JPEG if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){ $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was GIF if($_FILES["image_upload_box"]["type"] == "image/gif"){ $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]); } // BMP doesn't seem to be supported so remove it form above image type test (reject bmps) // if uploaded image was BMP if($_FILES["image_upload_box"]["type"] == "image/bmp"){ $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was PNG if($_FILES["image_upload_box"]["type"] == "image/x-png"){ $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]); } $remote_file = "image_files/".$_FILES["image_upload_box"]["name"]; imagejpeg($image_source,$remote_file,100); chmod($remote_file,0644); // get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height){ $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefromjpeg($remote_file); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); } imagedestroy($image_source); header("Location: add_new_product4.php?id={$item_id}=success&show_image=".$_FILES["image_upload_box"]["name"]); exit; } else{ header("Location: add_new_product.php4?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error"); exit; } } } ?> It's also not holding the $item_id in the URL code from above: header("Location: add_new_product4.php?id={$item_id}=success&show_image=".$_FILES["image_upload_box"]["name"]); Any suggestions?? Thanks for your help!
  3. Worked great! Thanks!
  4. The following code is from the form action code. On my site, a user adds a new item, then goes to the next page to confirm the details with the option to edit and update their information. The problem is, its not updating the information in the database. The information is showing up in the form fine and referring to the correct item id but just not updating. mysql_connect("localhost", "", "", "") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); $item_title = mysql_real_escape_string($_POST[title]); $item_description = mysql_real_escape_string($_POST[description]); $item_price = mysql_real_escape_string($_POST[price]); $item_location = mysql_real_escape_string($_POST[location]); $item_ship_to = mysql_real_escape_string($_POST[ship_to]); $item_shipping_cost = mysql_real_escape_string($_POST[shipping_cost]); $item_international = mysql_real_escape_string($_POST[international]); $item_in_shipping = mysql_real_escape_string($_POST[in_shipping]); $item_id = mysql_real_escape_string($_POST[id]); $username = $_SESSION['username']; $sql="UPDATE product SET title='$item_title', description='$item_description', price='$item_price', location='$item_location', ship_to='$item_ship_to', shipping_cost='$item_shipping_cost', international='$item_international', in_shipping='$item_in_shipping' WHERE id = [$item_id]"; header("location:add_new_product3.php?id={$item_id}=username=".$_SESSION['username'].""); if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } Any suggestions?? I've been really stuck on this! Thanks!
  5. Thanks for the help!
  6. I'm wondering how to pull information from a current record back into the "input type" of a form. For instance, if I had this input form and a user input their information, went to the next page where it was displayed for their approval but then realized they put in the wrong information and wanted to go back to edit it. I want the form to look the same but with their information in this "input type". I can do it with a "text area" box but I'm having trouble with the "input type". Any suggestions on how to incorporate the PHP code with this? <input type="text" name="price" size="40"/> This is how I did it with a "text area" box: <textarea name="payment" rows=10 cols=90><?php echo $display_block = "$item_price" ?></textarea>
  7. ok...got it working.
  8. Tried that but is still not working. Any other suggestions?
  9. I'm using an image uploader and uploading the image to the database is working fine...the problem is, I want the name of the image to go into the database table. It seems to be skipping over the insert code and going right to uploading the image. Any suggestions? Thanks! <?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?> <?php mysql_connect("localhost", "", "", "") or die(mysql_error()); mysql_select_db("table") or die(mysql_error()); $item_image = mysql_real_escape_string($_POST[image_upload_box]); $sql="INSERT INTO practice (image_upload_box) VALUES ('$item_image')"; // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,bmp,x-png and 4 MB max if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000)) { // some settings $max_upload_width = 2592; $max_upload_height = 1944; // if user chosed properly then scale down the image according to user preferances if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){ $max_upload_width = $_REQUEST['max_width_box']; } if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){ $max_upload_height = $_REQUEST['max_height_box']; } // if uploaded image was JPG/JPEG if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){ $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was GIF if($_FILES["image_upload_box"]["type"] == "image/gif"){ $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]); } // BMP doesn't seem to be supported so remove it form above image type test (reject bmps) // if uploaded image was BMP if($_FILES["image_upload_box"]["type"] == "image/bmp"){ $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was PNG if($_FILES["image_upload_box"]["type"] == "image/x-png"){ $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]); } $remote_file = "image_files/".$_FILES["image_upload_box"]["name"]; imagejpeg($image_source,$remote_file,100); chmod($remote_file,0644); // get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height){ $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefromjpeg($remote_file); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); } imagedestroy($image_source); header("Location: submit.php?upload_message=image uploaded&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]); exit; } else{ header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error"); exit; } } ?> <!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>Image Upload with resize</title> <style type="text/css"> <!-- body,td,th { font-family: Arial, Helvetica, sans-serif; color: #333333; font-size: 12px; } .upload_message_success { padding:4px; background-color:#009900; border:1px solid #006600; color:#FFFFFF; margin-top:10px; margin-bottom:10px; } .upload_message_error { padding:4px; background-color:#CE0000; border:1px solid #990000; color:#FFFFFF; margin-top:10px; margin-bottom:10px; } --> </style></head> <body> <h1 style="margin-bottom: 0px">Submit an image</h1> <?php if(isset($_REQUEST['upload_message'])){?> <div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>"> <?php echo htmlentities($_REQUEST['upload_message']);?> </div> <?php }?> <form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;"> <label>Image file, maximum 4MB. it can be jpg, gif, png:</label><br /> <input name="image_upload_box" type="file" id="image_upload_box" size="40" /> <input type="submit" name="submit" value="Upload image" /> <br /> <br /> <label>Scale down image? (2592 x 1944 px max):</label> <br /> <input name="max_width_box" type="text" id="max_width_box" value="1024" size="4"> x <input name="max_height_box" type="text" id="max_height_box" value="768" size="4"> px. <br /> <br /> <p style="padding:5px; border:1px solid #EBEBEB; background-color:#FAFAFA;"> <strong>Notes:</strong><br /> The image will not be resized to this exact size; it will be scalled down so that neider width or height is larger than specified.<br /> When uploading this script make sure you have a directory called "image_files" next to it and make that directory writable, permissions 777.<br /> After you uploaded images and made tests on our server please <a href="delete_all_images.php">delete all uploaded images </a> <br /> </p> <input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" /> </form> <?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?> <p> <img src="image_files/<?php echo $_REQUEST['show_image'];?>" /> </p> <?php }?> </body> </html>
  10. resolved. Thanks for anyone who read!
  11. Got it! I had to put the <?php session_start();?> by itself before the other PHP coding and it worked fine. Thanks everyone!
  12. Sorry, here is the rest of the Warning. I'm rather confused by it. Line 4 is the session_start(). If the first part if referring to line 2, that is <?php. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at artist_profile_update.php:2) in artist_profile_update.php on line 4 pie
  13. I put the session_start() at the beginning of the PHP action page (its already at the top of the form page) and its now updating the table in the database successfully BUT is giving me this warning: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
  14. I'm having trouble with the form updating. It seems I have all this code right but its still not updating the table. I have a form set up that pulls the information that's already in the table and then it can be edited (hence the need for updating) but when the update button is clicked, nothing is updated or changed. Now I'm working with session variables and wondering if they're being passed when the update button is clicked. I'm also wondering if I can make the "<form action="artist_profile_update.php" method="post" name="update">" PHP code to pass the SESSION variable? Here is the form: <form action="artist_profile_update.php" method="post" name="update"> <br /> <span class="titles">A bit about you:</span><br /> <span class="smallfont">update info </span><br /> <p> <textarea name="bio" rows=10 cols=90><?php echo $display_block = "$item_bio" ?></textarea></p> <br /> <span class="titles">artists</span><br /> <span class="smallfont">update info</span><br /> <p> <textarea name="other_artists" rows=10 cols=90><?php echo $display_block = "$item_other_artists" ?></textarea></p> <br /> <br /> <input type="submit" name="Submit" value="update"> </form> Here is the "form action file" artist_profile_update.php: ( I would also like to redirect this back to the original page.) <?php mysql_connect("localhost", "", "", "sgallery") or die(mysql_error()); mysql_select_db("sgallery") or die(mysql_error()); $item_bio = mysql_real_escape_string($_POST['bio']);; $item_other_artists = mysql_real_escape_string($_POST['other_artists']); $sql="UPDATE store SET bio='$item_bio', other_artists='$item_other_artists' WHERE username = '".$_SESSION["username"]."'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> Any suggestions?? I'm really stuck on this one. Thanks!
  15. I'm having trouble with the form updating. It seems I have all this code right but its still not updating the table. I have a form set up that pulls the information that's already in the table and then it can be edited (hence the need for updating) but when the update button is clicked, nothing is updated or changed. Now I'm working with session variables and wondering if they're being passed when the update button is clicked. Here is the form: <form action="artist_profile_update.php" method="post" name="update"> <br /> <span class="titles">A bit about you:</span><br /> <span class="smallfont">update info </span><br /> <p> <textarea name="bio" rows=10 cols=90><?php echo $display_block = "$item_bio" ?></textarea></p> <br /> <span class="titles">artists</span><br /> <span class="smallfont">update info</span><br /> <p> <textarea name="other_artists" rows=10 cols=90><?php echo $display_block = "$item_other_artists" ?></textarea></p> <br /> <br /> <input type="submit" name="Submit" value="update"> </form> Here is the "form action file" artist_profile_update.php: ( I would also like to redirect this back to the original page.) <?php mysql_connect("localhost", "", "", "sgallery") or die(mysql_error()); mysql_select_db("sgallery") or die(mysql_error()); $item_bio = mysql_real_escape_string($_POST['bio']);; $item_other_artists = mysql_real_escape_string($_POST['other_artists']); $sql="UPDATE store SET bio='$item_bio', other_artists='$item_other_artists' WHERE username = '".$_SESSION["username"]."'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> Any suggestions?? I'm really stuck on this one. Thanks!
  16. That is retrieving information that is already in the database.
  17. Okay, I changed that. Then when I clicked the "update" button, it cleared out the data in the database that was in the "bio" and "other_artists" and came up blank. So now it is communicating but not updating the information. Hmmmm...any other suggestions? I'm going to post the form too. Can I send the session variable through the "form action"? How would I do that? <form action=artist_profile_update.php> <br /> <span class="titles">bio</span><br /> <span class="smallfont">ignore this</span><br /> <p> <textarea name="bio" rows=10 cols=90><?php echo $display_block = "$item_bio" ?></textarea></p> <br /> <span class="titles"></span><br /> <span class="smallfont"> ignore</span><br /> <p> <textarea name="other_artists" rows=10 cols=90><?php echo $display_block = "$item_other_artists" ?></textarea></p> <br /> <br /> <input type="submit" name="Submit" value="Update"> </form>
  18. the store_id is a random integer greater than zero. So if it is set to less than 1 then the user has no store id and therefore should not have access. Then they would be redirected to a different page.
  19. When the update button is clicked, it access this code to update the table BUT its not updating the table. No information is changed and just goes back to what was there on the previous page. The username is the session variable. Any suggestions?? $item_bio = mysql_real_escape_string($_POST[bio]);; $item_other_artists = mysql_real_escape_string($_POST[other_artists]); $sql="UPDATE store SET bio = '$item_bio', other_artists = '$item_other_artists' WHERE username = '".$_GET["username"]."'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header("location:update.php?username=".$_SESSION['username']."");
  20. Thanks. I'm also wondering where to place it in the code because I want the loop to continue and not end.
  21. After a person is logged in, I want to be able to keep out users(buyers) who don't have a storefront (there are buyers and sellers). So, if they don't have a store id, they can't access that area. I came up with this statement: if ($store_id < "1") { header("location:store_signup.php");} This would reroute the user to a new page. I'm having problems with where to place the code within my code. When I test it, it keeps skipping over it and if I place it before the "list($width) = getimagesize($item_photo);....." closing off the "else" bracket preceding it, it does reroute to the page I want it to but it ends the while loop, only giving me one item for users who actually do have a store. I want it to be able to continue the loop for actual sellers who have a storefront and list all their items and not just one. Any ideas?? Thanks! //validate item $get_item_sql = "SELECT p.id, p.photo, p.title, p.username, p.date, p.price, p.store_id, s.store_id, s.username FROM store AS s LEFT JOIN product AS p on s.username = p.username WHERE s.username = '".$_GET["username"]."'"; $get_item_res = mysqli_query($mysqli, $get_item_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysqli_fetch_array($get_item_res)) { $store_id = $item_info['store_id']; $item_title = stripslashes($item_info['title']); $item_username = $item_info['username']; $item_date = $item_info['date']; $item_price = $item_info['price']; $item_photo = $item_info['photo']; $content .= ""; if ($store_id < "1") { header("location:user_login.php");} list($width) = getimagesize($item_photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth); $content .= "<table width=\"603\" border=\"0\"><tr><td width=\"101\"> <img alt=\"Image\" border=0 width=\"{$maxWidth}\" src=\"{$item_photo}\" /><td width=\"201\"> {$item_title}</td> <td width=\"109\">{$item_username}</td><td width=\"101\"> {$item_date}</td><td width=\"99\"> \${$item_price} USD </td></tr></table>"; $content .= "\n"; } }
  22. Thank you....it was my mistake...there was other php code at the top of the new page that should not have been left there!
  23. I want to direct my user to a new page instead of printing a simple congratulations on the following page but when I try to use the header() function it give me a fatal error. It likes this "echo"code and works fine: $sql="INSERT INTO artist (username, password, email, terms, activationkey, status) VALUES ('$username', '$password', '$email', '$test_terms', '$activationKey', 'verify')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration."; but it gives me the fatal error when I replace the "echo" statement with: $sql="INSERT INTO artist (username, password, email, terms, activationkey, status) VALUES ('$username', '$password', '$email', '$test_terms', '$activationKey', 'verify')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header("location:happy.php"); Any suggestions?? Thanks!
  24. My user login form works BUT I would like it to also check another field called "status" in the table before moving on to a successful login. I want it to check to see if the user status is "activated" or the login will go to an error page. I've played around with it without much success. I've inserted a variable for "status" but its not working. It seems like a simple thing....but it keeps going to the success page even when the $mystatus should fail. Here is the code: <?php session_start(); // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['username']; $mypassword=$_POST['password']; $mystatus=$_POST['status']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername', password='$mypassword' and status='$mystatus'"; $result=mysql_query($sql); if ($mystatus!="activated"){ header("location:error.php"); }else{ // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['username'] = $myusername; session_register("password"); header("location:listtest5.php"); } else { header ("location:userlogin_error.php"); } } ?>
  25. I'm trying to get my registration form to send a confirmation email. It works and enters a record and goes through the motion but I get this error: "Warning: mail() [function.mail]: SMTP server response: 550 must be authenticated" I've set my php.ini file to be set to my SMTP server...but am just not sure what's going on. Help?
×
×
  • 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.