PHP - Moved: Action Based On Select Box Item
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=354366.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308916.0 Completely new to PHP here, so on my website I'd like a specific image to appear according to whether or not the user in my DB has a row called 'premium', with a value of 1. I've tried figuring it out on my own but I'm stuck. I watched a video of someone doing something similar so this is what I have currently, but I'm aware it's totally incorrect. //init.php file <?php if (session_status() == PHP_SESSION_NONE) {//php >5.4 session_start(); } $_SESSION['user_id'] = 1; $db = new PDO('mysql:host=127.0.0.1;dbname=loginsystem', 'root', ''); $userQuery = $db->prepare(" SELECT idUsers, uidUsers, emailUsers, pwdUsers, premium FROM users WHERE idUsers =:user_id "); $userQuery->execute(['user_id' => $_SESSION['user_id']]); $user = $userQuery->fetchObject();
//webpage in which the image will appear <?php require_once '../includes/init.php'; ?> <?php if($user-> premium): ?> <img src="../../img/premium.png" alt="Swiftify+"></a> <?php else: ?> <img src="../../img/swiftify.png" alt="Swiftify+"></a> <?php endif; ?>
Hi, I need to write some code for this but unsure where to start. Basically i have a database of say 10 rows. I need to be able to input a number and some sort of fair algorithm will choose one of the rows. The number will be from 6 to 10 numbers long, and will need to pick the same result each time based on that number. Its for a lotto game I am unsure of how to select something made up of a composite key. Allow me describe the entity... Event ShowID (pk) VenueID (pk) StartDateTime (pk) My Checkout process will have an HTML Table displaying maybe 3-4 different Events like this... Code: [Select] ========================= Register in 3 Easy Steps... Step #1: Select a Date and Attendees Event Ticket (Update) Choose Name Cost Attendees Total One Flower Show $20 ___ $0 <<Buy a Ticket>> Mankato, MN Sept 24, 2011 Flower Show $20 _3_ $60 <<Buy a Ticket>> Willmar, MN Oct 1, 2011 Banjo Jamboree $50 ___ $0 <<Buy a Ticket>> Brainerd, MN Oct 8, 2011 ========================= When a User clicks on a particular "Buy a Ticket" button, how do I capture the 3 Composite Key Values I need so I can insert them into my Order table? Maybe a better question to ask, is HOW/WHERE would I store the 3 Composite Key Values so that when a User clicks on a given "Buy a Ticket" button, that I have the values I need to build my Order record?? Normally with just one value (e.g. Drop-Down List), when someone selects a value, there is a corresponding code that you'd use. For example "Extra Large" in a Drop-Down List equals "3". Hope I'm making sense?! Thanks, Debbie Hi, I have an array of items and I randomly want to remove one from the array. What's the easiest way to go about this?
In the same $-POST , i wanted to perform update and delete. With the updated and deleted database, I need to select the updated data from the database. However, it tells me: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in... .I am new to sql in php, is it true that i cannot perform sql in this way? Or is there any suggestion to perform select straight after deleting and updating? CANCEL BOOK RESERVATION if(isset($_POST['cancelres'])) { $query = "DELETE FROM reserved_books WHERE id='$resid';"; //delete reservation $query .="UPDATE reserved_books SET queue = queue - 1 WHERE bookid = '$bookid' AND queue > '$bookqueue';";//update queue number where reservation that queue behind/after/ the current reservation $query_run = mysqli_multi_query($connection, $query); if($query_run) { $_SESSION['success'] = "Reservation Cancelled"; } else { $_SESSION['status'] = " Reservation Not Cancelled"; } $query= "SELECT title FROM books WHERE id = '$bookid';"; //get book title from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { foreach ($query_run as $row) { $title = $row['title']; } } $bookres = "SELECT * FROM reserved_books WHERE bookid = '$bookid' AND queue = 1"; $bookres_run = mysqli_query($connection,$bookres); foreach($bookres_run as $row) { $res_username = $row['username']; $res_id = $row['id']; } $query= "SELECT option_value FROM settings WHERE option_name = 'email_temp_rescollect'"; //get email template from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { $row = mysqli_fetch_array($query_run); $rescollect_template = $row[0]; }}
In my php site i have a select button.On selecting an item from the select box ,the corresponding picture should be displayed in the <img>,from the mysql database. This is not happening with the following code <form name='abc' method='post'> <select name="std_name" onChange="this.form.submit();"> <option value="...Select...">...Select...</option> <option value="Adam">Adam </option> <option value="Amanda">Amanda</option> <option value="Angel">Angel </option> <option value="Brewier">Brewier</option> <option value="Butle">Butler </option> <option value="Carrie">Carrie </option> </select><br /> <?php if(isset($_POST['submit'])) { $aname1=$_POST['std_name']; $sql1="select * from std where name='$aname1'"; $result=mysql_query($sql1); while($n=mysql_fetch_row($result)) { echo $n[2]; echo "<img src='$n[2]' width='118' height='133' name='std/>";} } ?> <img src="Adam.jpg" width="118" height="133" name="std"/><br /> </form> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=350052.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359130.0 Hey guys, I am wanting to select a dropdown value based on the value of 'level' in the row of the user select by a $_GET. It will house the ranks of the user. Here is my script. RANK <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $row = mysql_num_rows($result); ?> <form id="main_form" name="main_form" method="post" action=""> <select name="rank"> <option value="0" <?php if($row['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($row['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($row['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($row['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($row['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($row['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($row['level']=="6") { echo "selected"; }?>>Owner</option> </select> <input type="submit" id="main_submit" name="main_submit" value="submit" /> </form> It is not selecting for some reason at all. Can someone tell me what I am doing wrong? Hi all I am trying to write a piece of code that selects different products from the database based on the URL parameter. There are 3 fields; category, type and colour. My URL will look like this if there is all three selected: product.php?category=31&type=74&colour=3 Basically, if what ever is set in the url I need this to be selected from the database. Here's my code: if (!isset($_GET['category']) && !isset($_GET['type']) && !isset($_GET['colour'])){ $fetchproducts = mysql_query(" SELECT * FROM `products` "); $lightboxcount = 0; while($returnedProduct = mysql_fetch_array($fetchproducts)) { $lightboxcount ++; include('product-cell.php'); } } Although if there is no colour or the colour is blank like this: product.php?category=31&type=74&colour= I want it to select the items from the database just where the category and type are set. Please help! Many thanks Hi, I have db field with date. I want to make select statement with where clause when part of the date (month) is true. Example, i have records from 2020-2-1 until 2020-4-3, i want to select records for march only 2020-3-1 to 2020-3-31. how to do that? Here is my code:
//Grab all the monster in Monster zone 1 $q = $db->query('SELECT * from rpg_monsters where monster_zone = 1'); while ($monsterdata = $db->fetch_assoc($q)) { $monster_chance[] = $monsterdata; }and my var_dump: array (size=4) 0 => array (size=8) 'monster_id' => string '1' (length=1) 'monster_name' => string 'Merman' (length=6) 'monster_level' => string '1' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '10' (length=2) 'monster_dmg' => string '1' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 1 => array (size=8) 'monster_id' => string '2' (length=1) 'monster_name' => string 'Chris Wilson' (length=12) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Unique' (length=6) 'monster_hp' => string '25' (length=2) 'monster_dmg' => string '3' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.04' (length=4) 2 => array (size=8) 'monster_id' => string '3' (length=1) 'monster_name' => string 'Seaman Warrior' (length=14) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Magic' (length=5) 'monster_hp' => string '20' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 3 => array (size=8) 'monster_id' => string '4' (length=1) 'monster_name' => string 'Goblin Attacker' (length=15) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '15' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4)As you can see, the Unique Monster (Chris Wilson) is the lowest chance at only 4%. And all the other mobs at at 10% chance to spawn. Here is my code for probability: $rate = (double) '0.03'; // 3% $max = 1 / $rate; // 100 if (mt_rand(0, $max) === 0) { // chance < $rate echo "Only 3% probability, holy cow!"; }My problem is, I'm a bit lost as how to get my probability code inside a loop and having the dynamic $rate correspond to my "chance" row. Although, I could just use ORDER BY rand() in mysql, it wouldn't let me use any probability and chances... hmmm Edited by Monkuar, 12 October 2014 - 11:12 AM. Hi, I am trying to create a drop down menu that will select a value that is stored in the database - right now the code creats a dropdown (with nothing selected) - hope someone can help. in the database, the values are stored as --null- Option1 Option2 Option3 my code is Code: [Select] $instruction = $_GET['instruction']; <?php <select id="instruction" name="instruction"> <option value="" <?php if (!empty($instruction) && $instruction == '' ) echo 'selected = "selected"'; ?>></option> <option value="Option1" <?php if (!empty($instruction) && $instruction == 'Option1') echo 'selected = "selected"'; ?>>Option1</option> <option value="Option2" <?php if (!empty($instruction) && $instruction == 'Option2') echo 'selected = "selected"'; ?>>Option2</option> <option value="Option3" <?php if (!empty($instruction) && $instruction == 'Option3') echo 'selected = "selected"'; ?>>Option3</option> </select> <? Not sure why this isnt working. Code: [Select] <?php session_start(); ?> <!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> <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script> <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <LINK REL=StyleSheet HREF="inc/dyn_style.css" TYPE="text/css" MEDIA=screen /> <?php ?> <?php include('logic.inc'); mysqlConnect(); ?> <script type="text/javascript" src="bbeditor/ed.js"></script> <link rel="stylesheet" type="text/css" href="dyn_style.css" /> <title> Social </title> <script type="text/javascript"> function changeTitle(title) { document.title = title; } </script> </head> <body> <?php $inc = 'new_story.php'; $view = 'Newest '; $by = 'added'; $where = " "; $where2 = " "; $order = "ASC"; $gen = "All"; $rat = 'All'; $blerg = ""; $sort = 'newest'; //---------------------------------------------------------------------- if(isset($_GET['sub'])) { $sort = $_GET['sort']; switch($sort) { case "Most Popular"; $by = 'views'; $view = 'Most Popular '; $order = 'DESC'; break; case "Most Reviewed"; $view= 'Most Reviewed '; $by = 'reviews'; $order = 'DESC'; break; case "Newest"; $by = 'added'; $view = 'Newest'; $order = 'ASC'; break; } $genre = mysql_real_escape_string($_GET['cat']); $rating = mysql_real_escape_string($_GET['rat']); if($gen == 'All') { $where = " "; $blerg = ""; } else { $where = "WHERE cat='$gen'"; } if ($rat == "All") { $where2 = ' '; $blerg = 'AND'; } else { $where2 = $blerg ." rating = '$rat' "; } } //---------------------------------------------------------------------- ?> <?php serch(); ?> <form action="story.php" method="get"> <label id='inline'> Order By: </label> <select name='sort'> <option selected='yes' label='Currently Selected' > <?php echo $view; ?> </option> <option> Newest </option> <option> Most Popular</option> <option> Most Reviewed </option> </select> <input type='hidden' value='spec_view' name='p' /> <label id='inline'> Genre/Catagory: </label> <select name='gen'> <option selected='yes' label = 'Selected Genre - <?php echo $gen; ?>'> <?php echo $gen; ?> </option> <option> All </option> <option> Fantasy </option> <option> Adventure </option> <option> Science Fiction</option> <option> Drama</option> <option> Fable </option> <option> Horror</option> <option> Humor</option> <option> Realistic Fiction </option> <option> Tall Tale</option> <option> Mystery </option> <option> Mythology </option> <option> Poetry </option> <option> Shorty Story </option> <option> Romance </option> </select> <label id='inline'> Rating: </label> <select name='rat'> <option selected='yes' label = "Selected Genre - <?php echo $rat; ?>"> <?php echo $gen; ?> </option> <option> All </option> <option> C </option> <option> C13 </option> <option> YA </option> <option> A </option> </select> <input type='submit' value='Go!' name = 'go' /> </form> <?php $query = " SELECT * FROM story_info ORDER BY $by $order $where $where2 "; echo $query; $select = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_assoc($select)) { $viewsdb = $rows['views']; $titledb = $rows['title']; $userdb = $rows['user']; $catdb = $rows['cat']; $ratdb = $rows['rating']; $id_db = $rows['story_id']; $sumdb = shorten($rows['sum']); echo "<h3><a href='?p=page&id=$id_db'> $titledb </a> </h3>"; echo "<div id='fun_info'>"; echo "$sumdb <br />"; echo "By <a href='?p=profile&user=$userdb'> $userdb </a> <br /> "; echo "$viewsdb Views | Rated: $ratdb | Catagory: <a href='?p=cat_view&gen=$catdb'> $catdb </a> </div>"; } ?> </div> </body> </html> I have a script that seems to work well to insert a bookmark into a users database when he/she is logged into the system but I am having a hard time figuring out how I would go about making a work-a-round for having an item selected before being logged in, and inserted after they have logged in or registered. For example, I would like a user to be able to select an Item to add to bookmark whether that user is logged in/registered or not and if they are not, they would be greeted with a login/registration form and after successful login the add bookmark script would be initiated on the item previously selected. What I've got this far: Simple form to add bookmark: <form name="bm_table" action="add_bms.php" method="post"> <input type="text" name="new_url" value="http://" /> <input type="submit" value="Add Bookmark"/> </form> Then I have the add bookmark script: BEGIN php $new_url = $_POST['new_url']; try { check_valid_user(); //cannot get past this part since it ends the script....code below if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } // check URL format if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check URL is valid if (!(@fopen($new_url, 'r'))) { throw new Exception('Not a valid URL.'); } // try to add bm add_bm($new_url); echo 'Bookmark added.'; // get the bookmarks this user has saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } } catch (Exception $e) { echo $e->getMessage(); } END php Checking valid user - the portion I cannot get past in the above script: function check_valid_user() { // see if somebody is logged in and notify them if not if (isset($_SESSION['valid_user'])) { echo "Logged in as ".$_SESSION['valid_user'].".<br />"; } else { // they are not logged in do_html_heading('Problem:'); echo 'You are not logged in.<br />'; do_html_url('login.php', 'Login'); do_html_footer(); exit; } } How would I go about modifying the script so that a user could fill in the form (later it would be a link...obviously they probably wouldn't be filling in a form that is log-in specific - but same concept I think) Thanks in advance for the help! tec4 Hi there, I think this is a big question but I'd appretiate any help you can provide!! I have a list of items and subitems in a table that looks like this: id parent_id title 1 0 House Chores 2 1 Take Out Trash 3 1 Clean Room 4 0 Grocery List 5 4 Eggs 6 4 Produce 7 6 Lettuce 8 6 Tomato 9 4 Milk I want to display it like this: (+) House Chores: > Take Out Trash > Clean Room (+) Grocery List: > Eggs (+) Produce > Letutce > Tomato > Milk So basically each entry in the table has an unique id and also a parent id if it's nested inside another item. I "sort of" got it figured out in one way, but it doesnt really allow for nested subgroups. I'd like to know how would y'all PHP freaks to this Also taking suggestions for the javascript code to expand/collapse the tree !! Thank you! Hello, I had 8 select boxes(dropdowns) in a form. Its like a search kind of implementation in the website. I don't know what the user selects, he may choose different select boxes, any number of select boxes. So, based upon the user selection, I need to generate the data. The data fields to be generated would be almost same. So, How would I know what the user selection is and how many select boxes has been selected and how could I generate different data based upon selected boxes. I had to make a small note abt this, that the data generation fields may change for some of the user select combinations, but most of the result fields would be same. so, can you please help me out, how to do, how to make different combination data generations, because, i had 8 fields, i had to make 8! combinations, that would result in a big code. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=359538.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358615.0 |