PHP - Php Multiselect Process From Different Tables
I have this 3 tables
users (id_user)
music_styles (id_style, style) ex. (1) - (Blues)
user_styles (id_user, id_style)
I'm trying to create a form in which the user ($user = $_SESSION['id_user']) chooses through a multiple select the styles of preference to store them in the database using mysqli statements.
If the styles prefered are selected they should be displayed in the select input later, how can i accomplish this?
Thanks.
Similar TutorialsHi guys, Im using a poker league script to keep track of the home games me and my 5 friends play every month. This script works fine, but its kinda tendeous because when I make a round I have to manually add every player individualy. I edited the html so that I get a multiselect box where all the names are listed and can be multiselected, but the code only saves the first name and thus it does not work as intended. anyone got any idea how to change this so I can select multiple names and they are added all at once? here is how the page looks: this is the add-players-to-tournament.php: Code: [Select] <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournament League Solution</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 bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { $result = mysql_query("SELECT playerid FROM ".$score_table." WHERE playerid = " . $sql->quote ( $cgi->getValue ( "playerid" ) ) . " AND tournamentid = " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $cgi->getValue ( "playerid" ) ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); ?> <br> <p align="center" class="red">The player <strong><?php echo $_POST['playerid']; ?></strong> has been assigned to the poker tournament.</p> <?php } } ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid" multiple size="8"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?> Hi guys, I have a form with a multiselect option as below Code: [Select] <select multiple="multiple" id="smoker" name="smoker[]"> <option value="" selected="selected">Please select</option> <option value="No" >No</option> <option value="Occasionally" >Occasionally</option> <option value="Often" >Often</option> <option value="Open to All" >Open to All</option> </select> and need to pass this info into mysql insert, but before that I need them to be seperated by coma, i have the code below but keep getting errors Code: [Select] if ($_SERVER['REQUEST_METHOD'] == 'POST') { $smoker=stripslashes($_POST['smoker']); $smoker_db=implode(", ",$smoker); } this is the error i get Quote Notice: Array to string conversion in ...... Could you please help me with this? Many thanks in advance I know it's maybe EASY but how can I insert datas into database from multi-select html form? Here is the code: Code: [Select] <body><form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> <?php $test=$_POST['test']; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } ?></body>Any ideas how to modify the above code so I can INSERT INTO values from multi-select box? Hi forum, I would like to create a webpage (no DB) where I internally can reboot my phones (with https+login ofcause...). This is my reboot.php from http://code.google.com/p/php-sip/: --- <?php require_once('PhpSIP.class.php'); try { $api = new PhpSIP('172.30.30.1'); // IP we will bind to $api->setUsername('10000'); // authentication username $api->setPassword('secret'); // authentication password // $api->setProxy('some_ip_here'); $api->addHeader('Event: resync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:10000@sip.domain.com'); $api->setUri('sip:10000@sip.domain.com'); $res = $api->send(); echo "res1: $res\n"; } catch (Exception $e) { echo $e->getMessage()."\n"; } ?> --- What I would like to achieve is to have a index.php with a "SITE" dropdown and a multiselect "PHONE" dropdown - where only marked phone(s) for a selected site can be chosen (most likely some java stuff...?): I need to be able to run this (reboot.php) from linux shell (like: php reboot.php <IP>) so I can schedule remote phonereboots when software has been updated on my provisioning server. It would be awesome if I was also able to choose "SITE"+"ALL" and reboot all phones in a site from both webpage and shell... Thanks in advance :-) ! ~Maymann Hi guys, I want my application to run a triggered process based on time to execute some tasks, what is the best approach? Thanks Hey guys, I've hit a huge obstacle in my coding process of a script I am writing. It is basically an uploading interface script and it works like this. I have files on my server and I want a user to click a button which fires a php script which in turn fires a bash script which IN TURN fires the uploading program (plowshare). So to make it simple: user logs in, sees upload button. Clicks it, file starts uploading. I then want the user to see "upload initiated" and that's it. The problem is that with what I have now, the script just won't finish loading until the file has been uploaded and as a matter of fact I don't even think it is uploading anything :S Here are the scripts: PHP interface to call the bash script: Code: [Select] <?php error_reporting(E_ALL); function run_in_background($Command, $Priority = 0) { if ($Priority) $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!"); else $PID = shell_exec("nohup $Command 2> /dev/null & echo $!"); return($PID); } function is_process_running($PID) { exec("ps $PID", $ProcessState); return(count($ProcessState) >= 2); } $file = $_GET['file']; // Location of file relative to the index $where = $_GET['where']; // Absolute index location $absolute = '/var/www/vhosts/animekyun.com/httpdocs/icarus/'; $where = $absolute . $where; //$outfile ='log'; echo $where . $file . '<br>'; echo "<h2>The upload has been initiated!</h2>"; $ps = run_in_background("/bin/sh uploadparser.sh $file $where > $outfile"); while(is_process_running($ps)) //echo $output; ?> Bash script to call uploading program: Code: [Select] #!/bin/sh { FILE=$1 WHERE=$2 FILENAME="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_mu_$FILE" FILENAME2="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_multi_$FILE" /usr/local/bin/plowup megaupload "$WHERE$FILE" >> "$FILENAME".txt 2>&1 /usr/local/bin/plowup multiupload "$WHERE$FILE" >> "$FILENAME2".txt 2>&1 } & this works fine when I pass the variables as arguments in CLI I hope i have been clear enough, it does seem rather confusing I have been trying to figure out how this is done? One php file and all that changes is the name of the brand and the logo. This has to be clickable from a menu and also if a user changes the brand name it changes to the appropriate name and logo. Any ideas as to how this is done? If you can guide me in the right direction or give me an example of how this is done would be greatly appreciated. Thanks. http://www.drivermanager.com/en/download-confirmation.php?brand=compaq&logo= I have a full working order form in PHP. I process it and display it with a process page called "process.php." Whenever this information is displayed on the web page "process.php" I also want it to send me an e-mail with all of the information that it just processed. i.e. Checked checkboxes, text entered, etc. Whenever I try to send the contents of "process.php" to an email $message = include 'process.php'; the process page just goes through an infinite loop displaying itself over and over again instead of sending itself in an email.
Edited by AP_King7, 20 August 2014 - 10:51 AM. i have a form for which the data is sent to a process page via jquery like so: Code: [Select] jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ message:jQuery("#message_contents").val() } ,function(data) {etc... new_post_process checks the contents of message like so: if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } the problem is that it always throws this message even when the textarea isnt empty. however after the error has appeared if i submit again it goes through fine. I suppressed the error and tried and the database gets populated with an empty value which means it is indeed empty. so why does it work on the second time around? I am using CKEditor for the textarea. everything else gets submitted normally but this textarea. heres the full code: the textarea: Code: [Select] <textarea cols="80" rows="10" id="message_contents"></textarea> Code: [Select] jQuery("#new_post_form").submit(function() { jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ user_name:jQuery("#user_name").val(), redirect_url:jQuery("#redirect_url").val(), subject:jQuery("#subject_field").val(), forum_id:jQuery("#fid").val(), topic_id:jQuery("#tid").val(), method:jQuery("#method").val(), message:jQuery("#message_contents").val() } ,function(data) { if (data == 1) { jQuery("#process_info").removeClass().addClass("subject_okay").html("<img src=\"<?php echo $this->template_path; ?>icons/small_tick.png\" alt=\"icon\" />Redirecting...").fadeIn("slow"); var URL = jQuery("#redirect_url").val(); document.location = URL; } else { jQuery("#reply_btn").css("visibility", "visible"); jQuery("#draft_btn").css("visibility", "visible"); jQuery("#process_info").removeClass().addClass("subject_error").html('<img src="<?php echo $this->template_path; ?>icons/small_error.png" alt="icon" /> ' + data).fadeIn("slow"); } }); and the process page: if (isset($_POST['subject'])) { $message = $_POST['message']; if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } if (empty($error) && $is_error == false) { $query = $link->prepare("INSERT INTO ".TBL_PREFIX."posts (p_fid, p_tid, p_poster, p_name, p_content, p_time_posted) VALUES ('$forum_id', '$topic_id', '$user_name', '$subject', '$message', '".$config['time_now']."') ") or die(print_link_error()); echo "1"; } else { echo $error.'-'.$message; } This may spill over into java, just not quite sure yet! Basically what I am trying to do, is fill a box with text, click a button which runs a function which send the text in the box via a JSON request to an external server. The JSON works fine, I just want a way of submitting the string which hopefully doesnt involve a form, but its the only way I can think of! Any other ideas? hi, is there a way to tell php to do a process again? example: Code: [Select] $draft_number=rand(1, 15); if($draft_number == 5){ START OVER AT TOP } else { $sql1 = "UPDATE names SET draft = '$draft_number' WHERE id = '$uid'"; $result1 = mysql_query($sql1) or die('Error, Check you fields and try again.'); } I have this code: $shell = new COM('WScript.Shell'); $shell->Run("C:\WINDOWS\system32\cmd.exe /K ".$ini['indexer']['command'], 0, false); When it runs, it opens the command line, but then when it is done, it leaves the process open. How can I close it when the process is complete? this retrieves data from a webservice at Library of Congress for example this here http://www.loc.gov/standards/sru/simple.html What I want to do is process the XML? into a string of usable text to put in a mysql database Am I getting XML back or what? save it and run it to see. In firefox, it shows xml headers, in chrome just the text elements. <?PHP //from here http://www.devshed.com/c/a/PHP/Fetching-Search-Results-as-Serialized-Arrays-with-Yahoo-Web-Services-and-PHP-5/1/ //http://php.net/manual/en/book.simplexml.php // example using LOC SRU Search Web Service - search results are displayed in raw XML format try{ $request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5'; // trigger the http request if(!$results=file_get_contents($request)){throw new Exception('Error requesting LOC SRU Web service');} // display the results in XML format header('Content-type:text/xml;charset=iso-8859-1'); echo $results; }//end of try catch(Exception $e){echo $e->getMessage();exit();} $xml = simplexml_load_string($result); print_r($xml); //print_r ($xmlarray); ?> hi there, I have a chained combo boxes. I manage to get the values for the sub process using onchange event.My problem here is how can I retain the values in the sub process combo box after the page is loaded? main.php Code: [Select] <?php require_once 'connectDB.php'; $sub_id = $_GET['sub_id']; $id = $_SESSION['process_id']; $sql = " SELECT * FROM tb_process ORDER BY pro_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $sql = "SELECT tb_record.rec_tpcd, tb_record.rec_part, tb_record.rec_code, tb_record.rec_vendor, tb_record.rec_location, tb_record.rec_remark, tb_sub_process.sub_name, tb_process.pro_name FROM tb_record LEFT JOIN tb_sub_process ON tb_record.sub_id=tb_sub_process.sub_id LEFT JOIN tb_process ON tb_sub_process.pro_id=tb_process.pro_id WHERE tb_sub_process.sub_id = '$sub_id'"; $result2 = mysql_query($sql); $row = mysql_fetch_assoc($result2); $pro_name = $row['pro_name']; $sub_name = $row['sub_name']; ?> <html> <head> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript" src="js/jquery-1.2.3.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#selectProcess").change(function() { var processID = $(this).val(); if(processID > 0) { $("#txtID").val(processID); $("#selectSubProcess").load('getSub.php?processID='+processID); } }); $("#selectSubProcess").change(function() { var subProcessID = $(this).val(); if(subProcessID > 0) { window.location = 'main.php?sub_id='+subProcessID; } }); }); </script> </head> <body> <form action="" method="post"> <table> <tr> <td>Process: </td> <td> <select id="selectProcess" name="selectProcess"> <option value="0" selected="selected">---SELECT PROCESS---</option> <?php while ($row = mysql_fetch_array($result)) { $process_id = $row['pro_id']; $process_name = $row['pro_name']; $select = ($id == $process_id) ? 'selected="selected"' : NULL; echo "<option value='$process_id' $select>$process_name</option>"; } ?> </select> </td> </tr> <tr> <td>Sub Process: </td> <td> <select id="selectSubProcess" name="selectSubProcess" > <option>SELECT PROCESS FIRST</option> </select> </td> </tr> </table> </form> <table border=1> <?php while($row = mysql_fetch_assoc($result2)) { extract($row); $imageDir1="images/".$rec_tpcd.".jpg"; $info = @getimagesize($imageDir1); if((bool)$info) { $imageDir="images/".$rec_tpcd.".jpg"; } else { $imageDir="images/NoPhoto.jpg"; } if ($col == 0) { $display .= "<tr>"; } $col++; if ($col == 1) { $col = 0; $display .= "</td>"; } echo "<tr> <td> <img src=$imageDir width='220' height='170' onClick=\"window.open('$imageDir', 'popup','height=500,width=800,scrollbars=yes,resizeable=yes status=yes'); return false\" target=\"_blank\"> </td> <td> <table style='overflow:auto; width:325px;'> <tr> <td width='80' valign='top'>Name</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_part</td> </tr> <tr> <td valign='top'>Code</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_code</td> </tr> <tr> <td>TPCD</td> <td>:</td> <td colspan='2'>$rec_tpcd</td> </tr> <tr class='style15'> <td>Vendor</td> <td>:</td> <td colspan='2'>$rec_vendor</td> </tr> <tr> <td>Location</td> <td>:</td> <td colspan='2'>$rec_location</td> </tr> <tr> <td>Remarks</td> <td>:</td> <td>$rec_remark</td> <td align='right'> <input type='image' name='change[$rec_tpcd]' src='library/cart add.png' width='20' height='20' value='Add To Order List >'/> </td> </tr> </table> </td> </tr>"; } ?> </table> </body> </html> getSub.php Code: [Select] <?php require_once 'connectDB.php'; if(isset($_GET['processID'])) { $process_id = $_GET['processID']; $sql = " SELECT * FROM tb_sub_process WHERE pro_id = '$process_id' ORDER BY sub_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $_SESSION['process_id'] = $process_id; echo "<option>---------------------SELECTION--------------------</option>"; while($row = mysql_fetch_assoc($result)) { $sub_process_id = strtoupper($row['sub_id']); $sub_process_name = strtoupper($row['sub_name']); echo "<option value='$sub_process_id'>$sub_process_name</option>"; } } ?> I could use some suggestion on how to model the Checkout Process for my e-commerce site. As I see it, when a person "checks out" there are 5 steps... 1.) Create an Account/Log-In 2.) Enter Addresses 3.) Choose Shipping Options 4.) Enter Payment Details 5.) Review & Place Order I'm trying to avoid having gigantic "God classes" and struggling to figure out how to abstract things in good OOP terms. My Head First: Design Patterns book talked about the "State Pattern" and I'm wondering if that might be a good approach? Maybe each of the 5 steps above could be a "state" in the Checkout Process? What do you think? TomTees Hi Im doing a login for a website I've built and Im having troubles, The connection to the actual database works fine, no errors, but when trying to verify data in the database to log on and get to a secure area i just get the incorrect username or password that i created for when details are incorrect. heres the code where the problem lies Any help would be appreciated <?php session_start(); require("db_connect.php"); $username = $_POST['uname']; $password = $_POST['pword']; $sql = "SELECT * FROM login_details WHERE username='$username' AND password='$password'"; $results = mysql_query($sql, $connect); $numofrows = mysql_num_rows($results); if ($numofrows == 1) { $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = true; header ("Location: secure_page.php"); die(); } else { $_SESSION['error']= "Icorrect Username Or Password"; header("Location: login.php"); die(); } ?> This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=355947.0 hello, I have this problem in running a specific command after using shell_exec or exec to execute a certain process. The process I am running is unimrcpclient, after initialization, it expects some command to be entered in order to communicate with the mrcp server. however, passing the command as an attribute is not an option. Is there a way in PHP to execute a process, wait for initialization and then pass the command automatically? thank you. Hey guys my code is like this Code: [Select] <?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $_POST['name']. "<br />"; echo "You are ". $_POST['age']. " years old."; exit(); } ?> <html> <body> <form action="<?php $_PHP_SELF ?>" method="POST"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> The Inputs are taken from form.How do I make it display somewhere at the bottom of the form in the same page.The Output of this code comes up in a new page. |