PHP - Problem With 2 Page Based Form Validation Assignment
We have the page that the users enter the information, which shows as this in an html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Scholarship Form</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <?php ?> <body> <h1 style = "text-align:center">Scholarship Form</h1> <form name = "scholarship" action = "process_Scholarship.php" method = "post"> <p>First Name: <input type="text" name="fName" /></p> <p>Last Name: <input type="text" name="lName" /></p> <p><input type="reset" value="Clear Form" /> <input type="submit" name="Submit" value="Send Form" /> </form> </body> </html> and then the attached file, process_Scholarship.php is the file giving me trouble. We're supposed to be using advanced escaping techniques from our book, and that's when things got tricky. I know it's something silly but I just cant figure it out! Any help asap would be awesome!!!! Similar TutorialsHello, is it possible to define the next page after a form submission based on a value from the form ? Example: My form has a dropdown Value 1: Flight Value 2: Flight + Hotel now i'm trying to achieve that if value 1 is chosen after submission it goes to flight.php, if value 2 it should go to flighthotel.php or am i heading into the completely wrong direction here and over complicating things ? Thanks in advance ! I am building a hospital chart simulation for my pharmacy students and I am trying to learn PHP. Today is form validation. The following form has only one input. I have tried to piece together examples I find and from readings. The function works if the student leaves the input null, but does not catch any other errors and passes them to the next form as typed. The Patient ID is a 6 digit numeric between 100000 and 999999 and the 'patientid' will eventually be placed in a MySQL query to see if a patient with that number exists, but one question at a time. Thanks for any help. <?php session_start(); if (isset($_POST['submit'])) { $patient_id = check_input($_POST['patient_num'], "Enter Patient ID"); $_SESSION['patientid'] = $patient_id; header('Location: pt_found.php'); exit(); } ?> <!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> <title>Patient Call Form</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <form name="patientfindform" action="#" method="post"> <div> <label>Patient ID:</label> <input type="text" name="patient_num" /><br /> </div> <div> <label> </label> <input type="submit" name="submit" value="Find Patient" /><br /> </div> </form> <script> type="text/javascript"> document.patientfindform.patient_num.focus(); </script> </div> </body> </html> <?php function check_input ($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data)== 0) { die($problem); } return $data; } ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=352057.0 I dont understand why this simple validation im doing isnt working. I got rid of all my code and took it down to its simpliest form. I tried every debuging i can think of using echo's. If all fields are blank it performs as suspected and echos all fields are empty. but if i type something in one of the fields or all the fields at once it never goes onto the else statment. Is it possible to display everything a page is doing? in like true and false statements. if (isset($_POST['send_attack'])) { // checks if all fields are blank if(empty($_POST['jaffa'])) { echo "jaffa is empty <br />"; if(empty($_POST['staff_cannons'])) { echo "staff_cannons is empty <br />"; if(empty($_POST['transport_ships'])) { echo "transport_ships is empty <br />"; if(empty($_POST['bombers'])) { echo "bombers is empty <br />"; if(empty($_POST['mother_ships'])) { echo "mother_ships is empty <br />"; echo "all fields are empty"; }else{ echo "one or more fields has something in it"; }}}}}} This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 i am creating a responsive website.
I'll give you an example.
I am retriving 100 items from mysql database using php. I am only showing 20 items per page using simple pagination with arrows. I keep this format on desktop and tablets. However, I would like to show less items when I am viewing the page on a smartphone. So instead of 20 items per page, it'll show 5 items per page along with the pagination arrows.
I was wondering if this is possible with PHP or would I have to use javascript?
Hi all not been playing with php over the past year and still a noob lol i did have some code to include files based on the URL link E.G: Code: [Select] http://www.yoursite.com/index.php?page=about then i had some form of string that would access the URL so it would have checked if the url was just index.php or had ?page=somepage after it I can not seem to find any referance on the www or shift the headach i have got trying to remember the code so thought some of you wondaful people would no what i am on about and point me in the rught direction of a tutorial for the information or have the code tohand so i can referance from it thanx all Hello I have an assignment and I am really struggling with it, just wondering if anyone can give me a start or some help with it. I have uploaded the files we have been given and also the details of what we need I am really stuck and appreciate any help thanks This is the link to pull the page http://127.0.0.1/kudos/?viewkudoid=### This is the kudo-function.php page function get_kudo_info($viewkudoid){ global $wpdb; $tablename=acikudos_table_name(); $viewsql = "SELECT * FROM $tablename WHERE kudoid='$viewkudoid'"; $viewresult = $wpdb->get_results($viewsql); #$vewrow = mysql_fetch_assoc($viewresult); return $viewresult; } This is the kudo-view.php page function show_kudos($viewkudoid) { global $wpdb; $viewkudoid = $_GET['viewkudoid']; $getthekudo = get_kudo_info($viewkudoid); if ($viewkudoid == $getthekudo['kudoid']) { echo 'Congratulations, you have successfully fixed it!'; } else { echo 'Everything is displayed'; } } add_shortcode( 'kudosview', 'show_kudos' ); I know the issue is right in front of me but I can not find it. Hoping someone can help. I have a file, say bounce.php that uses php url ramdomizer, like this: <?php $urls = array("link1", "link2"); $url = $urls[array_rand($urls)]; header("Location: http://$url"); ?> What I want is to only allow that code to execute if the user is coming from another php page on the same sever/folder. So like this.... So bounce.php will check where the traffic is coming from.....if traffic is coming from page1.php (file on same server) then it will allow URL REDIRECT CODE to execute, if traffic is coming from another source, such as google.com, or from no referel, then person is sent to another site, say msn.com. What I'm trying to do is get a php file with content to load into my basic page template based on the page id, however it's not loading anything, however there are no errors coming up. I've looked everywhere I could find, and tried everything I could think of. I really could use some help on this. Below is the page template code and the code I'm trying to use to get the content to load up. page_templ.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <link rel="stylesheet" type="text/css" href="templates/content/style.css" > <!--This is the css used for IE because we need to correct some things for it.--> <!--[if IE]> <style type="text/css"> @import 'templates/content/styleIE.css'; </style> <![endif]--> </head> <body> <?php //We need to load our language files with our common text varibles require("content/langeng.php"); ?> <div id="header"> <? //Lets show the header. I use html where I can so smartphones load as little advanced code as possible require_once("header.php"); ?> </div> <div id="menu"> <?//Now our menu. require_once("menu.php"); ?> </div> <div id="mbody"> <?//Now the primary site content. //Load up our postvars.php file require_once("content/postvars.php"); ?> </div> </body> </html> postvars.php Code: [Select] <?php $id = $_POST["id"]; if ( $id == "home" ) { include 'main_c.php'; } elseif ( $id == "guides" ) { include 'guides_c.php'; } elseif ( $id == "trips" ) { include 'trips_c.php'; } ?> We are trying to get progress bar to place active class on the current page it one based on variable being set on page called "page", also the page is written into the <body class="page"> tag, once it is loading the page.
It is not working as we need can anyone, help us with script below to set progress bar to do prev and next?????
So variable is:
var page = "refundstep1";Body Class tage looks like: <body class="refunStep 1 main-layout">Progress bar is: <div class="tabContent progress-bar hidden-phone"> <div class="step active"> <h2>Step 1: Enter your Pin</h2> </div> <div class="step inactive"> <h2>Step 2: Tell us your address</h2> </div> <div class="step inactive"> <h2>Step 3: Confirm Your Details</h2> </div> </div>Code to actual set the other list next as class="inactive", list passed or compelted as class="active done", Current page as class="active" var progressClass = $('.progress-bar div.step'); $(progressClass).addClass(function(index, activeClass) { var activeClass = 'done'; var activePage = 'active'; alert(page); var currentPage = page; var pageClass = $('body').hasClass(page); console.log(pageClass); if(pageClass === true) { progressClass.addClass(activePage); progressClass.prevAll().addClass(activeClass); //To select all next elements of `.progressClass` element: progressClass.nextAll().addClass(nopageClass); } return nopageClass; }); I'm feeling a little overwhelmed/burned-out/confused... I have a page "article_index.php" that contains a summary of each article plus a link to it, e.g. Code: [Select] <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-save-you-money"> When you click on a link, it goes to "article.php" and uses a mod_rewrite to transform the "pretty URL" to regular URL that "article.php" can use to query the correct article from my database. ----- Here is what I need help with... When a user is on a given article page, I want to sto - ReturnToPath - ArticleID in the SESSION. I am drawing a blank on how to get the "ArticleID" when a user is on a give page?! Hope you guys follow me?! Debbie This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=358320.0 I have a multi-step form that offers different options of membership to users with the e-mail domain 'vip.co.uk' I finally have it working but have hit a wall with pulling the variables together to form an URL that can be submitted to the payment gateway in the final step.
The variables I need to pass are username, password, email, subscription id (a value attached to a radio button in step 2 - not yet built it).
I have a JS fiddle at http://jsfiddle.net/zsasvoo4/15/.
The final form will be in PHP and I'd prefer to use that language.
im wanting to change the sql in my query based on if a field is empty or not. if the field is empty then i dont want it to post anything, but if its not empty then it can post the content. heres what i have so far but it does post the content even if the field is empty. (!empty($password)) ? $pass_sql = "u_password = '$password'," : $pass_sql = null; $link->query("UPDATE ".TBL_PREFIX."users SET $pass_sql u_allow_user_pm = '".$_POST['allow_user_pm']."' WHERE u_username = '".$_POST['user_name']."'") or die(print_link_error()); how can i stop it from updating if the field is empty? Hi. I've been working on a shopping cart for a college course, and everything is going all right but there is something I'm confused about. What the professor wants is for the total number of items in the shopping cart to be displayed on all pages EXCEPT the actualy cart page. Right now, this feature appears on all pages, including the cart. I don't know how to make it invisible on the cart page . Here is the code from the header.html file, which is where the function to display this feature is located: Code: [Select] <?php # Script 5.2 - header.html /* * This page begins the HTML header for the site. * The header also creates the right-hand column. * This page calls session_start(). */ // Need sessions! session_start(); // Check for a $page_title value: if (!isset($page_title)) $page_title = 'WC::Widget Central'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title><?php echo $page_title; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="./includes/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="all"> <div class="box"> <div class="menu"><a href="index.php">home</a><a href="about.php">about</a><a href="products.php">products</a><a href="contact.php">contact</a></div> <div class="header"><img alt="" style="float:right; " src="./images/www.jpg" width="225" height="95" /> <h1>[<span class="style1">WC</span>] Widget Central</h1> <div class="clearfix"></div> </div> <div class="newsbar"> <h1>Browse Widget Categories</h1> <div class="p2"><ul> <?php // Get all the categories and // link them to category.php. // Define and execute the query: $q = 'SELECT category_id, category FROM categories ORDER BY category'; $r = mysqli_query($dbc, $q); // Fetch the results: while (list($fcid, $fcat) = mysqli_fetch_array($r, MYSQLI_NUM)) { // Print as a list item. echo "<li><a href=\"category.php?cid=$fcid\">$fcat</a></li>\n"; } // End of while loop. ?></ul></div> <?php if($_SERVER['PHP_SELF']!="../cart.php"){ echo "<h1>Cart Contents</h1>"; echo "<div class=\"p2\">"; $qty=0; $itemCount=$qty; foreach($_SESSION['cart'] as $qty){ for($i=0;$i<count(qty);$i++){ $itemCount+=$qty; } } echo "<a href=\"cart.php\">You have ".$itemCount." items in your cart.</a>"; echo "</div>\n"; } ?> <h1>Specials</h1> <div class="p2"> Coming soon. </div> </div> <div class="content"> If anyone can help, I'd greatly appreciate it! Thanks in advance! Below is the screenshots and script for user page level access i have used it for one of my old projects. Code is working as it was intended. But it needs to be improvised. Users table
pages table , which has all the pages and links
Access level table. which has user id from users table and page id from pages table (for which user has access)
Once the user is created, admin gives access to the user on page basis, the permissions.php page looks like this The modules
Menus inside the modules
Pages in each menu
Here is my code for permission.php <div id="demo2-html"> <ul id="demo2" class="mnav"> <li><a href="#">Sales</a> <ul> <li><a href="#">Lead</a> <ul> <table class="table table-bordered table-striped table-hover"> <?php $s1 = mysqli_query($con, "SELECT pages.page_id as pid, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.user_id FROM pages LEFT JOIN access_level ON (pages.page_id=access_level.page_id AND access_level.user_id=".$user." ) WHERE pages.code='led'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><li><td><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['pid']; ?>" <?php if($s2['pgid'] === $s2['pid']) echo 'checked="checked"';?> /> <input type="hidden" value="<?php echo $s2['pid']; ?>" name="page_id[<?php echo $s2['pgid']; ?>]"> </td></li></tr> <?php } ?> </table> </ul> </li> <li><a href="#">Customer</a> <ul> <table class="table table-bordered table-striped table-hover"> <?php $s1 = mysqli_query($con, "SELECT pages.page_id as pid, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.user_id FROM pages LEFT JOIN access_level ON (pages.page_id=access_level.page_id AND access_level.user_id=".$user." ) WHERE pages.code='cst'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><li><td><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['pid']; ?>" <?php if($s2['pgid'] === $s2['pid']) echo 'checked="checked"';?> /> <input type="hidden" value="<?php echo $s2['pid']; ?>" name="page_id[<?php echo $s2['pgid']; ?>]"> </td></li></tr> <?php } ?> </table> </ul> </li> //code goes for all the other modules </ul> </li> </ul> </div> <input type="hidden" name="user" value="<?php echo $user; ?>" /> <div class="row" align="center"> <input type="submit" name="submit" class="btn btn-success" value="Save" /> </form> // form Submission if(isset($_POST['submit'])) { $user = $_POST['user']; $sql = "DELETE FROM access_level WHERE user_id = ".$user.""; $query = mysqli_query($con, $sql) or die (mysqli_error($con)); foreach($_POST['sn'] as $sn) { $sql = "insert into access_level (page_id, user_id) values (".$sn.", ".$user.")"; $query = mysqli_query($con, $sql) or die (mysqli_error($con)); } if($query) { header("location:users.php?access=1"); } }
So against each user i am storing all the page ids here. When i edit any of the users, it deletes all the records and again insers new records. Which i feel is not a proper way to do. And in codewise also, i am redirecting the user to no_access.php (as below) page if the user do not have access. <?php ob_start(); include("connect.php"); include("admin_auth.php"); $q1 = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']); $q2 = $_SERVER['REQUEST_URI']; $var1 = "/".$q1; $qa_path=explode('/', $q2); $right_path = $qa_path[2].$var1; $parsedUrl = parse_url($q2); $curdir = dirname($_SERVER['REQUEST_URI'])."/"; $m4 = "select p.page_id, p.code, p.page, p.href, al.aid, al.page_id, al.user_id FROM pages p INNER JOIN access_level al ON p.page_id=al.page_id WHERE al.user_id=".$_SESSION['user_id'].""; $m5 = mysqli_query($con, $m4) or die (mysqli_error($con)); while($nk1 = mysqli_fetch_array($m5)) { $href1[] = ($nk1['href']); } if(in_array($right_path, $href1)) { echo "<script type='text/javascript'> document.location = ".BASE_URL."/".$right_path."</script>"; } else { echo "<script type='text/javascript'> document.location = '../no_access.php' </script>"; exit(); } ?> I need help in improve and better/effective (structural) way to do this both in database and php script. |