Jump to content

Perad

Members
  • Posts

    287
  • Joined

  • Last visited

    Never

Everything posted by Perad

  1. if you start the profile page with $_GET['u'] You can then search the database and return the details of that specific user.
  2. $lastlogin = strtotime($row['last_login']); $now = strtotime(now); $difference = date("u", $now) - date("u", $lastlogin); I want to know if there is an hour difference between now and when the user last logged in. How do I do this as I am completely failing when I try to subtract the two with date functions.
  3. for ($i=0;$i<=count($item)-1;$i++) { <input type=\"submit\" class=\"select\" name=\"$item[$i]\" value=\"\"> } Multiple forms... each submit button has a different name. Name is based on the item code and thus I do not know it. Only one submit button can be pressed. Because I cannot put in $_POST['name'] I need to be able to sign the first value in the $_POST array to a variable. I tried $_POST[0] but it didn't work. furthermore current($_POST) also didn't work.
  4. I mean that I want to gather only one $_POST item and that is the first post item so I can use it later on in my script.
  5. I want to select the first item of the post array. How do i do it?
  6. For some reason the if statement keeps coming up as true. This is even if "Call+Out+Fee+for+" isn't in the string being tested. Could someone help me correct this please if (preg_match("Call+Out+Fee+for+", $req)) { preg_match('/item_name1[^&]+/', $req, $out); $vowels = array("item_name1=", "Call+Out+Fee+for+", "%3A00", "%23"); $a = str_replace($vowels, "", $out[0]); $b = str_replace("%23", "*", $a); $c = str_replace("+on+", "*", $b); $d = str_replace("+", "*", $c); $pieces = explode("*", $d); preg_match('/payer_email[^&]+/', $req, $out2); $a = str_replace("payer_email=", "", $out2[0]); $email = str_replace("%40", "@", $a); include 'RCMConnect.php'; echo $sql; $sql = "UPDATE bookings SET confirm='1' WHERE bookingtime='".$pieces[1]."' AND bookingdate='".$pieces[2]."' AND conf='".$pieces[0]."'"; $result = mysql_query($sql); } else { preg_match('/item_name1[^&]+/', $req, $out); $a = str_replace("+for+", "*", $out[0]); $b = str_replace("+", " ", $a); $pieces = explode("*", $b); include 'RCMConnect.php'; $sql = "UPDATE bookings SET confirm='1' WHERE user='".$pieces[1]."' AND type='".$pieces[0]."'"; $result = mysql_query($sql); }
  7. The key part of this string is the following... item_name1=Call+Out+Fee+for+14%3A00+on+29%2F8%2F2007 The whole string is... I need to get out the Call+Out+Fee+for+14%3A00+on+29%2F8%2F2007. I can tidy this up myself, its just a case of actually getting it out of the big string. The content changes so ideally I need something which will cut between "item_name1=" and "&". I need to do this a few times and once I learn to do it once I can do it for the rest.
  8. This returns Array ( [imagefile] => Array ( [name] => mba-il9pro.jpg [type] => image/jpeg [tmp_name] => /tmp/phpagO6ad [error] => 0 => 56428 ) )
  9. The error I am getting is There was an error uploading the file, please try again! I have been playing around with the path and still no joy, is there some sort of "or die" statement I can use here to help troubleshoot?
  10. It returns an error every time.. I just want it to upload a file into a folder called root/uploads I haven't added any security yet, i just wanted to get it running. target_path echos out /uploads/ <?php // Where the file is going to be placed $target_path = "/uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); echo $target_path; 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!"; } ?> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <label>Image Name</label> <input type="file" name="imagefile" value="" /><br /> <input type="submit" name="submit" value="submit" /> </form>
  11. Form <form action="build.php?page=process&part=<?php print $row['itemcode'] ?>" class="part" enctype="multipart/form-data" method="post"> <label>Item Code</label> <input type="text" name="itemcode" value="<?php print $row['itemcode']; ?>" /><br /> <label>Item Name</label> <input type="text" name="item" value="<?php print $row['item']; ?>" /><br /> <label>Brand/Model</label> <input type="text" name="model" value="<?php print $row['model']; ?>" /><br /> <label>Weight</label> <input type="text" name="weight" value="<?php print $row['weight']; ?>" /><br /> <label>Price</label> <input type="text" name="price" value="<?php print $row['price']; ?>" /><br /> <label>Image Name</label> <input type="file" name="imagefile" value="<?php print $row['image'] ?>" /><br /> <input type="submit" name="submit" value="submit" /> </form> Loop foreach($_POST as $K => $V) { echo $K; } Result itemcode item model weight price submit Where is the file field!?
  12. Is there someway I can clean this query to make it work with MySQL, I think it is going wrong because mysql is interpretting the - in the item code as a minus. Query is the following. UPDATE p_MUM - INOPT SET mconnec = 'USB', itemcode = 'MUM-INOPT', item = 'MicroSoft IntelliMouse Optical - PS2/USB', model = 'Microsoft D58-00017', tm = 'Optical', mwireless = 'No', tr = '800dpi', mdocking = 'Yes', mrecharge = '', mbuttons = '5', mscroll = 'Yes', weight = 'PS2, USB 1.1/2.0', price = '0.50', WHERE itemcode = 'MUM-INOPT' Error starts at '-INOPT" so it must be the - character. My PHP is... foreach($_POST as $K => $V) { //may want to clean $K as well if ($K == "submit") { } else { if ($_GET['page'] == "process") { $databaseentry .= $K . "='" . $this->cleanString($V). "', "; } else { $Clean[$K] = $this->cleanString($V); } } } if ($_GET['page'] == "process") { } else { $fields = implode(",",array_keys($Clean)); $Values = implode("','",$Clean); } if ($_GET['page'] == "process") { $sql = "UPDATE p_$cleanpart SET $databaseentry WHERE itemcode='".$_POST['itemcode']."'"; echo $sql; } else { $sql = "INSERT INTO p_$cleanpart ($fields) VALUES ('$Values')"; } $result = mysql_query($sql) or die(mysql_error());
  13. I have this line. $form .= "<td>£$price[$i] ex VAT <br />£".$price[$i]*1.175." inc VAT</td>"; this returns £41.95 ex VAT £49.29125 inc VAT I would like the inc VAT price to become £49.29 I have tried $form .= "<td>£$price[$i] ex VAT<br />£".printf("%.2f", ($price[$i]*1.175))." inc VAT</td>"; But this doesn't work, does anyone have any other suggestions?
  14. Ah thank you so much, just needed to filter out the $_POST['submit'] and it ran perfectly, now I have a shot of finishing this today
  15. ok I have 20 forms each with 20+ inputs. After writing an SQL function for 1 I have realised that I would rather chop of my balls than do the rest of them manually. Is it possible to loop through $_POST so it will do something like this this... In this case $_POST would be 'mwireless'... $mwireless = $this->cleanString($_POST['mwireless']); $sql = "INSERT INTO dbname (mwireless, ... ) VALUES ('$mwireless',..)"; Please tell me this can be done.
  16. This 20/8/2007 could become 20/10/2007. The date can increase and decrease by 1 integer
  17. I think i might need to use preg_replace. However I have never used it before and can't workout how to find the following. This is my string.. Call Out Fee for 10:00 on 20/8/2007 What I need is for this string to be reduced to 10:00 and 20/8/2007. These values would preferably be in an array. Could someone give me a hand with this please.
  18. Ah works a treat, thanks for your time and thank you very much for your help.
  19. I am having some trouble with a booking system. What I want to do it is make booked times display in red. Available times in white. Below is my function. It works for no, or one booking. However if you do a second booking everything comes unstuck, its pretty obvious why but I can't figure out any other way to do this. public function DisplayDay($date) { $theday = date('l', $date); if ($theday == "Saturday") { $starttime = "10"; $endtime = "12"; } else { $starttime = "10"; $endtime = "16"; } $sql = "SELECT * FROM bookings WHERE bookingdate='$date'"; $result = mysql_query($sql); if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { $bookedtimes[] = $row['bookingtime']; } } print "<table><tr><td>$theday</td></tr>"; for ($time=$starttime;$time<=$endtime;$time++) { $newtime = $time.":00 - ". ($time+1).":59"; if ($bookedtimes) { foreach($bookedtimes as $value) { echo $time . " = " . $value . "<br />"; if ($time == $value) { echo "<tr><td style=\"background:#713b3b;\">$newtime</td></tr>"; } else { echo "<tr><td style=\"background:#FFF;\"><a href=\"$page?book=$time&date=$date\">$newtime</a></td></tr>"; } } } else { echo "<tr><td style=\"background:#FFF;\"><a href=\"$page?book=$time&date=$date\">$newtime</a></td></tr>"; } $time++; } print "</table>"; } If 1 bookings is made then the array loops through once as so.. 10 = 10 - red 12 = 10 - white 14 = 10 - white 16 = 10 - white If there are 2 bookings then everything goes wrong. 10 = 10 - red 10 = 14 - white 12 = 10 - white 12 = 14 - white 14 = 10 - white 14 = 14 - red 16 = 10 - white 16 = 14 - white Does anyone have any ideas on to how I can rewrite the for statement?
  20. I was just wondering how I would get the day of the week from the string "12/07/07".
  21. 0 is the id of a guest, perhaps I better change that to -1. I am only changing it when the user log's in. My class so far. class Login { public $message; public $error; public $loggedin; private function cleanString($string) { $string = trim($string); $string = stripslashes($string); $string = strip_tags($string); return $string; } public function loginCheck() { if (isset($_SESSION['user'])) { $this->loggedin = TRUE; } else { $_SESSION['id'] = "0"; $_SESSION['user'] = "Guest"; } } public function parseLogin($user, $pass) { $clean_user = $this->cleanString($user); $clean_pass = md5($this->cleanString($pass)); $sql = "SELECT username FROM member WHERE password='$clean_pass'"; $result = mysql_query($sql); if (mysql_num_rows($result)) { $sql = "SELECT id FROM member WHERE username='$clean_user'"; $result = mysql_query ($sql); $row = (mysql_fetch_assoc($result)); unset($_SESSION['id']); unset($_SESSION['user']); $_SESSION['id'] = $row['id']; $_SESSION['user'] = $clean_user; } } }
  22. I want this code to check if the session "user" is up and running. if so set a variable to true, otherwise set it to guest... however it seems to be setting the variable to guest no matter what the session is set to. I'm staring at this bit of code and just cannot see what is wrong. Can anyone help me out? public function loginCheck() { if (isset($_SESSION['user'])) { $this->loggedin = TRUE; } else { $_SESSION['id'] = "0"; $_SESSION['user'] = "Guest"; } }
  23. Its been a while since I have used classes and I am obviously doing something wrong. When I submit the form nothing is happening. Could someone tell me what I need to do to actually make something happen. Head of register.php <?php include 'functions.php'; if ($_POST['register']) { $register = new Register; $register->SQL($_POST['user'], $_POST['pass'], $POST['confpass'], $POST_['email']); } ?> register.php content <?php if ($register->error || $register->message) { print $register->error; print $register->message; } else { ?> <form name="register" action="register.php" method="post"> Username:<input type="text" name="user" class="login" value="" maxlength="20"> Password:<input type="text" name="pass" class="login" value="" maxlength="20"> Confirm Password:<input type="text" name="confpass" class="login" value="" maxlength="20"> E-Mail:<input type="text" name="email" class="login" value="" maxlength="40"> <input type="submit" value="Register" name="Register" /> </form> <?php } ?> functions.php <?php class Register { public $message; public $error; public function SQL($user, $pass, $confpass, $email) { echo "ha"; $clean_user = $this->cleanString($user); $clean_pass = $this->cleanString($pass); $clean_confpass = $this->cleanString($confpass); $clean_email = $this->cleanString($email); if ($clean_pass == $clean_confpass) { $sql = "INSERT INTO members (username, password, email, join) VALUES ('$clean_user', '$clean_pass', '$clean_email', NOW())"; $result = mysql_query($sql) or die(mysql_error()); if ($result) { $this->message = "Congrats, you have successfully registered"; } else { $this->error = "There has been an error, please try again later"; } } else { $this->error = "Error: Your passwords do not match"; } } private function cleanString($string, $length) { $string = trim($string); $string = stripslashes($string); $string = strip_tags($string); $string = substr($string, 0, $length); return $string; } } Any help with this is every much appreciated
  24. I forgot to say that times are savedd as datetime in my db
  25. I am having a bit of trouble working out how to do this. I just want to get all articles posted within a month, unfortunately I am not having much luck does anyone know whow to do this?
×
×
  • 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.