Jump to content

Ugluth

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Ugluth's Achievements

Member

Member (2/5)

0

Reputation

  1. Well yes the problem lies in the next button as well for sure, the only way i can think i can fix this is by adding the values of the 2 dropdown boxes on each navigation link. But i thought i'd post this here, because this isn't something new that has never been seen before, many sites allow you to do these 2 things together. The navigation for the pages at the moment is handled by the pagination script as i said. I will try to make it manually, or change the code a bit on the script to try to embed the values from the 2 dropdowns on each navigation link. If someone has a better solution, please guide me the correct way
  2. Hello I want to create a page where the movies of my database will be available for view. I have added a drop down box where the user can select one parameter to categorize the results, like release date, category etc.. I used to use a pagination script which really worked perfect, but I'm having some problems right now. The dropdown boxes keep the values they have on each postback of that form. The problem is that if a page has more results, and you press the next page link, you get the results from a "new" query, instead of the remaining results of that query. That probably is hard to understand, so i will paste some of my code. The pagination script i am using is http://phpsense.com/php/php-pagination-script.html. Ok and here's the code i have written. <form action="view_movies.php" method="post"> <label for="picker">Please select how to display movies.</label><br /> //This is the list where the user chooses on what to categorize the results. <select name="picker" id="picker"> <option <?php if(isset($picker) && $picker === "category") { echo "selected"; } ?> value="category">Category</option> <option <?php if(isset($picker) && $picker === "release") { echo "selected"; } ?> value="release">Release Date</option> <option <?php if(isset($picker) && $picker === "mov_med") { echo "selected"; } ?> value="mov_med">Movie Medium</option> <option <?php if(isset($picker) && $picker === "rent_time") { echo "selected"; } ?> value="rent_time">Rental Period</option> <option <?php if(isset($picker) && $picker === "price") { echo "selected"; } ?> value="price">Price</option> </select><br /> <?php if (isset($picker)) { //This is the second drop down box to show once the user has made a choise. switch ($picker) { case "category": ?> <select name="category" id="category"> <option value="">Select a category</option> <?php while($row_cat = mysql_fetch_row($result_category)) { ?> <option <?php if ($parameter == $row_cat[0]) { echo "selected"; } ?> value="<?php echo $row_cat[0]; ?>"><?php echo $row_cat[1]; ?></option> <?php } ?> </select> <?php break; case "release": ?> <select name="release" id="release"> <option value="">Select a year</option> <?php while($row_release = mysql_fetch_row($result_release_date)) { ?> <option <?php if ($parameter == $row_release[0]) { echo "selected"; } ?> value="<?php echo $row_release[0]; ?>"><?php echo $row_release[0]; ?></option> <?php } ?> </select><?php break; case "mov_med": ?> <select name="medium" id="medium"> <option value="">Select a medium</option> <?php while($row_med = mysql_fetch_row($result_mov_med)) { ?> <option <?php if ($parameter == $row_med[0]) { echo "selected"; } ?> value="<?php echo $row_med[0]; ?>"><?php echo $row_med[1]; ?></option> <?php } ?> </select><?php break; case "rent_time": ?> <select name="period" id="period"> <option value="">Select a period</option> <?php while($row_per = mysql_fetch_row($result_period)) { ?> <option <?php if ($parameter == $row_per[0]) { echo "selected"; } ?> value="<?php echo $row_per[0]; ?>"><?php echo $row_per[1]; ?></option> <?php } ?> </select><?php break; case "price": ?> <select name="price" id="price"> <option value="">Select a price</option> <?php while($row_per = mysql_fetch_row($result_period)) { ?> <option <?php if ($parameter == $row_per[0]) { echo "selected"; } ?> value="<?php echo $row_per[0]; ?>"><?php echo $row_per[2]; ?></option> <?php } ?> </select><?php break; } } ?> <input type="submit" value="go"> </form> After having the selection of the user, i modify my query with some elseif's according to what the user has picked. That all works fine so i wont make this post even longer. I have also read the pagination tutorial on the site, which was really helpful, but I'm not really sure how to go about what i want to do. First of all, is this way I'm doing things correct? Or is there another way that is a lot simpler? And my second question is if i should embed what the user has chosen on these menus on the link for the pagination. Please advice me what to do, and sorry for the long post.
  3. Thank you very much works fine that way for most of the fields, some fields though have are foreign key and i get a constraint violation when i try to enter the name only. The foreign keys are like this in the form: <td><label for="category">Category</label></td> <td><select name="category" id="category"> <option value="">Select a category</option> <?php while($row_cat = mysql_fetch_row($result_category)) { ?> <option value="<?php echo $row_cat[0]; ?>"><?php echo $row_cat[1]; ?></option> <?php } ?> </select> </td> I suppose the problem is with this line <option value="">Select a category</option> What should i put as a value on that so it doesn't require these? Thank you for your time.
  4. Hello i have a table called movies on my database and i have a form where the user can input the data, press submit and add it to the database. My problem is that i only want the movie name to be a required field (the user doesn't set the id field, its auto incremented, so i leave that to the database). I'm using this query to insert the new movie to the database: $query = "INSERT INTO movies (movie_name, movie_category, release_date, movie_medium, rental_time, total_stock, current_stock, rented) VALUES ('$name', $category, '$release', $medium, $period, $total, $current, $rented)"; My problem is that this way all of the fields are required, else it generates an error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '', , , , , )' at line 2 Which i understand why, but what can i do so only the movie name is required? All of the fields allow nulls so that is not the problem. I could check which variables have values and use a query with only the values that have a meaningfull value, but I don't think that is the best way to do it. That would have me create many different queries for each case, or use a gigantic query with some if's in it? (don't know if that would work, just an idea) Could someone please direct me to the correct way of doing this? Thank you in advance
  5. Terribly sorry for the post but i just figured it out right after posting and checking the tutorial again, sorry for the trouble. preg_match("/^[A-Za-z]+$/", $_POST['name']) Fixed my problem. If there's something wrong with using this please do tell me.
  6. Hello I just read the tutorial on the site about regular expresions which was really nice. After reading i tried putting some of that knowledge in practice with no results though. I only want the user to enter letters and not digits. So I used if (isset($_POST['name']) && preg_match("/^[A-Za-z$]/", $_POST['name'])) { $name = mysql_real_escape_string($_POST['name']); echo "ok"; } else { echo "Category name must be a word!<br />"; When i enter something starting with a letter it passes the check. If something starts with a number it doesnt. The problem is that if i enter asdf123 it passes the test, while it shouldn't. I think it has something to do with the $ but i'm not really sure whats wrong with it. Could someone please tell me what I'm doing wrong? I'm sure its something pretty silly but i can't figure it out.
  7. Thank you very much for your replies, you cleared things up for me
  8. Hello I want to check that a variable the user enters is not empty and that it is a string (no numbers). Here is what i have written: <?php include('css/layout.css.php'); include('css/menu.css'); if (isset($_POST['submit'])) { include('includes/dbconn.php'); if (is_string($_POST['name']) && strlen($_POST['name']) > 0) { $name = mysql_real_escape_string($_POST['name']); } else { echo "Category name must be a word!<br />"; } if (isset($name)) { echo $name; } else { echo "something"; } } ?> and this is the form i'm getting the data from: <form action="category_add.php" method="post"> <table class="table-view"> <tr> <td><label for="name">Category Name</label></td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td><input type="submit" value="Save changes" name="submit" id="submit"></td> </tr> </table> </form> If i enter nothing it works fine, if i enter a string it also works fine, the problem is when i enter 123 in the textbox, i dont get the "Category name must be a word!" as i expected i would. Could someone help me with this one please? Thanks in advance.
  9. Hello, i'm trying to upload a file through a page, on a local wamp server. Here's the code i'm using: <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Upload" /> </form> This is the form i'm using to pass my file <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br />"; if (move_uploaded_file($_FILES["file"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']. "/template_example/slideshow/images/" . $_FILES["file"]["name"])) { echo "Stored in: " . $_SERVER['DOCUMENT_ROOT'] . "localhost/template_example/slideshow/images/" . $_FILES["file"]["name"]; } } ?> The problem comes up if i try to upload an image file of size 1,07 MB. upload_max_filesize on my php.ini is at 2M. I also tried changing it to 2000M just to see if thats the problem. The error code i'm getting is 2 which means: Value: "2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form." from what i got on the internet. My operating system is windows XP SP2 and i have wamp server installed. Please help!
  10. Hello again, on a different page i'm having trouble with the where clause. I'll post the code first and explain after <?php $result_sql=mysql_query($sql="SELECT DISTINCT m.movie_ID, m.name, c.category_name, mm.medium_name, rp.period, rp.price, m.total_stock, m.current_stock FROM movie_actor AS ma INNER JOIN movies AS m ON ma.movie_ID = m.movie_ID INNER JOIN categories AS c ON m.category = c.category_ID INNER JOIN movie_medium AS mm ON m.medium = mm.medium_ID INNER JOIN rental_period AS rp ON m.rental_time = rp.medium_ID") or die("Query failed: " . mysql_error()); if (isset($_POST['actor'])) { $sql .= "WHERE ma.actor_ID = " . $actor; } while ($row = mysql_fetch_array($result_sql, MYSQL_NUM)) { ?> <tr> <td><?php echo $row[1]; ?></td> <td><?php echo $row[2]; ?></td> <td> <?php $result_actor = mysql_query("SELECT a.name, a.surname FROM movie_actor AS ma INNER JOIN actors AS a ON ma.actor_ID = a.actor_ID WHERE ma.movie_ID = $row[0]") or die("Query failed: " . mysql_error()); while ($row_actor = mysql_fetch_array($result_actor, MYSQL_NUM)) { ?> <?php echo $row_actor[0] . " " . $row_actor[1]; ?><br /> <?php } ?> </td> <td> <?php $result_director = mysql_query("SELECT d.name, d.surname FROM movie_director AS md INNER JOIN directors AS d ON md.director_ID = d.director_ID WHERE md.movie_ID = $row[0]") or die("Query failed: " . mysql_error()); while ($row_director = mysql_fetch_array($result_director, MYSQL_NUM)) { ?> <?php echo $row_director[0] . " " . $row_director[1]; ?><br /> <?php } ?> </td> <td><?php echo $row[3]; ?></td> <td><?php echo $row[4]; ?></td> <td><?php echo $row[5]; ?></td> <td><?php if(($row[6] - $row[7]) > 0) { echo "available"; } else { echo "all copies are rented"; } ?></td> </tr> <?php } I don't get any errors on this one, but its not fetching the results i want it to. I also have a drop down list that displays all actors and when it postback's it brings the id of the actor (checked it) and there are only supposed to be results with movies that the certain actor is in them. I have also tried selecting from movies table instead of movie actor, but it had the same effect, it didn't limit the results to the selected actor. The movies table has the movie_ID PK, the movie_actor has movie_ID as FK and actor_ID as FK and actors has actor_ID as PK. Please help me again, thanks in advance!
  11. I can't believe i spent so much time trying to get whats wrong and it was that simple after all, worked great, thank you very much!
  12. Hello there, i have a database for a video store where there's a table for movies, a movie_actor table and an actors table. The movie_actor table holds the id of a movie and the id of an actor. What i want to do is display the actors for each movie (can be more than 1). Here is what i have done up to now. $sql="SELECT m.movie_ID, m.name, c.category_name, mm.medium_name, rp.period, rp.price, m.total_stock, m.current_stock FROM movies AS m INNER JOIN categories AS c ON m.category = c.category_ID INNER JOIN movie_medium AS mm ON m.medium = mm.medium_ID INNER JOIN rental_period AS rp ON m.rental_time = rp.medium_ID"; //This is the main query, no probs with this one $pager = new PS_Pagination($link, $sql, 10, 3); //pager is a script for pagination i'm using, not relevant to the problem i think. $rs = $pager->paginate(); while ($row = mysql_fetch_array($rs, MYSQL_NUM)) { ?> <tr> <td><?php echo $row[1]; ?></td> <td><?php echo $row[2]; ?></td> <td> <?php $result_actor = mysql_query("SELECT a.name, a.surname FROM movie_actor AS ma WHERE ma.movie_ID = $row[0] INNER JOIN actors AS a ON ma.actor_ID = a.actor_ID") or die("Query failed: " . mysql_error()); while ($row_actor = mysql_fetch_array($result_actor, MYSQL_NUM)) { ?> <?php echo $row_actor[0] . " " . $row_actor[1]; ?><br /> <?php } ?> </td> <td><?php echo $row[3]; ?></td> <td><?php echo $row[4]; ?></td> <td><?php echo $row[5]; ?></td> <td><?php if(($row[6] - $row[7]) > 0) { echo "available"; } else { echo "all copies are rented"; } ?></td> </tr> <?php } ?> The error i'm getting is this one: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN actors AS a ON ma.actor_ID = a.actor_ID' at line 1 I'm pretty sure the fields are correct its not a matter of a typo. I'm using wamp server, mysql version 5.1.36 if someone could tell me whats wrong with my second query i would really be grateful. P.S. If i remove the inner join part and just leave it with the where, the query works properly it returns the id's of the actors that are associated with that movie, so my problem is displaying the actor name and surname. Thanks in advance and if u need any more info please just ask!
  13. Found the problem with phpmyadmin got it to work after all. I've tried what you suggested, even though now my drop down doesn't even get data. Here's the code i used: <?php include 'includes/dbconn.php'; if (isset($_POST['actorID']) && isset($_POST['actorName']) && isset($_POST['nation'])) { if ($_POST['actorID'] != "" && $_POST['actorName'] != "") { $sql= sprintf("INSERT INTO actors (Actor_ID, Actor_Name, Actor_Nation) VALUES ('%s', '%s', '%s')", mysql_real_escape_string($_POST['actorID']), mysql_real_escape_string($_POST['actorName']), mysql_real_escape_string($_POST['nation'])); dbconnect(); if (!mysql_query($sql, $link)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; mysql_close($link); } } else { echo "All fields need to be completed to add the record."; } } ?> <form action="actor_add.php" method="post"> <table> <tr> <td> Actor ID: </td> <td> <input type="text" name="actorID"> </td> </tr> <tr> <td> Actor Name: </td> <td> <input type="text" name="actorName"> </td> </tr> <tr> <td> Actor Nationality ID: </td> <td> <select name="nation"> <?php dbconnect(); $result_nation = mysql_query("SELECT * FROM nationalities"); while($row = mysql_fetch_array($result_nation)) { ?> <option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option> <?php } mysql_close($link); ?> </select> </td> </tr> </table> <?php mysql_free_result($result_nation); ?> <input type="submit" value="Submit" /> </form> I also made a function for connection with the database, gonna paste it here in case something is wrong with it. <?php function dbconnect() { // Connect to the database $link = mysql_connect("localhost", "User-name", "Password") or die ("Failed to connect to the database"); $db_select = mysql_select_db("videoclub", $db_connect) or die ("Failed to select the database"); } ?> What is wrong with my code and i don't get any data on my drop down?
  14. First of all thank you for your reply, and I'm rather stupid for posting the db connect info and thank you for pointing out. Actually another problem came up to me rather irrelevant with the drop down box. I just tried to open phpmyadmin and for some reason it tells me: #1045 - Access denied for user 'root'@'localhost' (using password: NO) I can open the console it asks for password and i supply it and its fine. But how can i make phpmyadmin get that password too so i don't get that error? About the dropdown box i see my mistake now, i was recently studying some vb.net and got a bit confused with the datasets, for some reason thought php worked that way too, but thank you very much. If you could help me with getting phpmyadmin to work (and change the password as well) i would be really grateful. Thanks in advance!
  15. Hello there, i have a pretty simple problem, but i cant seem to get over it hence this post. I have a very simple form with 2 text boxes and a dropdown box. The user is supposed to insert an actor to the database using that form, but the thing is that i can't get the value from my dropdown box for some reason. Anyway here's the form. <div id="content"> <?php if (isset($_POST["actorID"]) && isset($_POST["actorName"]) && isset($_POST["nation"])) { if ($_POST["actorID"] != "" && $_POST["actorName"] != "") { $link = mysql_connect('localhost', 'Ugluth', 'dracul'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $sql="INSERT INTO actors (Actor_ID, Actor_Name, Actor_Nation) VALUES ('$_POST[actorID]','$_POST[actorName]','$_POST[nation]')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; mysql_close($link); } } else { echo "All fields need to be completed to add the record."; } } $link = mysql_connect('localhost', 'turu', 'tururu'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $result_nation = mysql_query("SELECT * FROM nationalities"); $row = mysql_fetch_array($result_nation); mysql_close($link); ?> <form action="actor_add.php" method="post"> <table> <tr> <td> Actor ID: </td> <td> <input type="text" name="actorID"> </td> </tr> <tr> <td> Actor Name: </td> <td> <input type="text" name="actorName"> </td> </tr> <tr> <td> Actor Nationality ID: <?php ?> </td> <td> <select name="nation"> <?php while($row = mysql_fetch_array($result_nation)) { ?> <option value="<?php $row[0]; ?>"><?php echo $row[1]; ?></option> <?php } ?> </select> </td> </tr> </table> <?php mysql_free_result($result_nation); ?> <input type="submit" value="Submit" /> </form> </div> <!-- end #content --> I'm trying to enter the value to my query using '$_POST[nation]' on the $sql string i use for query. I have also tried just displaying it on the screen to see what value it holds, but it just wont show anything. Also i don't really need this answered for this particular problem, but in general its good to know, how can i select the value from the text of each option on the drop down box? The $row[0] holds the id while $row[1] holds the name. Thank you in advance and if u need any more information just let me know
×
×
  • 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.