PHP - Newbie - Needs Help With Reg Form
Hi Guys
I am totally new to php and html and currently working on a project which is probably far to big for me! For reference - i am using dreamweaver and phpmyadmin. I have already created a regisration page and linked it to a database which works fine. But what i want to do now is to allow the user to upload a picture which will become the users profile picture and im really struggling. I had two seperate peices of code.. The first peice is the usual registration code which sends the data to the database and the second allows a user to upload an image to a folder on my server - both work fine on their own. What i THINK i need to do is try to merge the two peices of code and add an extra line somewhere which sends the file name and location to the users record on the database. the code i have so far is: Code: [Select] <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Username:</td> <td><input type="text" name="username" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Password:</td> <td><input type="text" name="password" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">First Name:</td> <td><input type="text" name="fname" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Surname:</td> <td><input type="text" name="sname" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Email:</td> <td><input type="text" name="email" value="" size="32" /></td> </tr> <tr valign="baseline"> <?php //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="profpics/".$image_name; //Writes the information to the database mysql_query("INSERT INTO users (prof_pic) VALUES ('$image_name')"); //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { echo "<h1>File Uploaded Successfull! </h1>"; } ?> <td nowrap="nowrap" align="right">Pictu </td> <td> <input type="file" name="photo"></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input name="Submit" type="submit" id="Submit" value="Submit" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> When a new user registers - the data is sent to the database but the image isnt uploaded or referenced in the DB Can anybody please help...Sorry if this is all mddled up but im pretty confused at the minute Thanks in advance Similar TutorialsI bought this template, and so far the template creator has not really been able to help me figure out the php side of the template, which really frustrates me. I know very very basic php if at all, so I am a bit lost on how to get this contact form to work. I had filled in everything that I needed to on the php file, and then tested it out and it doesn't send the email and doesn't bring up a message of any kind or redirect. Here is the live site: http://www.johntheseoexpert.com [attachment deleted by admin] Hello, I am just getting interested in PHP, so please excuse my ignorance. Something I thought might help me learn is this challenge. http://penn-station.com/gift2010.php is a daily enter sweepstakes. I'm wanting to automate a daily entry. I was able to do so using AutoIT (windows automation), but the result was rather janky. Anyways, I found how to enter my name in the Name field of the form by modifying the value attribute of the textbox. (I used Chrome's DOM inspector plug-in) <input type="text" class="EH_Form_Textbox" name="Name" size="30" value="Fred"> How would I go about actually submitting this? Thank you very much, Fred HI there, i'm using a flash and php form. The problem lie in the PHP I only seem to get the field titles (Name and telephone) coming through and not the data they contain. Could somebody tell me what i'm doing wrong? <?php $sendTo = "myemail@gmail.com"; $subject = "An enquiry"; $headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-path: " . $_POST["email"]; $message = "telephone: ".$strtelephone."\r\n"; $message .= "message: ".$strmessage."\r\n"; mail($sendTo, $subject, $message, $headers); ?> thank you Working on a project for school and I am trying to code a form that feeds into a DB. I have been studying the syntax, reading and doing everything I can to get this to work. A little help, pointers, direction would be greatly appreciated. It may be my database structure so I included a image for anyone to see... and the files. Thanks in advance [attachment deleted by admin] Hi there guys, I am very new to php and mySQL and i am currently working on a new site which I want to create a form where my sit visitors can leave their details so i can send them emails with future promotions... I have uploaded the files and when testing the form there doesnt seem to be any errors messages, but then when i go to my phpMyAdmin to check i it has worked. I can not see any of the information to which i ave entered from the form n the website.. I would be very grateful if somebody can please help me... the code for the php is as below.. Many many thanks in advance.. <?php $username="rdo10000_robin"; $password="mypassword"; $database="rdo10000_email"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); $query = "INSERT INTO data1 VALUES ('$_POST[name]','$_POST[email]','$_POST[phone]','$_POST[country]','$_POST[age]')"; header('Location: fish.html'); mysql_close(); ?> I really hope some one can help, many thanks in advance Hi, I'm a beginner to all this stuff, but I'm redesigning a website that needs an online booking form. I've made the form in HTML and the PHP bit to send direct to an email address. I found the template online. It works fine at sending to the email. But as soon as I started customising it and adding fields for "Date of Arrival" etc it's stopped working. I get a variety of error messages. Could you possibly take a look at it and see what I'm doing wrong? Thanks HTML (booknow.html) <form name="contactform" method="post" action="send_form_email.php"> <table width="450px"> </tr> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top""> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number *</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="arrival">Date of Arrival *</label> </td> <td valign="top"> <input type="text" name="arrival" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments">Comments</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> <a href="http://www.freecontactform.com/email_form.php"></a> </td> </tr> </table> </form> PHP bit (send_form_email.php) <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "MYEMAIL"; $email_subject = "SUBJECT"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) !isset($_POST['arrival']) !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // required $telephone = $_POST['arrival']; // required $comments = $_POST['comments']; // not required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($telephone) < 2) { $error_message .= 'The Telephone you entered does not appear to be valid.<br />'; } if(strlen($arrival) < 2) { $error_message .= 'The Date of Arrival you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Date of Arrival: ".clean_string($arrival)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you soon. <? } ?> I think something's wrong with the way I added Date of Arrival, but I don't know what. Thanks in advance for any advice Can anyone find a glaring error with my contact form or my mailer? I previously had a form that was working (sending the email through) but stopped working. It was more complicated before and had a recaptcha in it. I've been troubleshooting this for awhile now and can't figure out what's happening. I've stripped it down to just the basics. I'm stumped because I am correctly redirected to the confirmation.html page, yet no email has come through. I even put a simple test file (mailertest.php) on the server. The file is found and echoes "Mail sent", but no email is received. I contacted the host and they claim that things are fine on their end with the PHP mailer and it must be a problem in my code. As a newbie, I don't doubt that I'm doing something wrong, but I can't figure it out!
I'm attaching three files. Contact.php, contact_mailer.php and my test PHP file called mailertest.php. I'd appreciate any help that anyone can offer.
Attached Files
mailertest.php 99bytes
3 downloads
contact_mailer.php 608bytes
1 downloads
contact.php 7.55KB
0 downloads Hi guys, I've spent quite a bit of time searching the site and have a good start - hoping for some help. I run a hockey league and have a database that keeps our stats. Regular stats page is here - http://okchockey.com/stats/stats.php I need a web form that can update existing records in the database. Maybe I am going thru this the wrong way - please let me know. I know there's a better way than my current version. Basically I have a table that has fields of Week, Jersey, Name, Goals, Assists, Points, and Penatly_Min. Again - excuse the newbie-ness - what I did is have a record for each player for each week. I already pre-created a record for each player for each week. I just need a web form that will update these existing records. I already created one that can add new records but I am having a tough time creating one to update existing ones. I'd like to be able to select the week (week 1-10) then select a player and update his stats for that particular week. Hopefully this makes sense. If anyone has some sample code I can look at I'd sure appreciate it. Really struggling trying to teach myself PHP Hello JS experts,
I'm new to JS coding (self-learning) and I have just one (potenitally) simple request to ask of you wonderful folks here.
Oh BTW, I've tried searching through this forum (and the WWW as well) but couldn't seem to easily find something that fits my request, or was easy for me to understand and apply to my situation.
So what I have/want is: a Data-Entry form which (for the first record/entry for a given date) allows the user to select a date from a "Calendar Date Picker". Upon subsequent records/entries (for the same date), the date field should no longer be accessible, but the (previously entered/selected) value should be both displayed (greyed-out) and certainly carried over to the DB/Table.
I know this might be a very simple piece of code, but being that I'm a newbie, I'm not sure how to achieve this.
Would appreciate any and all help to get this done (preferably the necessary code).
If it helps, here's some of my existing code that's related to the field names:
Form field details:
<div class="control-group"> <label class='control-label'>Select Flyer Start Date:</label> <input type="text" name="datepicker" id="datepicker"> </div>DB (table) field details: $flyerDateStart = isset($_POST["datepicker"]) ? $_POST["datepicker"] : "";Thanks much.
Hello all, I'm a basic coder 😀 if($_POST['form']['hobby'] == '')  $modUserEmailText = str_replace('{hobby:caption} : {hobby:value}', ''<br/>'',$modUserEmailText);
{hobby:caption} : {hobby:value} Thanks a million! I am brand new to php and the following code gives me an error of undefined variable although it seems to be defined. Please tell what I'm doing wrong cause this code comes from a book: <?php // Definition of the class Donation class Donation { private $name; private $amount; static $totalDonated = 0; static $numberOfDonors = 0; // Function to display what each person has donated function info() { $share = 100 * $this->amount / Donation::$totalDonated; return "{$this->name} donated {$this->amount} ({$share}%)"; } function __construct($nameOfDonor, $donation) { $this->name = $nameOfDonor; $this->amount = $donation; Donation::$totalDonated = Donation::$totalDonated + $donation; Donation::$numberOfDonors++; } function __destruct() { 109) Donation::$totalDonated = Donation::$totalDonated - $donation; Donation::$numberOfDonors--; } } It gives me the following error: Notice: Undefined variable: donation in C:\wamp\www\learnPHP\unitCounter.inc on line 109 I have used a tutorial to create an upload form for my website, it works fine until the file gets over 850 kb, how can I set it up so larg files 80 megs and up can be uploaded? Here is the simple code I am using,form Code: [Select] <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> PHP <html> Thanks <head> <title>My First PHP Page</title> </head> <body> <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </body> </html> Hi all, I am completing an assignment for Uni and I have run it to a bit of difficulty. I hope someone can help me out. I am deleting a record from the database and I want it to then display the student record number, firstname and surname. I know it is probably something simple but I can see where I am going wrong! <?php $id=$_REQUEST['id']; $firstname=$_GET['firstname']; $surname=$_GET['surname']; $db="prs"; $link=mysql_connect("localhost","gandalf","bella") or die("Cannot Connect to the database!"); mysql_select_db($db,$link) or die ("Cannot select the database!"); $query="DELETE FROM students WHERE upn='".$id."'"; if(!mysql_query($query,$link)) {die ("An unexpected error occured while <b>deleting</b> the record, Please try again!");} else { echo "Student with Student Number #".$id." ".$firstname." ".$surname." removed successfully!";} ?>() Thanks in advance for any and all help, it is much appreciated. Cheers, Fergal Hello guys! My name is João Miquelis, Im from Portugal and I am a real noob in php, so i hope i can count with ur help HI guyz, want help in a code that can help find the GCD of two input numbers Use the example of GCD (12,15). Hi all I'm learning php and can't see where my error is in this simple code. I just want the country title to display with the states name below. here is the code. And thnk you for any help Code: [Select] // create arrays $_Mexico = array ('YU' => 'Yucatan', 'BC' => 'Baja California', 'QA' => 'Oaxaca'); $_US = array ('MD' => 'Maryland', 'IL' => 'Illinois', 'PA' => 'Pennsylvania', 'IA' => 'Iowa'); $_Canada = array ('QC' => 'Quebec', 'AB' => 'Alberta', 'NT' => 'North Territories', 'YT' => 'Yukon', 'PE' => 'Prince Edward Island'); // combine them $_N_america = array ('Mexico' => $_Mexico, 'United States' => $_US, 'Canada' => $_Canada ); // create loop foreach ($_N_america as $country => $list) { echo "<h2>$country</h2><ul>"; } foreach ($list as $k => $v) { echo "<li>$k - $v</li>\n"; } echo '</ul>'; Ok, I am currently at Uni, with one of my units needing me to build a content management system. I have been learning PHP for about 2 months, so go easy on me. So I was developing happily, I was able to use the CMS to add a product, edit that product and delete it. I load it up today to carry on working on it, but find that adding a product no longer works. I investigate further and find that the HTML form on the "Add a product" section's processing page (createProduct.php) is not receiving the values from the form using the $_POST method, therefore the mysql query was containing empty values. I found this confusing as I had not changed any of the code. So i investigate further, creating a test php page, copying the $_POST method into here and echoing the variables. And.. it worked. Even more confused, I delved deeper and found that the culprit for the $_POST method not working was one of my includes. connection.php. Here is the connection.php include: Code: [Select] <?php //1. Create database connection $connection = mysql_connect("localhost", "root"); //No password on the DB yet as it is only local. if (!$connection) { die("Database connection failed: " . mysql_error()); } //2. Select database to use $db_select = mysql_select_db("cms",$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } ?> And here is createProduct.php; Code: [Select] <?php require_once("../includes/connection.php");?> <?php require_once("../includes/functions.php");?> <?php ?> <?php //Populating the variables with values from the HTML form $Product_Name = mysql_prep($_POST['Product_Name']); $Price = mysql_prep($_POST['Price']); $Product_Information = mysql_prep($_POST['Product_Information']); $category_id = $_POST['category']; echo $Product_Name . "<br />"; echo $Price . "<br />"; echo $Product_Information . "<br />"; echo $category_id . "<br />"; ?> <?php //Creating and submitting the mysql query echo $category_id; $query = "INSERT INTO tblProducts( Product_Name, Price, Product_Information, category_id ) VALUES ( '{$Product_Name}', {$Price}, '{$Product_Information}', {$category_id} )"; echo $query; if (mysql_query($query, $connection)) { header("Location: createProduct.php"); exit; } //error handling else { echo "<p>Product creation failed.</p>"; echo "<p>" . mysql_error() . "</p>"; } ?> <?php mysql_close($connection); ?> So my question is.. why, when suddenly loading it up today after a few days absence would the database connection code be conflicting ONLY ON THIS PAGE. editing and deleting a product still work. I am truly stumped as this seems completley illogical and is probably something really obvious. Any help would be greatly appreciated. Hey guys, i'm not just new here but i'm new to php.. I've been trying to edit some wordpress templates i was given, but there is some code in the footer/copyright files that i really don't understand at all .. Here is an example of the code ... Code: [Select] <?php $_F=__FILE__;$_X='Pz4JCQkJCTxkNHYgNGQ9ImYyMnQ1ciI+DQoJCQkJCQkNCgkJCQkJCTxwIGNsMXNzPSJjMnB5cjRnaHQiPkMycHlyNGdodCAmYzJweTsgYTAwOCAtIDwxIGhyNWY9Imh0dHA6Ly8xc3MzcjFuYzVjMm1wbDVtNW50MTRyNXMxbnQ1LjJyZyIgdDR0bDU9ImQ1djRzIGMybXBsNW01bnQxNHI1IHMxbnQ1IGMybXAxcjF0NGYgMXNzM3IxbmM1IG0xbDFkNDUgbTN0MzVsbDUiPmQ1djRzIGMybXBsNW01bnQxNHI1IHMxbnQ1IGMybXAxcjF0NGYgMXNzM3IxbmM1IG0xbDFkNDUgbTN0MzVsbDU8LzE+PC9wPg0KCQkJCQkJDQoJCQkJCQk8cCBjbDFzcz0icDJ3NXI1ZCI+DQogICAgICAgICAgICAgICAgICAgICAgICA8MSBocjVmPSJodHRwOi8vczRtM2wxdDQybjFzczNyMW5jNXY0NS5jMm0iIHQ0dGw1PSJzNG0zbDF0NDJuIDFzczNyMW5jNSB2NDUgcjVuZDVtNW50IG0zbHQ0c3MzcDJydCB0MTN4IGMybXAxcjF0NGYiIGNsMXNzPSJ3MjJ0aDVtNXMiPiZuYnNwOzwvMT4NCiAgICAgICAgICAgICAgICAgICAgICAgIDwvcD4NCgkJCQkJDQoJCQkJCTwvZDR2PjwhLS0gRW5kIGYyMnQ1ciAtLT4=';eval(base64_decode('JF9YPWJhc2U2NF9kZWNvZGUoJF9YKTskX1g9c3RydHIoJF9YLCcxMjM0NTZhb3VpZScsJ2FvdWllMTIzNDU2Jyk7JF9SPWVyZWdfcmVwbGFjZSgnX19GSUxFX18nLCInIi4kX0YuIiciLCRfWCk7ZXZhbCgkX1IpOyRfUj0wOyRfWD0wOw=='));?> Could someone please explain if there is a way of decoding this?? Thanks so much |