Jump to content

kayz100

Members
  • Posts

    33
  • Joined

  • Last visited

kayz100's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi guys, thanks for all your help. I am trying to use php pagination without mysqli on one of my pages and I have the following php script. however, it keeps outputting an error that $page is not indexed please help and also how to put a css style attribute to my arrays. <?php $array = array('Music and chairs','hello mama','c','d','e','f','g','h','i','j'); //failing to put styles on this info array $total_data = count($array); // COUNTING TOTAL ARRAY $per_page = 3; // Outputting error on the $page below $page = intval($_GET['page']); // Error output is this - Undefined index: page if(empty($page) || $page==1) { $start_val = 0; $end_val = $per_page - 1; } else { $start_val = ($page * $per_page) - $per_page; $end_val = $start_val + ($per_page - 1); } //Echoing my array and failing to use my css for($i=$start_val;$i<=$end_val;$i++){ echo $array[$i].' '; } $less_than = $total_data/$per_page; if($less_than>intval($less_than)) $less_than = $less_than + 1; if($total_data>1) { echo '<div class="pagination">'; echo ($page-1)>0?'<a href="?page='.($page-1).'">Previous</a> ':'Previous '; for($i=1;$i<=$less_than;$i++){ if($page==$i) echo '<a class="paginator linkno">'; else echo '<a href="?page='.$i.'" class="paginator">'; echo $i; echo '</a> '; } echo ($page+1)<=$less_than?'<a href="?page='.($page+1).'">Next</a>':'Next'; echo '</div>'; } ?>
  2. Hi guys, Please help, my css image enlarge on mouse hover is not behaving. The main div is failing to center even though I have used margin:0 auto; I want it to enlarge image on hover without adjusting other div elements. I would love it to enlarge image with text, tried using javascript but no success. <html> <head> <style type="text/css"> .myimg { position:relative; width:50%; top:0px; } .myimg:hover { width:80%; z-index:9999; } .Enlrg ul {clear:both; list-style-type:none; } .Enlrg li {width:20%; float: left; overflow:visible; display: block; } </style> </head> <body> <div style="margin:0 auto; background:gray; width:80%;"> <div class="Enlrg"> <ul> <li><img class="myimg" src="pic1.jpg" alt="Rocasa Future classroom" /></li> <li><img class="myimg" src="pic2.jpg" alt="Rocasa Future classroom" /></li> <li><img class="myimg" src="pic3.jpg" alt="Rocasa Future classroom" /></li> </ul> </div> </div> </body></html>
  3. Hi guys How do I get a thank you message on the same page instead of redirecting the message to a different page as on the script here - header('Location: thanks.html'); Also I want the errors to be echoed in front of the field concerned as in name, email, subject, message <?php $myemail = "hila@gmail.com"; $name = check_input($_POST['name'], "Enter your name"); //error or success message echoed here $subject = check_input($_POST['subject'], "Enter a subject");//error or success message echoed here $email = check_input($_POST['email']);//error or success message echoed here $message = check_input($_POST['message'], "Write your message");//error or success message echoed here if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } $message = " Name: $name E-mail: $email Subject: $subject Message: $message "; mail($myemail, $subject, $message); //This is where the problem is header('Location: thanks.html'); //Want to have this message on the same page exit(); function check_input($data, $problem=''){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0){ show_error($problem); } return $data; } function show_error($myError) { ?> <html><head> <title> email 2014</title> </head> <body> <strong><?php echo $myError; ?></strong><br /><br /> <form class="email" action="" method="post"> <p>Name:</p> <input type="text" name="name" /> <p>E-mail:</p> <input type="text" name="email" /> <p>Subject:</p> <input type="text" name="subject" /> <p>Message:</p> <textarea name="message"></textarea></p> <input class="send" type="submit" value="Send"> </form> <?php exit(); } ?> </body></html>
  4. I can't seem to see the problem with my success and not success form below. The form is sent successfully but keep outputting oops try again <?php if ($success) { $message = "Message sent succesfully! Thank you."; } else { $message = "Oops! Try again!"; } echo '<div id="message">'.$message.'<div id="close-button"></div></div>'; ?>
  5. Hi guys, my form works fine but I want the thank you message on the same page in red font, At the moment I am redirecting to thanks.htm and my form is on contme.php, how do i do that? script below: <?php $Email_address ='sam@yahoo.com '; session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $user_message = $_POST['message']; if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { $to = $Email_address; $subject="loverman"; $from = $Email_address; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "$name contacted you by submitting the message below:\n\n". "Name: $name\n\n". "Email: $visitor_email \n\n". "Message: \n\n ". "$user_message\n\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); //header('Location: ?success'); //echo "your enquiry was submitted successfully, thank you,"; header('Location: contme.php'); echo "Form submitted succesfully, thank you"; } else { echo "Form failed to send"; } } function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?>
  6. Thanks guys but how do I get the php echo working together with alert message? For example using both php echo $myInfo; and echo "<script> alert('Your input is correct');</script>"; maybe something like this but not so good still a newbie echo "<script type='text/javascript'>alert('$myInfo' Your input is correct);</script>"; echo "<script> alert('Your input is correct');</script>"; now where do I put my alert message as well echo "<script type='text/javascript'>alert('$myInfo');</script>";
  7. Hi guys how do I get JavaScript and php doing wonders for me. I want to chnage the following php echo $myInfo; to something like this echo "<script> alert('Your input is correct');</script>"; I am failing to make any changes here please help. I actually want javascript to output the echo $myInfo but don't know how. Thanks a lot
  8. Hi guru I meant how go I get users input to replace any badwords with symbols? My biggest problem is using input field with PHP, as a newbie I am struggling a bit so any help would be welcomed and appreciated greatly. I mean the above example for instance the badwords.text am i correct to add bad words in the file as follows: "bad1","bad2","bad3" or do I have to enter badwords this way: "bad1, bad2, bad3" I want to make sure that when user type in a bad word in the field it alerts them that thier badword will be replaced with *** Thank you once again
  9. PHPfreaks your script woks fine. However I would like to make a few modifications and apply it inside input fields, how do I do that? Lets say my input fields are as foolows: <input type='text' name='badwords' /> <!-- where do I put php on this input field as a php include file--> <?php $badwords = array('bad1', 'bad2', 'bad3', 'ass'); $text = 'This is a test. Ass. Grass. bad1.'; function filterBadwords($text, array $badwords, $replaceChar = '*') { return preg_replace_callback( array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords), function($match) use ($replaceChar) { return str_repeat($replaceChar, strlen($match[0])); }, $text ); } echo filterBadwords($text, $badwords); ?>
  10. Thanks again guys you are all awesome. I cant thank you enuogh
  11. Hi guys i am busy playing around with php if statements. The code below works fine as it is but I am having problems trying to gt it to work inside an input field please help <?php $number1 = "01234"; $number2 = "012345"; if($number1 != $number2) { //if they don't match output the following echo "info do not match. Please try again."; }else{ //if they match output the following echo "Info matched Successfully!"; exit(); } ?> Now how do I tweak my above php code to incorporate the code above for easy input into fields? $number1 = "01234"; $number2 = "012345"; Please help? <form method="post" name="change"> <p>Number 1 Info<br /> <input type="text" name="number1" /> </p> <p>Number 2 Info<br /> <input type="text" name="number2" /> </p> <p> <input name="submit" type="submit" value="Check if they match" /> </p> </form>
  12. Wow guys! 1439 views on this in two days is awesome. I am a php newbie and I am impressed. Hope you can all visit my website when I am finished making it lol.
  13. Thanks Thodanga and Mcgyver you guys really helped me on this. I am working on it
  14. I have tried the code and it keeps echoing password do not match, any help guys
×
×
  • 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.