Jump to content

phily245

Members
  • Posts

    47
  • Joined

  • Last visited

    Never

Everything posted by phily245

  1. I've logged in multiple times (nd am currently logged in), but I cannot find any session files in the /tmp directory :/
  2. Hi all, I have a session problem on my development site. Whenever I go to my login screen at www.mydomain.com/my/path/index.php, i get the following error messages: However, when I go to mydomain.com/my/path/index.php, the error messages aren't there. I am very confused. We don't have an SSL (which google suggested it could be) or any whitespace between the opening php tag. I have chmoded the /tmp directory to 777 but to no avail. Any ideas? My opening code is below: <?php session_start(); require_once("includes/db_connector.php"); include("includes/cms_class.php"); include("includes/login_class.php"); loginForwarder(); $issue = checkLoginIssue(); if (isset($_POST["login"])) { loginUser($_POST["email"], $_POST["password"]); } ?> <!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"><!-- InstanceBegin template="/Templates/my_template.dwt.php" codeOutsideHTMLIsLocked="false" -->
  3. http://lmgtfy.com/?q=php+login+tutorial
  4. I had an extra i in $_POST["expiryDate"] when submitting the date. I just want to crawl away and hide in shame.
  5. <?php echo $_POST["startDate"]; ?> echos 20-11-2011 (if the date selected is the 20th November 2011)
  6. It's meant to validate to 3rd August. We expect the user to enter it this way, as the end users are from the UK (like me) and we use dd-mm-yyyy. I also have an instruction to do it this way in the label on the field which the user enters the date into. I think a select statement will be overkill, as the dates needed can be from tomorrow to in multiple years time.
  7. It's still not working, gah! I tried what you suggested, then I tried using another one I found on google and slightly modified: <?php if(!preg_match('/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', $expiryDate) or !preg_match('/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', $startDate)) { $issue = "9"; return $issue; } ?> I need the - seperator so that I can use explode() on the date function. When I get this working with just a -, I'm going to add support for [- \/\.] and a switch statement for the explode.
  8. move: <?php $query = "INSERT INTO carmansa.t_imagenes (id_categoria,imagen_antes_txt_esp,imagen_despues_txt_esp,imagen_antes_txt_eng,imagen_despues_txt_eng,imagen_before,imagen_after) ". "VALUES ('$categoria','$textoantesesp','$textodespuesesp','$textoanteseng','$textodespueseng','$image1','$image2')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); ?> to after: <?php header("Location: PC_images_inserted.php"); } ?> The code is currently inside the for loop, so it will insert records twice. I'd recommend coding on notepad++ or another program with similar syntax highlighting, as it highlights your curly braces and shows what is contained inside loops and if statements etc.
  9. Have you put the query inside the for loop?
  10. Thanks for the advice. I changed my regex to the following code, but it still wouldn't work. <?php if(!preg_match('/^\d{2}-\d{2}-\d{4}$/', $expiryDate)) { $issue = "9"; return $issue; } if(!preg_match('/^\d{2}-\d{2}-\d{4}$/', $startDate)) { $issue = "9"; return $issue; }?>
  11. Hi lingo, I missed a line out. This: <?php //Declare the target location and move the file there $target = $target . ${image.$i}; $target = $target . basename(${image.$i}); move_uploaded_file(${tmpImage.$i}, $target); ?> Needs to be this: <?php //Declare the target location and move the file there $target = 'uploads/'; //Declare your upload path here $target = $target . ${image.$i}; $target = $target . basename(${image.$i}); move_uploaded_file(${tmpImage.$i}, $target); ?> And your new query should be inside the for loop beneath where you add to the array and look like this: <?php $query = "INSERT INTO carmansa.t_imagenes (id_categoria,imagen_antes_txt_esp,imagen_despues_txt_esp,imagen_antes_txt_eng,imagen_despues_txt_eng,imagen_before,imagen_after) ". "VALUES ('$categoria','$textoantesesp','$textodespuesesp','$textoanteseng','$textodespueseng','$target','$target')"; ?> I'm not sure why you need to enter the file path in twice though, is that a mistake?
  12. You need this: <?php $from = "$string@website.com" ?> to be this: <?php $from = $string."@website.com"; ?>
  13. Hi, I'm using the JQuery UI datepicker to insert a date into a form field, but I need validation in case the user enters the date by hand. The date needs to be dd-mm-yyyy. I currently have this: <?php if(!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $expiryDate)) { $issue = "9"; return $issue; } if(!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $startDate)) { $issue = "9"; return $issue; } ?> But it's not working and I'm pretty sure its the regex.
  14. On your form, have this for all the file uploads <label for="image[]">LABEL HERE</label><input type="file" name="image[]" id="image[]" /> Then, use this script inside your "if submitted" if statement to upload your files <?php //Declare the variables for the first image $image1 = $_FILES['image']['name'][0]; $tmpImage1 = $_FILES['image']['tmp_name'][0]; $imageError1 = $_FILES['image']['error'][0]; //Declare the variables for the second image $image2 = $_FILES['image']['name'][1]; $tmpImage2 = $_FILES['image']['tmp_name'][1]; $imageError2 = $_FILES['image']['error'][1]; //For both the images for ($i = 1; $i <= 2; $i++) { //If there is a file if(${image.$i} != '' && ${tmpImage.$i} != ''){ //If there is an error with the file uploaded if(${imageError.$i} > 0) { //Provide an error message }else{ //encode the image name for the www urlencode(${image.$i}); //If magic quotes are off if(!get_magic_quotes_gpc()) { ${image.$i} = addslashes(${image.$i}); $target = addslashes($target); } //Declare the target location and move the file there $target = $target . ${image.$i}; $target = $target . basename(${image.$i}); move_uploaded_file(${tmpImage.$i}, $target); } }else{ //If there is an error with the file uploaded if(${imageError.$i} > 0) { //Provide an error message }else{ //Declare the target $target = '../img/none.jpg'; } //Add the target to the fileinsert array $fileinsert[]=$target; } ?> [code]
  15. Use a for loop, like the one below: <?php //Set the length $length = 10; //For however many time you specified above for ($p = 0; $p < $length; $p++) { //Send the email mail($to,$subject,$message,$headers); } ?>
  16. Hi all, I have a problem with emailing php code using a php function. using the code below, It emails the message 2 times with blank content. I think the problem might be with the eval() or file_get_content(), because if I comment it out the eval() and replace $message with a static value, it sends the message once with the static content. The functions safeText (which does a mysql_real_escape_string), returnShopName (which returns the shop name) and returnShopEmailURL(which returns the url of the shop minus the http://www) all work, as they are used in other functions. here is the function: <?php //Email a link to the voucher function emailVoucher($id) { //Ensure no one can use a combined URL and SQL Injection attack, as it comes from a $_GET $id = safeText($id); //Query the database, count the results and make an array to hold them $query = mysql_query("SELECT * FROM shop_vouchers WHERE voucher_id = '".$id."' LIMIT 1") or die ('Error: '.mysql_error()); $count = mysql_num_rows($query); $fetch = mysql_fetch_array($query); //If there are results if($count == 1) { $to = $fetch["voucher_email"]; $subject = 'Your voucher from '.returnShopName(); $headers = 'From: website@'. returnShopEmailURL() . "\r\n" . 'Reply-To: no-reply@'. returnShopEmailURL() . "\r\n" . 'X-Mailer: PHP/' . phpversion() . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html' . "\r\n"; $link = 'http://www.example.com/vouchers.php?email=1'; $name = returnShopName(); $URL = returnShopEmailURL(); $body = file_get_contents('includes/voucher_email.php'); eval("\$body = \"$message\";"); mail($to, $subject, $message, $headers); gotoURL("vouchers.php?issue=1"); }else{ //Popup error message and redirect echo '<script type="text/javascript">'; echo 'alert("An error occurred. Please try again.")'; echo '</script>'; gotoURL("vouchers.php"); } } ?> the code in voucher_email.php (for testing purposes) is: $name 1, $link 2, $URL 3
  17. I was expecting to have to do something waaaay more complicated than that. Problem solved. Sometimes it just takes someone to say stop overcomplicating things.
  18. Sorry, that was a mistype. Try using this thread post: http://forums.digitalpoint.com/showthread.php?t=16822
  19. $issue contains a text string, created by my switch in the code in the initial post: <?php //If there is an error code if (isset($_GET["issue"])) { //cycle through the list until the code is reached, return the text and break the switch switch ($_GET["issue"]) { case "1": $issue = '<p class="warning">Please log in to view this page</p>'; break; case "2": $issue = '<p class="warning">Wrong Username or Password</p>'; break; case "3": $issue = '<p class="warning">No user found with those details</p>'; break; } ?> return compact returns an array containing the variables and their variables, so in the case of switch case("3"), the array the function outputs would be: <?php array("issue" => "<p class="warning">No user found with those details</p>"); ?> which, when extracted, brings the following variable onto the page to use as though I had hand coded it: <?php $issue = '<p class="warning">No user found with those details</p>'; ?>
  20. It currently returns $issue as a variable like I'd hand coded it onto the page, eg '$issue = "Example";'. This works, however the error message still occurs.
  21. If you dont mind a page refresh, try adding this code to the select button (replacing my_page.php with your page url): onChange="javascript: window.location = 'my_page.php?uan='+this.value;" and at the top of the page add this: <?php if(isset($_GET["uan"]) &&$_GET["uan"] !='') { $uan = $_GET["uan"]; } ?>
  22. Hi. I have some code which needs to return a single variable from the function and stored as a variable within this page, so it can be echoed later on in the page. I couldn't get it to return as a variable, so i used "return compact();" to return the variable and "extract (myFunction());" to extract it to variables. However, when I turned on php's display errors and error reporting function, I got an error message saying "Warning: extract() [function.extract]: First argument should be an array in /my/web/site/index.php on line 6" (which is where my extract function is). This works fine with passing more than one variables through, is there another way pass one variable from a function to be stored as a variable on the page which called the function? Here is the function: <?php //This is a list of numeric error codes against their text. this will return the error code as the variable $issue function checkLoginIssue() { //If there is an error code if (isset($_GET["issue"])) { //cycle through the list until the code is reached, return the text and break the switch switch ($_GET["issue"]) { case "1": $issue = '<p class="warning">Please log in to view this page</p>'; break; case "2": $issue = '<p class="warning">Wrong Username or Password</p>'; break; case "3": $issue = '<p class="warning">No user found with those details</p>'; break; } //return the variable in an array with a single value return compact('issue'); } } ?> And here is the code which calls the function: <?php extract(checkLoginIssue()); ?>
  23. I have a problem with an amend to an admin system I am trying to change. The shop stocks different colours of each product and the client wants to be able to update the stock levels of all colours of one product (which all share the same title) on one form. I have tried following some instructions on some sites and tried making my own and I can get it to display the form and the values correctly, but on submission it does nothing but direct me to a page without a title value in the address (e.g. www.example.com/example/stock_level_2.php?title=). I think it may be to do with the arrays I am using, has anyone got any ideas? Here is the code. Form: <?php $pd_title = str_replace("_"," ",$_REQUEST["title"]); $pd_title = str_replace("%","&#37;",$pd_title); $pd_title = str_replace("/","&#47;",$pd_title); $lookupqueryc = mysql_query("SELECT * FROM product WHERE pd_title = '".$pd_title."' ORDER BY pd_id DESC"); echo '<table><tr><th align="center" class="bodytext">Product<br />ID</th><th align="center" class="bodytext">Product Name</th><th align="center" class="bodytext">Stock Level</th></tr>'; $form = '<form name="frmAmendStock" method="post" action="stock_level_2.php?title="'; $form .= $_GET["title"]; $form .= '" enctype="multipart/form-data">'; echo $form; echo '<input name="submitted" type="hidden" value="true">'; $count=mysql_num_rows($lookupqueryc); echo '<input name="count" type="hidden" value="'; echo $count; echo '">'; while($lookupresultc = mysql_fetch_array($lookupqueryc)){ echo '<tr><td align="center" class="bodytext">'; $id[]=$lookupresultc["pd_id"]; echo $lookupresultc["pd_id"]; echo '</td><td class="bodytext">'; echo $lookupresultc["pd_title"]; if (isset($lookupresultc["pd_colour"]) && $lookupresultc["pd_colour"] !="") { echo " ("; echo $lookupresultc["pd_colour"]; echo ')'; } if ($lookupresultc["pd_stock"] <= 5) { echo '</td><td align="center" class="bodytext" style="border: 2px solid red;">'; echo '<input name="stock[]" type="text" id="stock" value="'; echo $lookupresultc["pd_stock"]; echo '"style="width: 50px;" />'; echo "</td></tr>"; }else{ echo '</td><td align="center" class="bodytext">'; echo '<input name="stock[]" type="text" id="stock" value="'; echo $lookupresultc["pd_stock"]; echo '"style="width: 50px;" />'; echo "</td></tr>"; } } ?> <tr> <td> </td> <td height="35"><a href="javascript: " onClick="javascript:document.forms.frmAmendStock.submit()" class="bodytext"><strong>click here to amend your stock </strong></a></td> </tr> </form> </table> And here is the code it should run on submission: <?php if (isset($_POST["submitted"])) { for($i=0;$i<$_POST["count"];$i++){ mysql_query("UPDATE product SET pd_stock='$stock[$i]' WHERE pd_id='$id[$i]'"); } } ?>
  24. Thanks guys, sometimes it just needs a fresh pair of eyes!
×
×
  • 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.