PDA

View Full Version : Removing text in HTML with PHP - Help Please



Dirt_Diver
08-12-2008, 02:24 PM
I have a PHP page that has a script for uploading an image in it. After the script is a form that allows you to select and upload an image. Just before the form I have some text that I just wrote in stating some rules. What I want to do is remove the text when the submit button is clicked.

After the image uploads it shows a clickable preview of the image and some text telling you that your image was added to the DB. But it still shows the actual content text. Can anyone help me with some code to remove it after uploading an image?

Joe

motormichael12
08-12-2008, 02:26 PM
Can we see your existing code?

Dirt_Diver
08-12-2008, 03:38 PM
Sure here is what I have now...




<?php

define ("MAX_SIZE","204800");
define ("WIDTH","720");
define ("HEIGHT","720");

function make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);

if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);

$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);

imagedestroy($dst_img);
imagedestroy($src_img);
}

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);

$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);

if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}

$image_name=time().'.'.$extension;
$newname="xxxxx/xxxx/xxxx/x/xxx/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
$thumb_name='xxxxx/xxxx/xxxx/x/xxx/'.$image_name;
$thumb=make_thumb($newname,$thumb_name,160,120);
}} }}

if(isset($_POST['Submit']) && !$errors)
{

echo "<center><h2>Your image has been submitted and will be reviewed by our administrators for approval</h2></center>";
echo '<a href="'.$newname.'"rel="lightbox" title="<strong>Your Submission Image</strong>"> <img src="'.$thumb_name.'"></a>';
}

?>




<p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p>
<form name="newad" method="post" enctype="multipart/form-data" action="" onSubmit="submitonce(this)">
<input name="understand" type="checkbox" id="understand" value="checkbox">

I have read and understood the rules.(*required)<br>

<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload Image"></td></tr>
</table>
</form>

Nile
08-12-2008, 03:47 PM
I'm using javascript because thats the only way, change:


<p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p>
<form name="newad" method="post" enctype="multipart/form-data" action="" onSubmit="submitonce(this)">
<input name="understand" type="checkbox" id="understand" value="checkbox">

I have read and understood the rules.(*required)<br>

<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload Image"></td></tr>
</table>
</form>
To this:


<div id="rules"> <p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p></div>
<form name="newad" method="post" enctype="multipart/form-data" action="" onSubmit="submitonce(this);document.getElementById('rules').style.display='none';">
<input name="understand" type="checkbox" id="understand" value="checkbox">

I have read and understood the rules.(*required)<br>

<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload Image"></td></tr>
</table>
</form>

Dirt_Diver
08-12-2008, 04:20 PM
okay I have it in there but now it's not showing the initial text to begin with. Not sure if it matters or not but just to clarify what all I have going on...
I have multiple pages here...

upload_image_data.php (holds all the code and form listed in this thread)
image_upload.php - Actual viewable page from site calling for "upload_image_data.php"


Also I have never posted in these threads before so excuse me for being stupid but to make sure I'm doing it right I add my <script></script> tags before and after the <div></div> tags right?

Nile
08-12-2008, 04:24 PM
Can I see a link to your page. Also theres probably something in or on your page thats making the whole thing not display. So I wanna check it out. :)

Dirt_Diver
08-12-2008, 04:31 PM
Sure here you go

Link to upload page (http://www.treasureshackonline.com/upload_a_feature_image.php)

Nile
08-12-2008, 04:32 PM
Gimme a few minutes.
Its not displaying because you have <script> tags around it.
Find:


<script>
<div id="rules"> <p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p></div></script>


And change it to:


<div id="rules"> <p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p></div>

Dirt_Diver
08-12-2008, 04:35 PM
hey no problem at all. Do you use yahooIM?

Nile
08-12-2008, 04:41 PM
Sure whats your IM, also check my updated post.

Dirt_Diver
08-12-2008, 05:08 PM
jsalmi_oicu812

Thanks I'll check it out. I do have another thing I want to add to the page but only if it's not a huge deal. Should be a small script though.

Dirt_Diver
08-12-2008, 05:16 PM
okay actually there are a couple of things.

First thing is after clicking upload Image the text disappears (AWESOME WORK) but after the image is uploaded and it creates the thumbnail it then displays the thumbnail along with the text again.
Ideas???

2. I can't get my required check box to be required. I found a script online somewhere this morning and tried it but it wouldn't work with my situation.

Dirt_Diver
08-13-2008, 03:31 AM
Okay I have a new problem here now. Wonder if anyone can give me a hand...

okay I have a code on the site now that works but it's only for a username and password.

I have modified it to add other fields. I don't get any error codes when creating a member but it's not writing the data to the database anymore. Only thing I changed was this info:


$insert = "INSERT INTO users (first_name, last_name, email, gender, city, state, country, username, password)
VALUES ('".$_POST[first_name]."','".$_POST[last_name]."','".$_POST[email]."','".$_POST[gender]."','".$_POST[city]."','".$_POST[state]."','".$_POST[country]."','".$_POST[username]."','".$_POST[pass]."','".$_POST[pass2]."')";
//VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; //reference Code
$add_member = mysql_query($insert);

Got any clues as to what I did wrong?