Sign petition and add image without becoming a member - php

goldy300

New Member
Messages
33
Reaction score
0
Points
0
I'LL GIVE YOU THE URL TO THE FORM SO YOU UNDERSTAND WHAT I WANT. http://daniel.classroomonline.info/petition/add_record1.php

SO I WANT USERS TO BE ABLE TO SIGN A PETITION WITHOUT BECOMING A MEMBER AND UPLOAD AN IMAGE SO THE IMAGE SHOWS IN A TABLE WITH THEIR DETAILS IN THE SIGNATURES TABLE.

TABLE - SIGNATURES

  • firstname
  • lastname
  • dob
  • address
  • city
  • state
  • postcode
  • email
  • comments
TABLE - UPLOAD

  • name
  • size
  • type
  • content
ADD_RECORD1.PHP
HTML:
<h3>Sign the Petition</h3>

<table>
    <tr>
        <td>Personalize your signature</td>
        <td><form name="uploadImage">
        <input type="button" value="Upload Image" onClick="window.open('upload.php','mywindow','width=400,height=200,toolbar=no,location=yes,directories=yes,status=yes,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes')">
        </td>
    </tr>
</table>
        <br>
</form>

<form method="post" action="add_record2.php">
<table>
<tr>
    <td>First Name</td>
    <td><input type="text" name="firstname"></td>
</tr>
<tr>
    <td>Last Name</td>
    <td><input type="text" name="lastname"></td>
</tr>
<tr>
    <td>D.O.B</td>
    <td>
        <select name="month">
            <option value="01">January</option>
            <option value="02">Febuary</option>
            <option value="03">March</option>
            <option value="04">April</option>
            <option value="05">May</option>
            <option value="06">June</option>
            <option value="07">July</option>
            <option value="08">August</option>            
            <option value="09">September</option>            
            <option value="10">October</option>            
            <option value="11">November</option>
            <option value="12">December</option>
        </select>
        <select name="day">
            <?php
            $x=1;
            while($x<=31){
            echo "<option value=$x>$x</option>";
            $x++;}
            ?>
        </select>
        <select name="year">
            <?php
            $y=1900;
            while($y<=1991){
            echo "<option value=$y>$y</option>";
            $y++;}
            ?>
        </select>

    </td>
</tr>
<tr>
    <td>Address</td>
    <td><input type="text" name="address"></td>
</tr>
<tr>
    <td>Suburb</td>
    <td><input type="text" name="suburb"></td>
</tr>
<tr>
    <td>State</td>
    <td><input type="text" name="state"></td>
</tr>
<tr>
    <td>Postcode</td>
    <td><input type="text" name="postcode"></td>
</tr>
<tr>
    <td>Email</td>
    <td><input type="text" name="email"></td>
</tr>
<tr>
    <td>Comments</td>
    <td><textarea name="comments" rows="5" cols="30"></textarea></td>
</tr>
</table>
<p>
<input type="submit" value="Sign Petition">
</form>
</BODY>
</HTML>

I USED ONCLICK=OPEN.WINDOW() TO OPEN THE UPLOAD FILE TO BROWSE AND UPLOAD AN IMAGE.... BUT THAT DOESN'T LINK IT TO THE USERS SIGNATURE WHICH THEY HAVEN'T EVEN FILLED OUT YET. SO THAT'S NO GOOD ISN'T IT?

UPLOAD.PHP
HTML:
<form method="post" enctype="multipart/form-data" action="upload2.php">
<h3>Personalize Your Signature</h3>
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>

UPLOAD2.PHP
HTML:
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


include("database.inc");

$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');


echo "<body bgcolor='#dddabe'><h3> File $fileName uploaded successfully.</h3><p> <input type='button' value='Close Window' onClick='window.close()'><br></body>";
}
?>

AND THE FINAL FILE
ADD_RECORD2.PHP
HTML:
<?php

include("database.inc");
?>
<?php

$dob=$year."-".$month."-".$day;
//echo $dob;

$query="INSERT signatures(firstname,lastname,dob,address,city,state,postcode,email,comments)
VALUES ('$firstname','$lastname','$dob','$address','$city','$state','$postcode','$email','$comments')";
//echo $query;
mysql_query ($query) or print mysql_error();

?>
 

goldy300

New Member
Messages
33
Reaction score
0
Points
0
It's saved as a medium blob. but as it is at the moment, the user can upload as many photo's as they want and it won't be linked to the signatures id. I just wanted it so they can add it, sign the petition and have their personal image show with the petition.
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
create a separate table for images something like this:

int imageid primary key auto-increment (unique ID for image)
int petition_id (petition to show this image in)
int user_id (id of user)
medium blob image (image data)
varchar(25) image_type (image mime type)

then you just have to add another query, one for loading the petition and signatures, and one for the images.
 
Top