PHP - Feedback Form For Multiple Items
Hello:
I want to create a feedback form that will allow a user to select from 30 or so items on a page, and send the data to an email address. I think it's something like a shopping cart but without a need to process a payment. I want to list items (like a soccer ball, a basket ball, etc.) and allow the user to select the size of the ball, the color, the number of balls, etc. I want the user to be able to select 1 item or many items. Once they are done, they would hit submit, and the data would get sent to an email address. Do I need to use a session to do this? I was trying to work with this code: Code: [Select] <?php session_start(); session_register('product'); session_register('amount'); $_SESSION['product'] = $_POST['product']; $_SESSION['amount'] = $_POST['amount']; //SEND THE EMAIL CODE HERE ???? ?> <form method="post" action=""> <input type="text" size="10" name="product"><br /> <input type="text" size="10" name="amount"><br /> <input type="submit" value="Finish"> </form> But I'm pretty sure I'm not in the ballpark on how to do this. Anyone have any ideas? Thanks in advance. Similar TutorialsThe following code used to work in PHP 4, but it no longer works under PHP 5. Can someone take a look and let me know what needs fixing please? I'm not new to PHP, but I'm not an expert. Code: [Select] <? // Set page variables. $title = "Feedback Form"; $back = ""; $bg = '000066'; $text = 'ffffff'; $link = 'ffff00'; $vlink = 'ff0000'; $trans = 'spinoutin'; $btntag = 'text=000070 insetselection'; $txtbxtag = 'bgcolor=ffffff text=000070 cursor=ff autoactivate nohighlight'; $ip = $_SERVER['REMOTE_ADDR']; // Remove < and > from the email message. $msg = str_replace("<","",$msg); $msg = str_replace(">","",$msg); // Set email variables. $your_email = 'email@mydomain.com'; $your_name = 'Joe Blogs'; $your_link = 'http://www.mydomain.com/'; $confirm_sub = 'Message Sent'; $confirm_msg = "Hi $feedbackname, Thank you for your email message sent from the $sub. I will respond to it as quickly as I can. Thanks again, $your_name $your_link"; $contact_msg = "$feedbackname ($feedbackemail) wrote: $msg $ip"; // Begin the sendmail routine. if ($send) { if (!$feedbackname || !$feedbackemail || substr_count($feedbackemail, '@') < 1 || substr_count($feedbackemail, '.') < 1 || !$sub || !$msg || substr_count($spam, 'clark') < 1) { print <<<EOF <html> <title>Error!</title> <body background="$back" bgcolor="$bg" text=$text link=$link vlink=$vlink transition=$trans fontsize=medium> <center> <br><br> <font s=7 c=f0><b> Error!</b></font> <p> Please go back and correct the errors listed below: <p> <table> <tr><td> <ul> EOF; if (!$feedbackname) { print "<li>Your name is missing!<br>"; } if (!$feedbackemail || substr_count($feedbackemail, '@') < 1 || substr_count($feedbackemail, '.') < 1) { print "<li>Your email is missing or invalid!<br>"; } if (!$sub) { print "<li>The email subject is missing!<br>"; } if (!$msg) { print "<li>The email message is missing!"; } if (substr_count($spam, 'clark') < 1) { print "You need to correctly type in the Anti-Spam word. Hit Back and try again."; } print <<<EOF </ul> </table> <p> <A href="feedback.php">Back</A> <br><br><br><br> </center> </body> </html> EOF; } else { // Email that gets sent to you. mail($your_email, $sub, $contact_msg, "From: $feedbackname < $feedbackemail >"); // Email that gets sent to them. mail($feedbackemail, $confirm_sub, $confirm_msg, "From: $your_email"); // Print the thank you page. print <<<EOF <html> <head><title>Message Sent</title> </head> <body background="$back" bgcolor="$bg" text=$text link=$link vlink=$vlink transition=$trans> <H2>Feedback</H2> Thanks $feedbackname for sending your message to me!<P> You will receive a confirmation email momentarily.<P> </body> </html> EOF; } } else { // Print the contact form page. print <<<EOF <H3>Feedback Form</H3> To send an email to me simply fill out the form below.<P> <form method=post> Name: <input name=feedbackname $txtbxtag size=40><P> Email: <input name=feedbackemail $txtbxtag size=40><P> <INPUT type="hidden" name="sub" value="Feedback Form"> Message:<br> <textarea name=msg rows=10 cols=50 maxlength=500 $txtbxtag></textarea><P> <IMG SRC="images/sh-layout/turing.jpg" WIDTH="100" HEIGHT="30" BORDER="0" ALT="turing"><BR> Anti-Spam Measure - In lowercase letters, retype the word in the image above:<BR> <input name=spam $txtbxtag size=40><P> <INPUT TYPE=submit NAME=send $BTNTAG VALUE="Send"><BR> </form> EOF; } ?> Hi there, I'm trying to add a feedback form to my website, so that people can send me emails directly from my site. I found this code on another website, which works fine except that when the sender doesn't enter their reply email address it still sends it anyway - which is what this code is supposed to prevent. This is the code: <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "myname@mydomain.com", "Subject: $subject", $message, "From: $email" ); echo "Your message has been sent"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='feedback.php'> Your Email Address: <input name='email' type='text' size='50' /><br /><br /> Subject: <input name='subject' type='text' size='50' /><br /><br /> Message:<br /> <textarea name='message' rows='15' cols='56'> </textarea><br /> <input type='submit' name='sendEMail' value='Send Email' /> </form>"; } ?> Am I supposed to redirect the user to another page? I want it to simply say "please enter your email address" next to the email field box if the user forgets to enter it. Please help. Help! I'm stuck! This is the feedback form file I made. Code: [Select] <html> <head><title>Bob's Auto Parts - Customer Feedback</title></head> <body> <h1>Customer Feedback</h1> <p>Please tell us what you think.</p> <form action="processfeedback.php" method="post"> <p>Your name:<br/> <input type="text" name="name" size="40" /></p> <p>Your email address:<br/> <input type="text" name="email" size="40" /></p> <p>Your feedback:<br/> <textarea name="feedback" rows="8" cols="40" wrap="virtual" /></textarea></p> <p><input type="submit" value="Send feedback" /></p> </form> </body> </html> And this is the process feedback file I made. Code: [Select] <?php //create short variable names $name = trim($_POST['name']); $email = trim($_POST['email']); $feedback = trim($_POST['feedback']); //set up some static information $toaddress = "wolocaw@localhost"; $subject = "Feedback from web site"; $mailcontent = "Customer name: ".$name."\n". "Customer email: ".$email."\n". "Customer comments:\n".$feedback."\n"; $fromaddress = "From: webserver@example.com"; //invoke mail() function to send mail mail($toaddress, $subject, $mailcontent, $fromaddress); ?> <html> <head> <title>Bob's Auto Parts - Feedback Submitted</title> </head> <body> <h1>Feedback submitted</h1> <p>Your feedback (shown below) has been sent.</p> <p><?php echo nl2br($mailcontent); ?> </p> </body> </html> After I fill out the form, it brings me to a page that says "Feedback submitted" at the top and "Your feedback (shown below) has been sent." below it. And that's it. nl2br($mailcontent) doesn't do anything. What am I doing wrong? I don't understand! Hello: I have this form below that stores the data in a database, and sends an email to my client so he gets the information (And if there is a more proper way to code this, I am all ears): Code: [Select] <?php include('include/myConn.php'); ?> <html> ... <?php $error = NULL; $myDate = NULL; $ParentsName = NULL; $BestPhone = NULL; $Email = NULL; $StudentsName = NULL; $StudentsSchool = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $ParentsName = $_POST['ParentsName']; $BestPhone = $_POST['BestPhone']; $Email = $_POST['Email']; $StudentsName = $_POST['StudentsName']; $StudentsSchool = $_POST['StudentsSchool']; if(empty($ParentsName)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the parent\'s name.</div>'; } if(empty($BestPhone)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the best phone number to reach you.</div>'; } if(empty($Email) || !preg_match('~^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$~',$Email)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter a valid email.</div>'; } if(empty($StudentsName)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s name.</div>'; } if(empty($StudentsSchool)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s school.</div>'; } if($error == NULL) { $sql = sprintf("INSERT INTO mySignUpData(myDate,ParentsName,BestPhone,Email,StudentsName,StudentsSchool) VALUES ('%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($ParentsName), mysql_real_escape_string($BestPhone), mysql_real_escape_string($Email), mysql_real_escape_string($StudentsName), mysql_real_escape_string($StudentsSchool); if(mysql_query($sql)) { $error .= '<div style=\'margin-bottom: 6px;\'>Thank you for using the sign-up sheet.</div>'; mail( "me@mywebsite.com", "Sign-up Sheet Request", "Date Sent: $myDate\n Parent's Name: $ParentsName Best Phone: $BestPhone Email: $Email Student's Name: $StudentsName Student's School: $StudentsSchool\n ", "From: $Email" ); unset($ParentsName); unset($BestPhone); unset($Email); unset($StudentsName); unset($StudentsSchool); } else { $error .= 'There was an error in our Database, please Try again!'; } } } ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> <div id="tableFormDiv2"> <fieldset> <hr /> </fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">* - Required</span></span> <span class="floatFormLeft"> </span></fieldset> <?php echo '<span class="textError">' . $error . '</span>';?> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Parent's Name:</span> <span class="floatFormLeft"><input type="text" name="ParentsName" size="45" maxlength="50" value="<?php echo $ParentsName; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Best Phone # To Reach You:</span> <span class="floatFormLeft"><input type="text" name="BestPhone" size="45" maxlength="50" value="<?php echo $BestPhone; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Email:</span> <span class="floatFormLeft"><input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Student's Name:</span> <span class="floatFormLeft"><input type="text" name="StudentsName" size="45" maxlength="50" value="<?php echo $StudentsName; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Student's School:</span> <span class="floatFormLeft"><input type="text" name="StudentsSchool" size="45" maxlength="50" value="<?php echo $StudentsSchool; ?>" /></span></fieldset> </div> <input type="submit" name="submit" value="Click here to submit your registration form" class="submitButton2" /><br /> </form> </html> I want to add a feature that will also send an autoresponder email with a message to the user who submitted the form. How can that be done? Do I need to somehow revise this section: Code: [Select] mail( "me@mywebsite.com", "Sign-up Sheet Request", "Date Sent: $myDate\n Parent's Name: $ParentsName Best Phone: $BestPhone Email: $Email Student's Name: $StudentsName Student's School: $StudentsSchool\n ", "From: $Email" Please let me know and thanks in advance. Hello. Basically the issue I am having is my feedback form is not grabbing the Company Name and ID from the URL. I have the php code set in place where it's supposed to post, but it's not getting it. Can someone please help me out? I'm pretty new with php, so I'm kind of at the brink of my knowledge. Thanks, Jess. Code: [Select] <?php //Modified because only email is required //if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { if (empty($_POST['email'])) { $error_msg .= "E-mail is a required field. \n"; } elseif (strlen($_POST['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!ereg("^[A-Za-z' -]*$", $_POST['name'])) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url'])) $error_msg .= "Invalid website url."; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Feedback for " . $_POST['Company']; $message = "You received this e-mail message through your website: \n\n"; foreach ($_POST as $key => $val) { $message .= ucwords($key) . ": $val \r\n"; } $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; $message .= 'Spam points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: $yourEmail \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail> \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { echo '<p>Thank you for taking the time to send us your feedback. Your comments are appreciated and help us provide the most current and accurate information possible.</p> <p>If you require further assistance, please visit our <a href="http://www.domain.com/" target="_blank">contact us</a> page.</p>'; $sentmail = 1; echo ' <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("analyticscode"); pageTracker._setDomainName(".domain.com"); pageTracker._trackPageview(); </script> '; } else { echo '<p>Your mail could not be sent this time.</p>'; } } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } ?> <?php foreach( $_POST as $checkbox ){ echo $checkbox .'<br />'; $checkbox = array("WebsiteLinkIsNotAccurate", "TelephoneNumberIsNotAccurate", "FaxNumberIsNotAccurate", "CompanyIsOutOfBusiness", "CompanyIsNoLongerAtThisLocation", "CompanyDoesNotProvideTheProductOrServiceAsFeatured", "Other(PleaseExplainBelow)"); } ?> <?php // DISPLAY ERROR MESSAGE - CHECK TO SEE IF USER HAS SUBMITTED THE FORM SUCCESSFULLY if ($error_msg != NULL) { echo '<p><strong style="color: red;">ERROR:</strong><br />'; echo nl2br($error_msg) . "</p>"; } if($sentmail == 0){ ?> <form id="feedback" name="feedback" method="post" action="feedback.php" onSubmit="return CheckForm()"> <noscript> <p><input type="hidden" name="nojs" id="nojs" /></p> </noscript> <input type="hidden" name="CompanyID" id="CompanyID" value="<?php echo $_POST['companyid']; ?>"> <input type="hidden" name="Company" id="Company" value="<?php echo $_POST['companyname']; ?>"> <p><strong>If you have different information about <u><?php echo $_POST['companyname']; ?></u>, or were unable to contact them, please let us know by completing the form below.</strong></p> ... Hi again: What I want to do - and am stuck on - is to allow the user to add files to the feedback, submit the form, and the data will get stored in the DB (and the uploaded files will get stored in "uploads"), plus an email will get sent to the client who can click the files links in the email, and download them that way. I have done this via ASP, but never tried it with PHP ... This is what my database table looks like" Code: [Select] CREATE TABLE `myProductRightData2` ( `myDate` varchar(55) default NULL, `myNameAndProduct` text, `myWebsite` text, `myProductUse` text, `myProductProblemSolver` text, `myProductUnique` text, `myWhyBetter` text, `myProductAppeal` text, `myProductSelling` text, `myProductResearch` text, `file1` varchar(255) default NULL, `myProductStory` text, `mySpokesperson` text, `myProductReviewed` text, `myProductDecision` text, `file2` varchar(255) default NULL, `file3` varchar(255) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Dumping data for table `myProductRightData2` -- INSERT INTO `myProductRightData2` VALUES('February 22, 2011', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test.pdf', 'test', 'test', 'test', 'test1.jpg', 'test2.jpg'); And this is the form code: Code: [Select] <?php $error = NULL; $myDate = NULL; $myNameAndProduct = NULL; $myPhone = NULL; $myEmail = NULL; $myWebsite = NULL; $myProductUse = NULL; $myProductProblemSolver = NULL; $myProductUnique = NULL; $myWhyBetter = NULL; $myProductAppeal = NULL; $myProductSelling = NULL; $myProductResearch = NULL; $file1 = NULL; $myProductStory = NULL; $mySpokesperson = NULL; $myProductReviewed = NULL; $myProductDecision = NULL; $file2 = NULL; $file3 = NULL; if(isset($_POST['submit'])) { if ((($_FILES["file1"]["type"] == "image/gif") || ($_FILES["file1"]["type"] == "image/jpg") || ($_FILES["file1"]["type"] == "image/jpeg") || ($_FILES["file1"]["type"] == "image/pjpeg")) && ($_FILES["file1"]["size"] < 20000)) { if ($_FILES["file1"]["error"] > 0) { echo "Return Code: " . $_FILES["file1"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file1"]["name"] . "<br />"; echo "Type: " . $_FILES["file1"]["type"] . "<br />"; echo "Size: " . ($_FILES["file1"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file1"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file1"]["name"])) { echo $_FILES["file1"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file1"]["tmp_name"], "upload/" . $_FILES["file1"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file1"]["name"]; } } } else { echo "Invalid file"; } $myDate = $_POST['myDate']; $myNameAndProduct = $_POST['myNameAndProduct']; $myPhone = $_POST['myPhone']; $myEmail = $_POST['myEmail']; $myWebsite = $_POST['myWebsite']; $myProductUse = $_POST['myProductUse']; $myProductProblemSolver = $_POST['myProductProblemSolver']; $myProductUnique = $_POST['myProductUnique']; $myWhyBetter = $_POST['myWhyBetter']; $myProductAppeal = $_POST['myProductAppeal']; $myProductSelling = $_POST['myProductSelling']; $myProductResearch = $_POST['myProductResearch']; $file1 = $_POST['file1']; $myProductStory = $_POST['myProductStory']; $mySpokesperson = $_POST['mySpokesperson']; $myProductReviewed = $_POST['myProductReviewed']; $myProductDecision = $_POST['myProductDecision']; $file2 = $_POST['file2']; $file3 = $_POST['file3']; if(empty($myNameAndProduct)) { $error .= '-- Enter your Name and Product. <br />'; } if(empty($myPhone)) { $error .= '-- Enter your Phone Number. <br />'; } if(empty($myEmail)) { $error .= '-- Enter your Email. <br />'; } if($error == NULL) { $sql = sprintf("INSERT INTO myProductRightData2(myDate,myNameAndProduct,myPhone,myEmail,myWebsite,myProductUse,myProductProblemSolver,myProductUnique,myWhyBetter,myProductAppeal,myProductSelling,myProductResearch,file1,myProductStory,mySpokesperson,myProductReviewed,myProductDecision,file2,file3) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($myNameAndProduct), mysql_real_escape_string($myPhone), mysql_real_escape_string($myEmail), mysql_real_escape_string($myWebsite), mysql_real_escape_string($myProductUse), mysql_real_escape_string($myProductProblemSolver), mysql_real_escape_string($myProductUnique), mysql_real_escape_string($myWhyBetter), mysql_real_escape_string($myProductAppeal), mysql_real_escape_string($myProductSelling), mysql_real_escape_string($myProductResearch), mysql_real_escape_string($file1), mysql_real_escape_string($myProductStory), mysql_real_escape_string($mySpokesperson), mysql_real_escape_string($myProductReviewed), mysql_real_escape_string($myProductDecision), mysql_real_escape_string($file2), mysql_real_escape_string($file3)); if(mysql_query($sql)) { $error .= 'Thank you for submitting your product. We will be in contact with you soon.'; mail( "m@sp.com", "Product Submission", "Date Sent: $myDate\n Name and Product: $myNameAndProduct\n Phone: $myPhone\n Email: $myEmail\n Website: $myWebsite\n Product Use: $myProductUse\n Problem Product Solves: $myProductProblemSolver\n Product Uniqueness: $myProductUnique\n Product Better Because: $myWhyBetter\n Product Appeal: $myProductAppeal\n Product Selling Places: $myProductSelling\n Product Research: $myProductResearch\n Research Documentation: $file1\n Product Story: $myProductStory\n Product Spokesperson: $mySpokesperson\n Product Reviewed: $myProductReviewed\n Product Decision Maker: $myProductDecision\n Samples: $file2\n $file3", "From: $Email" ); } else { $error .= 'There was an error in our database, please try again!'; } } } echo '<span class="textError">' . $error . '</span>'; ?> <form name="myform" action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> What is the name of your company and product? <textarea name="myNameAndProduct" cols="72" rows="1"><?php echo $myNameAndProduct; ?></textarea> What is your phone number? <textarea name="myPhone" cols="72" rows="1"><?php echo $myPhone; ?></textarea> What is your email? <textarea name="myEmail" cols="72" rows="1"><?php echo $myEmail; ?></textarea> website we can visit for more information? <textarea name="myWebsite" cols="72" rows="1"><?php echo $myWebsite; ?></textarea> What is this product used for? <textarea name="myProductUse" cols="72" rows="3"><?php echo $myProductUse; ?></textarea> Does this product solve a problem? If so, how? <textarea name="myProductProblemSolver" cols="72" rows="3"><?php echo $myProductProblemSolver; ?></textarea> Does your product have unique or cutting-edge features, ingredients or benefits? <textarea name="myProductUnique" cols="72" rows="3"><?php echo $myProductUnique; ?></textarea> What makes it better than similar products? <textarea name="myWhyBetter" cols="72" rows="3"><?php echo $myWhyBetter; ?></textarea> Does this product have mass appeal? Who is the target audience? <textarea name="myProductAppeal" cols="72" rows="3"><?php echo $myProductAppeal; ?></textarea> Is this product currently selling elsewhere? If so, where and what is the retail price? <textarea name="myProductSelling" cols="72" rows="3"><?php echo $myProductSelling; ?></textarea> Do you have independent research to prove claims about this product? Please provide copies. <textarea name="myProductResearch" cols="72" rows="3"><?php echo $myProductResearch; ?></textarea> Upload independent research copies (Word or PDF files): <input type="file" name="file1" id="file1" /> How and why did your company start? Does that "story" make this product more interesting? <textarea name="myProductStory" cols="72" rows="3"><?php echo $myProductStory; ?></textarea> Do you have a passionate spokesperson that would be comfortable presenting on TV? <textarea name="mySpokesperson" cols="72" rows="3"><?php echo $mySpokesperson; ?></textarea> Has this product ever been submitted to QVC for review? If yes, please provide the details. <textarea name="myProductReviewed" cols="72" rows="3"><?php echo $myProductReviewed; ?></textarea> Who from your company will make the decision to proceed if QVC is presents the right opportunity? <textarea name="myProductDecision" cols="72" rows="3"><?php echo $myProductDecision; ?></textarea> Upload two samples of your product for review (.JPG or PDF files): <input type="file" name="file2" id="file2" /> <input type="file" name="file3" id="file3" /> <input type="submit" name="submit" value="Submit New Product" class="submitButtonProduct" /><br /> </form> It's essentially the same feedback for I always use and it works fine, but I have been trying to integrate the upload portion into it from a tutorial I found on W3C: http://www.w3schools.com/PHP/php_file_upload.asp Any ideas on how to make this work? Hello: Did my first post last week and am new to PHP. Making the jump from Classic ASP into PHP. I got some good advice last time. I have a feedback form I have been using, and it works fine for sending results to the website owner. How can I add to it so it will first add all the data to mySQL database, and then email the results to the site owner? Also, I hear about SQL injection attacks a lot - is my current code safe from that? This is what I have: contact.php Code: [Select] ... <form method="post" name="myform" action="sendmail.php"> Full Name: <input type="text" name="FullName" /> Address: <input type="text" name="Address" /> City: <input type="text" name="City" /> State: <input type="text" name="State" /> Zip: <input type="text" name="Zip" /> Phone: <input type="text" name="Phone" /> Email: <input type="text" name="Email" /> Website: <input type="text" name="Website" /> Comments: <textarea cols="43" rows="6" name="Comments"></textarea> <input type="submit" /><br /> </form> ... sendmail.php Code: [Select] <?php $FullName = $_REQUEST['FullName'] ; $Address = $_REQUEST['Address'] ; $City = $_REQUEST['City'] ; $State = $_REQUEST['State'] ; $Zip = $_REQUEST['Zip'] ; $Phone = $_REQUEST['Phone'] ; $Email = $_REQUEST['Email'] ; $Website = $_REQUEST['Website'] ; $Comments = $_REQUEST['Comments'] ; mail( "info@website.com", "Contact Request", "Full Name: $FullName\nAddress: $Address\n City: $City\n State: $State\n Zip: $Zip\n Phone: $Phone\n Email: $Email\n Website: $Website\n Comments: $Comments\n", "From: $Email" ); header( "Location: http://www.website.com/thanks.php" ); ?> Any help or coding examples would be most appreciated! Thanks! Hi. Can someone show me the proper way to do a feedback form (like a "Contact US" form). I have read about SQL injections and would like to know I am protecting against it. And the proper way to store the submitted data in a database for a client's records. I have a basic form I use, but I am unable to store the data properly. Any help or a code idea would be appreciated. Thanks much. Hello need some help keep getting Code: [Select] [function.readfile]: failed to open stream: No such file or directory in code im use Code: [Select] // Ziper function zipFilesAndDownload($file_names,$archive_file_name,$file_path){ $zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) { exit("cannot open <$archive_file_name>\n"); } //add each files of $file_name array to archive foreach($file_names as $files) { $zip->addFile($file_path.$files,$files); } $zip->close(); $zipped_size = filesize($archive_file_name); header("Content-Description: File Transfer"); header("Content-type: application/zip"); header("Content-Type: application/force-download");// some browsers need this header("Content-Disposition: attachment; filename=$archive_file_name"); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-Length:". " $zipped_size"); ob_clean(); flush(); readfile($archive_file_name); unlink($archive_file_name); // Now delete the temp file (some servers need this option) exit; } if(isset($_POST['formSubmit'])) { //$file_names=$_POST['items'];// Always sanitize your submitted data!!!!!! //$file_names = filter_var_array($_POST['items']);//works but it's the wrong method $filter = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS) ; $file_names = $filter['items'] ; //Archive name $archive_file_name = 'images.zip'; //Download Files path $file_path= getcwd(). ''.$baseurl.'/cinema/'; //cal the function zipFilesAndDownload($file_names,$archive_file_name,$file_path); } html Code: [Select] <form method="post"> <input type="checkbox" name="items[]" value=" href="{$baseurl}/data/images/s/{$filename}"/> </form> Please help I have the following session variables for each item in a cart, which gets updated each time an item is added from the catalog // Register the session variables $_SESSION['ses_basket_items']=$ses_basket_items; $_SESSION['ses_basket_name']=$ses_basket_name; $_SESSION['ses_basket_amount']=$ses_basket_amount; $_SESSION['ses_basket_price']=$ses_basket_price; $_SESSION['ses_basket_stockcode']=$ses_basket_stockcode; $_SESSION['ses_basket_image']=$ses_basket_image; $_SESSION['ses_basket_size']=$ses_basket_size; $_SESSION['ses_basket_sizechoice']=$ses_basket_sizechoice; $_SESSION['ses_basket_id']=$ses_basket_id; I have a current cart page which loops through the sessions and displays them in a form. I have a check box for each item with the name="remove[]" and the value is the itemID which is the $ses_basket_id of item in the session. I have a select box with name="size[]" and the value is the users selected size for each item in the session which is $ses_basket_size Finnally I have a quantity text box with name="quantity[]" and the value is the users quantity value selected which is $ses_basket_amount. After all the looping through the products displaying each item in a row I have an update cart submit button name="change" outside the loop. What I want to know is how do I setup to perform each of these actions for each item in the session, how do I create the foreach loops for each array to delete or modify the correct items in the session if they are modified. I have the code to perform each task but dont know how to loop it through for each item in the session affecting only the correct session items. so if I have 3 items in the session for example, and I want to change the size of item 1, remove item 2 and change item 3 for quantity 1 to quantity 3 with only the 1 form and change button for all items and actions? Hope that makes sense any help with this would be appreciated. I am a new guy here and don,t have much knowledge of PHP. My problem is complex but let me explain it in simple lines. I have two different codes , 1) This code takes form entries 'website','caption' and 'name' and stores it into the Table named as 'user_info' into mysql database. This page is saved as index.php 2) This code can add add new category as a root or a child of existing category with update(edit & delete) option.This page is saved as categories.php Both codes are working(except upload function),but what i want to do is to combine the both forms (Items and category) into one page so that a user can add : webite :Its any URL caption: Description of website name: name of the person Add category:choosing existing category Add new category:If not exist add new category Tell me how can i combine both codes so that my item entries display under their categories???? 1) code for items -stores in Table 'user_info' <html> <head> <style type="text/css"> body { margin-left: 10.5%; margin-right: 10%; margin-top: 1%;} </style> <style type="text/css"> .italic { font-style:italic; color: #336666; font-family: Calibri; padding:20px; } .bold { font-weight:bold; } </style> <title>submit Bookmarks</title> </head> <body background="wrapper.png"> <form action="index.php" method="post"> <font face="Calibri">Add Your Links Here: </font> <input name="website" maxlength="100" size="58" value="http://www."> <p><font face="Calibri">Description: </font> <input name="caption" maxlength="100" size="58"> </p> <p><font face="Calibri">Your Name: </font> <input name="name" maxlength="100" size="28"> <input type="submit" name="Submit" value="Submit"> <font size="4"> </font></p> <p><font size="4"> OR </font><font color="#008080" size="2"><b><a href="soon.html"> <span style="text-decoration: none"><font color="#008080" face="Calibri">Upload</font></span></a></b></font>|<i><font size="2" face="Calibri">upload your Bookmarks from your computer. e.g., , .Csv,.txt or .mdb files.</font></i></p> <form action='upload.php' method='post'> <input type="hidden" name="sel_file" /> <font face="Calibri">Choose a file: </font> <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> </p> </form> </body></html> <?php $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "Password"; // change to your database password $database = "database-name"; // provide your database name $db_table = "user_info"; // # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); ?> <html> <head> <title>Add Your Bookmarks Here</title> </head> <body> <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(name,website,caption) values ('".mysql_real_escape_string(stripslashes($_REQUEST['name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['website']))."','".mysql_real_escape_string(stripslashes($_REQUEST['caption']))."')"; $query_auto = "INSERT INTO user_info (entry_date, col_date) VALUE ('DATE: Auto CURDATE()', CURDATE() )"; if($result = mysql_query($sql ,$db)) { echo 'Thank you, your information has been entered into our database<br><br>'; } else { echo "ERROR: ".mysql_error(); } } else { ?> <?php } ?> <?php if(isset($_POST['SUBMIT'])) { $fname = $_FILES['sel_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['sel_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into user_info(name,website,caption) values('$data[0]','$data[1]','$data[2]')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> <?php $result = mysql_query("select * from user_info ORDER BY CUR_TIMESTAMP desc"); // Database Query result ?> <?php while ($row = mysql_fetch_array ($result)) { $i++; if ($i & 1) { echo " <div class='color1'> <br/> <span class='bold'>Website:</span> <span class='normalfont' ><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . " </span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> </div>"; } else { echo " <div class='color2'> <br/> <br/> <span class='bold'>Website:</span> <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . "</span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> <br/> </div>"; } } ?> </body> 2) Code for Adding Categories <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Categories Class</title> <style> .code_div{ border:dashed #006600 1px; background:#E8FFEB; font-family:Georgia, "Times New Roman", Times, serif; font-size:11px; width:90%; padding:5px; } </style> </head> <body style="font-family:Tahoma"> <p> <?php // connect to database $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "password"; // change to your database password $database = "batabase-name"; // provide your database name $db_table = "categories"; // leave this as is # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); require_once("categories.class.php"); // Simple Usage if(!isset($_GET["id"])) $_GET["id"] =0; $ctg_id = $_GET["id"]; $categories = new categories; $categories->name_prefix = " "; ?> </p> <p>Here is it a Html Menu:</p> <br> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; </font></font><br><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">;</font></font></code> </div> <p> <? // lets display the categories $output = $categories->html_output($ctg_id); echo $output; ?> </p> <hr> <p>now I'll modify the $HtmlTree value a bit.</p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">HtmlTree </font><font color="#007700">= array( <br> </font><font color="#dd0000">"header" </font><font color="#007700">=> </font><font color="#dd0000">"<table width=200px border=0 cellpadding=2 cellspacing=2>"</font><font color="#007700">, <br> </font><font color="#dd0000">"BodyUnselected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor=#C4D9FD >[prefix]&raquo;<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"BodySelected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor="#E4DB2C">[prefix]&bull;<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"footer" </font><font color="#007700">=> </font><font color="#dd0000">'</table>'</font><font color="#007700">, <br> ); <br> <br> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">; </font></font></code> </div> <?php $categories->HtmlTree = array( "header" => "<table width=200px border=0 cellpadding=2 cellspacing=2>", "BodyUnselected" => '<tr><td bgcolor=#C4D9FD >[prefix]»<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>', "BodySelected" => '<tr><td bgcolor="#E4DB2C">[prefix]•<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>', "footer" => '</table>', ); $output = $categories->html_output($ctg_id); echo $output; ?> <hr> <? // lets get an array of the categories for our works $categories = new categories; $categories_list = $categories->build_list(); // lets do some actions if(!isset($_REQUEST['act'])) $_REQUEST['act'] = ""; $act = $_REQUEST["act"]; switch($act) { case "add": // lets add new category // $categories->add_new( category parent , category name , description , icon path , group ) $categories->add_new($_POST['parent'] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was inserted successfully into database"); location="class_categories_test.php"; </script>'; break; case "delete": $categories->delete($_GET["id"]); echo '<script>alert("Category and Sub-Categories was successfully deleted"); location="class_categories_test.php"; </script>'; break; case "_update": $cat = $categories->fetch($_GET["id"]); ?> <form name="form1" method="post" action=""> <p> the form below will execute the following. <br> </p> <div class="code_div"> <code><font color="#000000"><font color="#007700"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">update</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"id"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"parent"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] );</font></font></code> </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3"><div align="center">Edit Category </div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"> <select name="parent" id="parent"> <option value="0" selected>ROOT</option> <? foreach($categories_list as $c) { if($cat["id"] == $c["id"]) continue; // we don't list the category to be child of itself !! ?> <option value="<?=$c["id"]?>" <? if($c["id"] == $cat["parent"]) echo "selected"; ?> ><?=$c["prefix"]?>»<?=$c["c_name"]?></option> <? } ?> </select> </td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" value="<?=$cat["c_name"]?>" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"><?=$cat["c_desc"]?> </textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="<?=$cat["c_icon"]?>" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="update"> <input name="id" type="hidden" value="<?=$ctg_id?>"> <input type="submit" name="Submit" value="Save"> </div></td> </tr> </table> </form> <? die(); break; case "update": $categories->update($_POST["id"] , $_POST["parent"] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was updated successfully!"); location="class_categories_test.php"; </script>'; break; } ?> <p align="center"> </p> <p align="center"><strong>You may list all your categories expanded like this</strong></p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; <br> </font><font color="#0000bb">$categories_list </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">build_list</font><font color="#007700">(0);</font></font></code> <br>// $categories_list is now an array and you should use foreach command to print something like the following list. </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td bgcolor="#4180BE"><font color="#FFFFFF"><strong> Categories List: </strong></font></td> </tr> <? foreach($categories_list as $c) { ?> <tr> <td> <?=$c["prefix"]?>»<?=$c["c_name"]?> - [<a href="?act=_update&id=<?=$c["id"]?>">Edit</a> - <a href="?act=delete&id=<?=$c["id"]?>">Delete</a>] </td> </tr> <? } ?> </table> <p align="center"> </p> <p align="center"><strong>Or you may also use it in a combo box</strong></p> <table width="0" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="72"><select name="category_id" id="category_id"> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>"><?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> <td width="0"><input type="button" name="Button" value="Edit" onClick="location='class_categories_test.php?act=_update&id='+document.getElementById('category_id').value;"></td> <td width="0"><input type="button" name="Button" value="Delete" onClick="location='class_categories_test.php?act=delete&id='+document.getElementById('category_id').value;"></td> </tr> </table> <p> </p> <p><hr></p> <form name="form1" method="post" action=""> the form below will execute the following. <br> <div class="code_div"> <code><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">add_new</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">'parent'</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] ); </font></font></code></div><br> <table width="400" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3" bgcolor="#4180BE"><div align="center"><strong><font color="#FFFFFF">Add New Category </font></strong></div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"><select name="parent" id="parent"> <option value="0">ROOT</option> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>" > <?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"></textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="http://" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="add"> <input type="submit" name="Submit" value="Add"> </div></td> </tr> </table> </form> <p align="center"> </p> </body> </html> Sorry for making this long post,hope u won,t mind :-) and will solve my problem This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=347660.0 Hi guys, I have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that This seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error. Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } I am in the process of writing a class to get the ip address and the referring site to store in a database. I am not all that familiar with writing classes and want to make sure that I am on the right path. If I am doing something wrong in it please explain it to me so I can learn
class browser_ip_ref{ private $_db; private $_ip; private $_url; public function __construct($db,$ip,$url){ $this->_db = $db; $this->_ip = ip2long($_SERVER["REMOTE_ADDR"]); $this->_url = $_SERVER['HTTP_REFERER']; } function getIp(){ if($this->_ip){ if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $this->_ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $this->_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } return $this->_ip; } } function insertInfo($this->_ip, $pageID, $browser, $version){ $country_code = $this->_db->query("SELECT `ci` from `ip` WHERE ".$this->_ip." BETWEEN `start` AND `end`"); $country_code = $country_code->fetch_array(MYSQLI_ASSOC); $countryID = $country_code['ci']; $ipCount = $this->_db->("SELECT COUNT(*) AS count from `hit_counter_info` WHERE `longIP` = ".$this->_ip." AND `pageID` = $pageID"); $total = $ipCount->fetch_array(MYSQLI_ASSOC); $num_rows = $total['count']; if ($num_rows < 1) { //if not in the database add it. $this->_db->("INSERT INTO `hit_counter_info` (`longIP`,`pageID`,`cc`,`browser`,`version`) VALUES ('".$this->_ip."', '".$pageID."', '".$countryID."', '".$browser."', '".$version."')"); } } function insertRef(){ $url_parts = parse_url($this->_url); $host_parts = explode( '.', $url_parts['path']); $tld = end($host_parts); $good_tld = array('com','org','edu','uk','net','ca','mil','de','jp','fr','au','us','ru','ch','it','nl','se','no','es'); if (empty($url)) { $this->_db->("UPDATE `hit_counter_referrers` SET `ref_count` = ref_count + 1 WHERE `ref_url` = 'bookmarked'"); } else if (in_array($tld, $good_tld)) { $rowCount = $this->_db->("SELECT COUNT(*) AS count from `hit_counter_referrers` WHERE `ref_url` = '$this->_url'"); $total = $rowCount->fetch_array(MYSQLI_ASSOC); $num_rows = $total['count']; if ($num_rows > 0) { $this->_db->("UPDATE `hit_counter_referrers` SET `ref_count` = ref_count + 1 WHERE `ref_url` = '$this->_url'"); } else { $this->_db->("INSERT INTO `hit_counter_referrers` (`ref_url`,`ref_count`) VALUES ('$this->_url', 1)"); } } } } I'm running one of those really dense zend-based frameworks with masses of recursion (Magento), and I'm getting a problem with reading/writing the session, before I deal with that I'm trying to find some feedback on where the issue is happening. I've got everything ( i know of ) switched on, error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); + I'm using PHPStorm with Xdebug and I've got Php Exception breakpoint set, I'm watching the Phpstorm Output/Console/Terminal (don't quite know the difference) +var/log/Exception.log, but....It just hangs without telling me which line. Is this someting I've got to take on the chin with Php (I'm a relative newbie)? Or is there some way else? Debian/Php 7.3 Hi guys,
Have some questions about "SESSIONS".
I am setting: $_SESSION['sessionID'] = session_id(); BUT not sure how to use it correctly or what for?
Is code below acceptable?
Any suggestions for improvements?
<?php error_reporting(-1); ini_set('display_errors', 'On'); spl_autoload_register(function ($class) { include 'lib/' . $class . '.inc'; }); session_start(); // =============================================================== if (isset($_GET['msg'])){ echo $_GET['msg']; } // =============================================================== if (isset($_POST['btn_login']) && !empty($_POST['btn_login'])){ $_SESSION['logged'] = "true"; $_SESSION['sessionID'] = session_id(); session_write_close(); header( 'Location: http://localhost/work/index.php?msg=Logged in!' ) ; } // =============================================================== if (isset($_POST['btn_logout']) && !empty($_POST['btn_logout'])){ //true $_SESSION['logged'] = ""; $_SESSION['sessionID'] = ""; session_write_close(); session_destroy(); header( 'Location: http://localhost/work/index.php?msg=Logged out!' ) ; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Server Status</title> </head> <body> <?php // =============================================================== if (!$_SESSION['logged'] == true){ ?> <form action="#" method="post" enctype="application/x-www-form-urlencoded" name="user-login"> <input name="btn_login" type="submit" value="Logon" /> </form> <?php }else{ ?> <form action="#" method="post" enctype="application/x-www-form-urlencoded" name="user-login"> <input name="btn_logout" type="submit" value="Logout" /> </form> <?php } ?> </body> </html>Kind regards and thanks. Hi, I've been using this tutorial all afternoon, and it's been great, but I wonder if it's outdated... http://www.tizag.com/phpT/index.php I'm using WAMPSERVER 2.2 and PHP 5.3.10 Any recommendations for good up-to-date/relevant tutorials? Thanks |