Jump to content

PHPenpals upgrade help...


MA5H3D

Recommended Posts

Hi all,

 

I really need some help with the PHPenpals script.  Basically i've customised the script to work on my site but i need it to have an "upload image" option, instead of the standard "image url" text field.

 

I know this is a big ask, but i've been struggling with this for days and it's slowly killing me.

 

The upload script needs to be in with the form fields, or on the preview page but it needs to add the image name to the database with the rest of the info.

 

Any help would be greatly appreciated (you could be saving a life), even a little help with where the script should actually go whould be a start.

 

This is the full (join.php) page used to sign up:

 

<?

include ("config.php")  ;

require ("./inc/functions.inc")  ;

include ( get_language() )  ;

include("./inc/countries.inc") ;

 

//print_r($_POST);

 

connect();

 

$query="SELECT * FROM admin WHERE ID=1" ;

$result= mysql_query($query) ;

$row= mysql_fetch_array($result) ;

$title=$row[6];

$admin_email=$row[6];

$stage=$_POST['stage'];

 

$username=$_POST['username'];

$gender=$_POST['gender'];

//$bday=$POST['bday'];

$bday=$_POST['bday'];

$byear=$_POST['byear'];

$bmonth=$_POST['bmonth'];

$country=$_POST['country'];

$aboutme=$_POST['aboutme'];

$aboutme2=$_POST['aboutme2'];

$email=$_POST['email'];

$homepage=$_POST['homepage'];

$occupation=$_POST['occupation'];

 

$password1=$_POST['password1'];

$password2=$_POST['password2'];

 

 

 

$startdate = gmdate("M d, Y");

 

$form1="

<form method=post action=\"join.php\">

 

<table><tr><td width=512>

<center>

<p><font color=\"#FF0000a\">*</font> is obliged</p>

</center>

 

<table border=\"0\" cellpadding=\"5\" cell spacing=\"0\">

 

<tr><td valign=\"top\" width=\"200\">Username <font color=\"#FF0000a\">*</font></td>

<td><input type=\"text\" name=\"username\" size=\"31\" maxlength=\"30\"><p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">Your e-mail address <font color=\"#FF0000a\">*</font>(make sure it is correct , because your password will be sent here) </td>

<td><input type=\"text\" name=\"email\" size=\"31\" maxlength=\"255\"><p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">Your homepage address </td>

<td><input type=\"text\" name=\"homepage\" size=\"31\" maxlength=\"255\"

value=\"http://\"><p></td></tr>

 

 

 

 

<tr><td valign=\"top\" width=\"200\">Your gender <font color=\"#FF0000a\">*</font> </td>

<td><select name=\"gender\"><option> <option >male <option >female

</select><p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">Your birthday <font color=\"#FF0000a\">*</font> </td>

<td>

<SELECT name=\"bmonth\"> ";

 

while($row1=each($lang[months])){

$form1 .= "<OPTION value=".$row1['key'].">".$row1['value']."</OPTION> ";

}

 

$form1.="

</SELECT>

 

<SELECT name=\"bday\">" ;

 

while($row1=each($lang[days])){

$form1 .= "<OPTION value=".$row1['value'].">".$row1['value']."</OPTION> ";

}

 

$form1.= "</SELECT>

 

 

<select name=\"byear\">  " ;

 

 

while($row1=each($lang[years])){

$form1 .= "<OPTION value=".$row1['value'].">".$row1['value']."</OPTION> ";

}

 

 

$form1 .="</select>

 

<tr>

<td valign=\"top\" width=\"200\">In which country do you currently live? <font color=\"#FF0000a\">*</font> </td>

<td><select name=\"country\">  "  ;

 

while($row1=each($countries)){

$form1 .= "<OPTION value=".$row1['key'].">".$row1['value']."</OPTION> ";

}

 

$form1.="</select><p></td></tr>

 

 

<tr><td valign=\"top\" width=\"200\">Occupation </td>

    <td><input type=\"text\" name=\"occupation\" size=\"31\" maxlength=\"30\"><p></td></tr>

 

 

 

<tr><td valign=\"top\" width=\"200\">Tell something about yourself ,the type of penpal you are looking for, your hobbies, etc.  <font color=\"#FF0000a\">*</font> </td>

    <td><textarea name=\"aboutme\" rows=\"10\"

cols=\"35\"></textarea><p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">Enter your password(4 to 8 characters)  <font color=\"#FF0000a\">*</font></td>

    <td><input type=\"password\" name=\"password1\" size=\"31\" maxlength=\"30\"><p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">Enter your password again <font color=\"#FF0000a\">*</font></td>

    <td><input type=\"password\" name=\"password2\" size=\"31\" maxlength=\"30\"><p></td></tr>

 

</table>

 

 

<br><br>

<INPUT TYPE=\"HIDDEN\"  name=\"date\" value=\"$startdate\">

 

<INPUT TYPE=\"HIDDEN\"  name=\"stage\" value=\"2\">

<input type=\"submit\" value=\"Preview Profile\">

 

 

</td></tr></table>

</form>

"

;

 

 

$toptext="<center><br><h3>Sign up now!</h3><br>"    ;

if(!IsSet($stage))

{

//include("mysql.php")      ;

//$query="SELECT text FROM pagetext WHERE ID=2 "  ;

//$result=mysql_query($query)  ;

//$termsarray=mysql_fetch_array($result) ;

//$terms=$termsarray[0]    ;

 

connect();

 

$query="SELECT terms FROM admin WHERE ID=1"  ;

$result = mysql_query($query)

    or die(mysql_error());

$terms=mysql_fetch_array($result)  ;

//print_r($terms)    ;

$terms=$terms[0];

 

$button="

<FORM  action=\"join.php\" method=\"POST\" name=\"join1\">

<INPUT TYPE=\"HIDDEN\"  name=\"stage\" value=\"1\">

<center><INPUT TYPE=\"SUBMIT\"  name=\"submitit\" value=\"I agree!!\" >

</FORM>

"  ;

 

$main=$terms.$button  ;

}

 

 

 

 

elseif ($stage==1)

{

$main=$toptext.$form1    ;

}

 

 

 

elseif ($stage==2)

{

 

 

 

 

include ("mysql.php")  ;

$query1="SELECT * FROM penpals WHERE email='$email' " ;

$result1=mysql_query($query1) ;

$array1= mysql_fetch_row($result1) ;

$countemail= mysql_num_rows ($result1);

 

$query1="SELECT * FROM penpals WHERE username='$username' " ;

$result1=mysql_query($query1) ;

$array1= mysql_fetch_row($result1) ;

$countfirst_name= mysql_num_rows ($result1);

//echo ($countemail) ;

 

$backbutton="<br><INPUT TYPE=\"BUTTON\"  name=\"back\" value=\"Back\"  onClick=\"history.back()\">"      ;

 

if ($username=="")

$main = "You didn't enter a username!".$backbutton    ;

 

if ($countfirst_name!="0")

$main = "This username already exists".$backbutton    ;

 

elseif ($gender=="")

$main = "You didn't enter you gender!".$backbutton ;

 

elseif ( $bday=="" or $byear=="" or $bmonth=="" )

$main = "You didn't enter your birthday!".$backbutton  ;

 

elseif ( $country=="")

$main = "You forgot to enter your country!".$backbutton      ;

 

 

elseif ($aboutme=="")

{

$main = "You forget to tell something about yourself!".$backbutton ;

}

 

elseif($countemail!="0")

{

$main= "Your emailadress has been used in another profile.You may only sign up once!".$backbutton  ;

}

 

elseif($password1!=$password2 or $password1=="" or $password2=="")

$main="The passwords you entered don't match".$backbutton ;

 

else

 

{

 

$cleanusername=htmlspecialchars($username) ;

 

$cleanemail=htmlspecialchars(strip_tags($email)) ;

$cleanhomepage=htmlspecialchars(strip_tags($homepage)) ;

$cleanpicture=htmlspecialchars(strip_tags($picture)) ;

$cleanoccupation=htmlspecialchars(strip_tags($occupation)) ;

$cleanaboutme=htmlspecialchars(strip_tags($aboutme)) ;

$cleanpassword=htmlspecialchars(strip_tags($password1))  ;

 

//if ($cleanlast_name=="")

//$lastname2=""      ;

//else

//$lastname2="Comment:<p class=\"data\"><br>$last_name" ;

 

if ($cleanpicture=="" or $cleanpicture=="http://" )

$photo=""          ;

else

$photo=  "<IMG  SRC=\"$picture\">"  ;

 

if ($cleanhomepage=="" or $cleanhomepage=="http://" )

$homepage2=""          ;

else

$homepage2="<p class=\"head\" >Homepage<p class=\"data\"<br><A  target=\"blank\" href=".stripslashes($homepage).">".stripslashes($homepage)."</A>"  ;

 

if ($cleanoccupation=="")

$occupation2=""    ;

else

{

$occupation2="<p class=\"head\" >Occupation </td>

    <td>".$cleanoccupation."<p>"    ;

}

//$aboutme2=addslashes($aboutme) ;

 

 

 

$main = "

<form method=post action=\"join.php\">

 

<table><tr><td width=512>

 

 

<table border=\"0\" cellpadding=\"5\" cell spacing=\"0\">

 

<tr><td valign=\"top\" width=\"200\"><p class=\"head\" >User name:<br> <p class=\"data\">". stripslashes($cleanusername) ."<br>

<p class=\"head\" >".stripslashes($lastname2)."<p class=\"head\" > Email adress:<br><p class=\"data\">".stripslashes($cleanemail)."<br>

".stripslashes($homepage2)."

</td>

<td valign=\"top\">".stripslashes($photo)."</td></tr>

 

 

<tr><td valign=\"top\" width=\"200\"><p class=\"head\">Gender </td>

<td>".$gender."<p></td></tr>

 

<tr><td valign=\"top\" width=\"200\"><p class=\"head\" >Birthday (MM-DD-YYYY) </td>

<td>

".$bmonth."-".$bday."-".$byear."

 

 

<tr>

<td valign=\"top\" width=\"200\"><p class=\"head\" >Country </td>

<td>".$countries[$country]."

<p></td></tr>

 

<tr><td valign=\"top\" width=\"200\">".stripslashes($occupation2)."</td></tr>

 

 

<tr><td valign=\"top\" width=\"200\"><p class=\"head\" >About me</td>

    <td>".stripslashes($cleanaboutme)."<p></td></tr>

 

</table>

 

 

<br><br>

<INPUT TYPE=\"HIDDEN\"  name=\"stage\" value=\"3\">

<INPUT TYPE=\"HIDDEN\"  name=\"username\" value=\"$cleanusername\">

<INPUT TYPE=\"HIDDEN\"  name=\"date\" value=\"$startdate\">

<INPUT TYPE=\"HIDDEN\"  name=\"email\" value=\"$cleanemail\">

<INPUT TYPE=\"HIDDEN\"  name=\"homepage\" value=\"$cleanhomepage\">

<INPUT TYPE=\"HIDDEN\"  name=\"picture\" value=\"$picture\">

<INPUT TYPE=\"HIDDEN\"  name=\"gender\" value=\"$gender\">

<INPUT TYPE=\"HIDDEN\"  name=\"bmonth\" value=\"$bmonth\">

<INPUT TYPE=\"HIDDEN\"  name=\"bday\" value=\"$bday\">

<INPUT TYPE=\"HIDDEN\"  name=\"byear\" value=\"$byear\">

<INPUT TYPE=\"HIDDEN\"  name=\"country\" value=\"$country\">

<INPUT TYPE=\"HIDDEN\"  name=\"occupation\" value=\"$cleanoccupation\">

<INPUT TYPE=\"HIDDEN\"  name=\"aboutme2\" value=\"$cleanaboutme\">

<INPUT TYPE=\"HIDDEN\"  name=\"password2\" value=\"$cleanpassword\">

<INPUT TYPE=\"HIDDEN\"  name=\"date\" value=\"$startdate\">

<input type=\"submit\" value=\"Save profile\">

 

 

</td></tr></table>

 

"  ;

 

 

}

}

 

elseif ($stage==3)

{

 

include("mysql.php") ;

$query="INSERT INTO penpals (ID, username, date, email, homepage, picture, gender, bmonth, bday, byear, country, occupation, about, password ) VALUES ( NULL, '$username', '$startdate', '$email', '$homepage', '$picture', '$gender', '$bmonth', '$bday', '$byear', '$country', '$occupation', '$aboutme2', '$password2'  )"  ;

//echo $query ;

$result = mysql_query($query) ;

if ($result==0)

$main= "SHIT!!!!".$query  ;

else

$main= "Your data is stored in our database." ;

 

mail("$email", "Your profile at $title", "You just signed up at $title\n$URL\nYour password = $password2\n\nYou can use this password together with your emailadress($email) to edit or remove your profile at $title." , "From: $admin_email\nReply-To: $admin_email")    ;

 

}

 

$content=$main;

$page[content]=$content;

printpage($page)

//include ("./design/design1top.inc")  ;

//include ("./design/design1footer.inc") ;

 

 

?>

 

 

Thanks.

 

Link to comment
Share on other sites

I have tried this a couple of time with different scripts i'm trying to use this one at the moment:

 

<code>

//edit this

$_max_file_size = '3000000'; //file size in bytes.

$upload_dir = "somefolder/"; //upload folder..chmod to 777

$_i = "1"; //number of files to upload at one time

//end edit

 

echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";

echo "<form enctype='multipart/form-data' action='?do=upload' method='post' style=\"margin: 0px;\">";

echo "<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='" . $_max_file_size , "'></td></tr>";

if($_GET['do'] != 'upload')

{

echo "<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>";

echo "<tr><td> </td></tr>";

echo "<tr><td class=bodytext>Choose your image:<br>";

//show number of files to select

For($i=0; $i <= $_i-1;$i++)

{

echo "<input name='file" . $i . "' type='file'></td></tr>";

}

echo "<tr><td class=bodytext><input type=submit name=Submit value=\"Upload Photo\" style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";

}

 

if($_GET['do'] == 'upload')

{

//upload all the fields until done

For($i=0; $i <= $_i-1; $i++)

{

//file with the upload folder

$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);

$target_path = str_replace (" ", "", $target_path);

//actual file name with the random number

$_file_name = basename($_FILES['file' . $i]['name']);

$_file_name = str_replace (" ", "", $_file_name);

//do not upload the 'left blank' fields

if(basename($_FILES['file' . $i]['name']) != '')

{

if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))

{

//uploaded successfuly

$_uploaded=1;

}

else

{

//error uploading

$_error=1;

}

}

else

{

$_check=$_check+1;

}

 

}

 

//file(s) did upload

if($_uploaded == '1')

{

$_uploaded=0;

$adID = $_GET['adID'];

 

mysql_query("update tbl_whatever set photo = '".$_file_name."' WHERE whatever = '$whatever ");

 

}

//file uploaded?

if($_error == '1')

{

$_error=0;

echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";

}

//user selected a file?

if($_check == $_i)

{

$_check=0;

echo "<div class=redtext>Select a file first than click 'Upload File'</div>";

}

}

echo "</td></tr>";

 

?>

</table>

</code>

 

The problem i'm having now is when i use the script with the form it submits the whole page instead of just the image and when i use the script on the preview page, it seems to forget all the other information and show a blank preview page.

 

Can you tell me how to put this script into this page properly so it'll all work together?

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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