Note that there are some explanatory texts on larger screens.

plurals
  1. POForcing Image Upload During Registration
    text
    copied!<p>Facing a bit of difficulty when trying to integrate the functionality of two different scripts. </p> <p>I have a login / registration system that later allows the user to go in and add a profile picture. I want to include the profile image picture upload as a requirement for registration, but am facing difficulty integrating the two. </p> <p>Here's where I am at with the php:</p> <pre><code> if (isset ($_POST['username'])){ $username = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['username']); $gender = preg_replace('#[^a-z]#i', '', $_POST['gender']); $b_m = preg_replace('#[^0-9]#i', '', $_POST['birth_month']); $b_d = preg_replace('#[^0-9]#i', '', $_POST['birth_day']); $b_y = preg_replace('#[^0-9]#i', '', $_POST['birth_year']); $email1 = $_POST['email1']; $email2 = $_POST['email2']; $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; $user_pic = $_POST['user_pic']; include_once "scripts/connect_to_mysql.php"; $emailCHecker = mysql_real_escape_string($email1); $emailCHecker = str_replace("`", "", $emailCHecker); $sql_uname_check = mysql_query("SELECT username FROM myMembers WHERE username='$username'"); $uname_check = mysql_num_rows($sql_uname_check); $sql_email_check = mysql_query("SELECT email FROM myMembers WHERE email='$emailCHecker'"); $email_check = mysql_num_rows($sql_email_check); if ((!$username) || (!$gender) || (!$b_m) || (!$b_d) || (!$b_y) || (!$email1) || (!$email2) || (!$pass1) || (!$pass2) || (!$user_pic)) { $errorMsg = 'ERROR: You did not submit the following required information:&lt;br /&gt;&lt;br /&gt;'; if(!$username){ $errorMsg .= ' * User Name&lt;br /&gt;'; } if(!$gender){ $errorMsg .= ' * Gender: Confirm your sex.&lt;br /&gt;'; } if(!$b_m){ $errorMsg .= ' * Birth Month&lt;br /&gt;'; } if(!$b_d){ $errorMsg .= ' * Birth Day&lt;br /&gt;'; } if(!$b_y){ $errorMsg .= ' * Birth year&lt;br /&gt;'; } if(!$email1){ $errorMsg .= ' * Email Address&lt;br /&gt;'; } if(!$email2){ $errorMsg .= ' * Confirm Email Address&lt;br /&gt;'; } if(!$pass1){ $errorMsg .= ' * Login Password&lt;br /&gt;'; } if(!$pass2){ $errorMsg .= ' * Confirm Login Password&lt;br /&gt;'; } if(!$user_pic){ $errorMsg .= ' * Add a Profile Picture&lt;br /&gt;'; } } else if ($email1 != $email2) { $errorMsg = 'ERROR: Your Email fields below do not match&lt;br /&gt;'; } else if ($pass1 != $pass2) { $errorMsg = 'ERROR: Your Password fields below do not match&lt;br /&gt;'; } else if (strlen($username) &lt; 4) { $errorMsg = "&lt;u&gt;ERROR:&lt;/u&gt;&lt;br /&gt;Your User Name is too short. 4 - 20 characters please.&lt;br /&gt;"; } else if (strlen($username) &gt; 20) { $errorMsg = "&lt;u&gt;ERROR:&lt;/u&gt;&lt;br /&gt;Your User Name is too long. 4 - 20 characters please.&lt;br /&gt;"; } else if ($uname_check &gt; 0){ $errorMsg = "&lt;u&gt;ERROR:&lt;/u&gt;&lt;br /&gt;Your User Name is already in use inside of our system. Please try another.&lt;br /&gt;"; } else if ($email_check &gt; 0){ $errorMsg = "&lt;u&gt;ERROR:&lt;/u&gt;&lt;br /&gt;Your Email address is already in use inside of our system. Please use another.&lt;br /&gt;"; } else if ($_FILES['fileField']['tmp_name'] != "") { $maxfilesize = 51200; // 51200 bytes equals 50kb if($_FILES['fileField']['size'] &gt; $maxfilesize ) { $error_msg = '&lt;font color="#FF0000"&gt;ERROR: Your image was too large, please try again.&lt;/font&gt;'; unlink($_FILES['fileField']['tmp_name']); } else if (!preg_match("/\.(gif|jpg|png)$/i", $_FILES['fileField']['name'] ) ) { $error_msg = '&lt;font color="#FF0000"&gt;ERROR: Your image was not one of the accepted formats, please try again.&lt;/font&gt;'; unlink($_FILES['fileField']['tmp_name']); } else { $newname = "image01.jpg"; $place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/".$newname); } } { $email1 = mysql_real_escape_string($email1); $pass1 = mysql_real_escape_string($pass1); $db_password = md5($pass1); $full_birthday = "$b_y-$b_m-$b_d"; $ipaddress = getenv('REMOTE_ADDR'); $sql = mysql_query("INSERT INTO myMembers (username, gender, birthday, email, password, ipaddress, sign_up_date) VALUES('$username','$gender','$full_birthday','$email1','$db_password', '$ipaddress', now())") or die (mysql_error()); $id = mysql_insert_id(); mkdir("members/$id", 0755); } } else { // if the form is not posted with variables, place default empty variables so no warnings or errors show $errorMsg = ""; $username = ""; $gender = ""; $b_m = ""; $b_d = ""; $b_y = ""; $email1 = ""; $email2 = ""; $pass1 = ""; $pass2 = ""; $user_pic = ""; } </code></pre> <p>And then the corresponding html form:</p> <pre><code>&lt;table class="table_f" width="100%" cellpadding="3"&gt; &lt;form action="register.php" method="post" enctype="multipart/form-data"&gt; &lt;tr&gt; &lt;td colspan="2"&gt;&lt;font color="#94A0D1"&gt;&lt;?php print "$errorMsg"; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;h11&gt;Add Profile Picture: &lt;/h11&gt;&lt;/td&gt; &lt;td width="61"&gt;&lt;?php echo $user_pic; ?&gt;&lt;/td&gt; &lt;td width="521"&gt;&lt;input name="fileField" type="file" class="formFields" id="fileField" size="42" /&gt; 50 kb max &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" style="color: #a2a2a2; font-family: helvetica; font-size: 11px; letter-spacing: 1px" name="Submit" value="Register" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/form&gt; &lt;/table&gt; </code></pre> <p>If anyone has any ideas about what I might be missing I would really appreciate it. I have been staring at this for so long that I am probably missing something obvious. </p> <p>Thanks in advance for any advice.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload