denno020
Members-
Posts
761 -
Joined
-
Last visited
-
Days Won
3
Everything posted by denno020
-
Are you able to use javascript?? function validate_form ( ) { valid = true; if ( document.form.field1.value == "" ) { alert ( "Please enter the field1." ); valid = false; } else if ( document.form.field2.value == "" ) { alert ( "Please enter info for the field2." ); valid = false; } else if ( document.form.field3.value == "" ) { alert ( "Please enter some info into field 3" ); valid = false; } return valid; } <form onsubmit="return validate_form ( );"> That will pop up a message that will check each field (1, 2 and 3), if there is anything in there. It will pop up a message if there is nothing inside when submit is pressed. Change field1 etc above to the id of each field you want to check. You can also do this in PHP, but it requires a page refresh, obviously. So javascript would be the quicker option, but here is how you would do it using php (pseudo code, cuz I can't find where I've already written it): //Initialize 3 variables (or however many you need - one for each field) - make them equal to = ""; //Check if form has been submitted or not //Multiple If statements checking $_POST for each field and if it's an empty string //Inside each If, you will set the 3 variables above to have a message, saying, please fill in this field (or something more specific) //If all 3 variables are filled in correctly, then you either include your form handling script, or re-direct to it. //Your form will have no action (this will just reload this same page when submit is pressed) //Echo the above 3 variables next to the fields that they correspond to (at first these will be blank, as no data has been POSTED so the above if statements shouldn't run) That's a general idea of what you could do, which will hopefully get you started on the right track Denno
-
$word = str_replace(array('(', ')'), array('<', '>'), $word); reference: http://www.w3schools.com/html/html_entities.asp Denno
-
I just tested it on my testing server and it worked fine too... It won't display on a page though, only (test) will display as the <test> is interpreted as a tag, so it isn't displayed as text. You can see it if you look at the page source though.. Denno
-
Try using double qutoes.. You might need to be escaping the symbols if you use single quotes (putting a \ directly before it). Just thinking out loud... Denno
-
as Pikachu2000, you need to wrap F in quotes, single or double, your choice. Just so long as session_start() is on every page that you want session variables, then they will work while the browser is kept open.. Denno
-
I don't think sessions time out by themselves? The only way a session will end (if there isn't a specific timer set up) is if the browser window is closed. There is no way to keep this information stored in the way you're thinking as a session, you would need to use cookies to store the session data. Denno
-
From the looks of it, this worked perfectly. Thanks for the help mate Denno
-
I've set the field type as just date. If I print out the date it will print like YYYY-MM-DD.. I've give your suggestion a go and report back . Thanks Denno
-
This should be a lot more easier than I'm finding it... at least I would have thought so. What I'm trying to do is get all results from a database where the date set is before the current date (right now). I tried by setting a variable $dateNow using date("Y-m-d"), but that didn't seem to work.. How do I put a WHERE clause saying that the date field in a row has to be before the current date? Thanks Denno
-
you can have an if statement at the top of the page, so see if anything has been posted. And then include the db.php file in that. Else, nothing. You give the form no action, so that the same page is loaded, and the if condition is run. This way you can leave all of your query information in the db.php file, and you keep focus on the form.php page, as you originally asked. reference: http://stackoverflow.com/questions/595358/how-can-i-execute-a-php-function-in-a-form-action I found the above link doing a very simple google search.... Denno
-
Display existing database where i can edit in html
denno020 replied to ohkered's topic in PHP Coding Help
Well if that page is blank, then that just means there is errors in the php that need to be rectified. So you're doing this for school work? There is no other way that I know of which would allow you to edit a database without using php, and therefore a .php file extension.. Denno -
Sorry my bad with the above post.. Looking at it further you can do this: $content = "/pages/"; if (!isset($_GET['content'])) { // Page has not been requested, show default page $content .= 'default.php'; } else { // Page has been requested, validate page exists, show page $content .= $_GET['content'].'.php'; } I've then apprended the filename to the content variable. So for the default link, $content will be equal to '/pages/default.php' Does that help? Denno
-
So you have a form set up that requests a page to view?? Denno
-
Display existing database where i can edit in html
denno020 replied to ohkered's topic in PHP Coding Help
you need to save your file as a .php. That is currently saved as a .html. Saving it this way, it will see <?php and not know what the hell is going on with it. So rename your file to be updaterecordform.php . Denno -
Display existing database where i can edit in html
denno020 replied to ohkered's topic in PHP Coding Help
<!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>adding a new data record</title> </head> <body> <?php include_once "connect_to_mysql.php"; //your script to connect to your database $sqlCommand = "SELECT student_number, first_name, last_name, email, phone FROM (your table name) WHERE student_number='$student_number' LIMIT 1"; // $query = mysql_query($sqlCommand, $myConnection) or die (mysql_error()); while ($row = mysql_fetch_array($query)) { $student_number = $row["student_number"]; $first_name = $row["first_name"]; $last_name = $row["last_name"]; $email = $row["email"]; $phone = $row["phone"]; } mysql_free_result($query); ?> <form id="form1" name="form1" method="post" action="processUpdateRecord.php"> <p> <label>Student Number: <input name="StudentNumber" type="text" id="StudentNumber" size="10" value="<?php echo $student_number ?>" /> </label> </p> <p> <label>First Name: <input name="FirstName" type="text" id="FirstName" size="20" value="<?php echo $first_name ?>" /> </label> </p> <p> <label>Last Name: <input name="LastName" type="text" id="LastName" size="20" value="<?php echo $last_name ?>" /> </label> </p> <p> <label>Email Address: <input name="EmailAddr" type="text" id="EmailAddr" size="50" value="<?php echo $email ?>" /> </label> </p> <p> <label>Telephone: <input name="PhoneNumber" type="text" id="PhoneNumber" size="20" value="<?php echo $phone ?>" /> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Update Record" /> </p> </form> </body> </html> If you haven't already done it, your processUpdateRecord.php script will need to update the row with student_number of (whatever student you're editing). Denno -
I'm hoping you've checked that it works before you've called me brilliant lol. But you're welcome Denno
-
Ohhhhhhkay then. You need the SQL too. Well that makes sense cuz what you had wouldn't have worked how you want. I would first grab the posted data and put them into variables: $category = $_GET['category']; $type = $_GET['type']; $colour = $_GET['colour']; Then, the SQL query will look something like this: SELECT * FROM products WHERE category = '$category' AND type = '$type' AND colour = '$colour' Now for the cases where there isn't one of those sections set, then I'm not sure if this SQL would run correctly. I can think of a couple of ways to do it, but it's going to be far less than efficient.. You could use php to check if the posted variable is set, how you already are doing, however you check for each possible combination. Then you have different SQL for each of those combinations. It wouldn't be too hard to set up, in fact here it is: //check if all variables were set if (isset($_GET['category']) && isset($_GET['type']) && isset($_GET['colour'])){ $sqlCommand = "SELECT * FROM products WHERE category = '$category' AND type = '$type' AND colour = '$colour'"; //check if just category and type were selected }else if(isset($_GET['category']) && isset($_GET['type'])){ $sqlCommand = "SELECT * FROM products WHERE category = '$category' AND type = '$type'"; //check if just category and colour were selected }else if(isset($_GET['category']) &&isset($_GET['colour'])){ $sqlCommand = "SELECT * FROM products WHERE category = '$category' AND colour = '$colour'"; //check if just type and colour were selected }else if(isset($_GET['type']) && isset($_GET['colour'])){ $sqlCommand = "SELECT * FROM products WHERE type = '$type' AND colour = '$colour'"; } $fetchproducts = mysql_query($sqlCommand); I also noticed that you had a ! before your isset.. This would be checking for if the variables aren't set. So I removed it to check if they are set. Obviously the words category, type and colour without the $ sign before them refer to the product tables cells. Hopefully that helps you, even if it is a long winded way of finding a solution. Denno
-
Post your code. Seriously, how do you expect to get help by just saying that you have the wrong number being entered in to the database? Denno
-
I'm not sure which script you want to change.. Do you want the SQL query to change? Right now, I can't see how this query will pull the correct item from the database at all.. Does it infact work for when all three options are set? Denno
-
Ok looking at it I think I may know what's going on. You're setting $_SESSION['extract']=$_POST['seat'], but there hasn't been any POST yet, so this won't work. Nothing will be assigned to that session variable. You need to do this assignment in formOne.php. Try changing that and see if it works. Denno
-
Does this render a page at all? Why is your topic called sessions? Do you realize that you've actually closed the <html> tag before you start echoing out the form? you need to move </html> to the bottom of your file.. Denno
-
Where are your <form> tags? Denno
-
You integrate it exactly the same. Just echo that where you would normally write it as HTML.. If you need an example, give me some HTML you have used previously with your onClick thing, and I'll write the php code for it... I really don't think it's tooo hard Denno