PHP - Passing Multiselect Data To Php
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 Similar TutorialsI can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Hi 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.
I'm in the need of some help. Cant figure out what is wrong with the code. Getting undefined all the time. The idea is to pass current playing video and user data to javascript using data-value="valuehere" and then let javascript to send the data to db with the current time and so on. I had a working solution but wanted to use videojs player and now im stuck. The code before was: (function(a){ a(".history").on("click",function(){ var b=a(this).data("mp4"); var store_type=a(this).data("store_type"); var store_title=a(this).data("store_title"); var store_tmdbid=a(this).data("store_tmdbid"); var subtitle=a(this).data("subtitle"); var resume=a(this).data("resume"); var user_id=a(this).data("user_id"); var playpath=a(this).data("mp4")+a(this).data("resume"); a(".yt-modal-box").append('<div class="modal fade" id="yt-modal"><div class="modal-dialog"><div class="modal-body flex-video widescreen"></div></div></div>'); a("#yt-modal").modal(); a("#yt-modal").find(".modal-body").html('<button type="button" class="modal-close" data-dismiss="modal" aria-hidden="true"></button><div id="video_container"><video width="100%" controls autoplay id="video"><source src="'+playpath+'" type="video/mp4"><track kind="subtitles" src="files/Movies/Subtitles/'+subtitle+'" srclang="et" />Your browser does not support the video tag.</video></div>'); a(document).on("hide.bs.modal",function(){ clearInterval(refreshId); a(".modal-body").html("")}) function updater(){ $.post("modules/api/unfinished/update.php",{ unban: "none", user_id: user_id, filename: b, store_type: store_type, store_title: store_title, store_tmdbid: store_tmdbid, lenght: video.duration, position: video.currentTime, }) .done(function(data){ if(data == 1){ $.post("assets/api/unfinished/update.php",{ unban: "unban", user_id: user_id, filename: b, lenght: video.duration, position: video.currentTime, }) function redirect(){ window.location = 'logout.php' } setTimeout(redirect, 2000); } }); } var refreshId = setInterval(updater, 5000); }) })(jQuery);Now i have something like this: <video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered history" controls preload="auto" width="100%" height="389" data-resume="123" data-setup="{}" > var myValue; (function(a){ a(".history").ready(function(){ myValue=a(this).data("resume"); }) videojs("example_video_1").ready(function(){ var myPlayer = this; myPlayer.on("play", function(){ alert(window.myValue); // I would like to use the myValue under this. }); //myPlayer.play(); }); })(jQuery);If you have something then please help out. Thanks. 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.
Hi,
I have a php script that generates a select dropdown box
<option value="1"> Bob </option>
<option value="2"> Tim </option>
<option value="3"> Sam </option>
<option value="4"> Phil </option>
I then have the following javascript to produce my google api graph:
<script type="text/javascript"> google.load('visualization', '1', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var jsonData = $.ajax({ url: "test1.php", dataType:"json", async: false, }).responseText; var data = new google.visualization.DataTable(jsonData); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data); } </script>This then runs a php script that returns the data back in Json format. How can I pass the <option value=""> through the to the test1.php script to generate the json data based on the the value selected i.e 1, 2, 3 etc. i an new at javascript and the google api can anyone let me know how I can get this variable sent through by the google api script. and for the graph to refresh every time another option is chosen. Thanks kris I'm using PHP and MySQL to display images on the first page.
When the image is clicked on I'm passing an ID to a new page.
I want that ID to display the ID data that's associated with that ID.
For example:
ID 1 should display - Title - title1, Details - details1, image - image1
and ID 2
ID 1 should dislay - Title - title2, Details - details2, image - image2
But only displaying ID 1 data not matter if the URL is - website.com/thedetials.php?id=1 or website.com/thedetials.php?id=2
In other words, it displays the same data even though the id in the URL is different.
Page 1
$sql="SELECT * FROM thetable"; $result = mysqli_query($con,$sql); echo " <ul>"; while($row = mysqli_fetch_array($result) { echo "<li'>"; echo "<a href='page2.php?id=$row[id]'><img src=$row[image]></a>"; echo "</li>"; } echo "</ul>"; ?> <?php // End while loop. mysqli_close($con); ?>Page 2 $id = $_GET['id']; $sql="SELECT id, title, details, image, FROM thetable"; $result = mysqli_query($con,$sql); $row = mysqli_fetch_array($result); ?> <?php echo $row['title'] ?> <?php echo $row['details'] ?> <img class='projectItem-pic' src="<?php echo $row['image']?>">If I use below - No data displays, not sure why. $sql="SELECT * FROM thetable WHERE id = $id";Can someone tell me what I'm doing wrong? Edited by patmon, 08 June 2014 - 09:22 PM. Having some issues, hopefully you guys can identify a solution for me. There are 7 Servers involved in this situation - Each with its own website. Server 1 houses a page with content that is shared by the other 6 servers. I need to change an image (logo) at the top of Server 1 page based upon which server they originally came from. For example they are traveling from server 4, when they arrive at server 1 they see server 1 content however the image at the top will corrospond with correct brand in this example server 4's logo. Cookies have not been a reliable solution considering they are usually disabled. Please Help Guys, Any feedback is Fantastic! 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 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 I will try and explain this as best I can, as I am not sure if the "include" is causing the problem. What I am trying to achieve is count the total number of vehicles in the "vehicles" db table and pass it to views (I have recently moved over to MVC so still learning so please be kind and keep it simple for me please) I have a folder in views called "vehicletracker" , within this folder I have 2 files "index.php" and "widget.php".........The "widget.php" file is an "include" within "index php". The problem I am having is passing data from the controller to the view, I keep getting an "Undefined index: total" error and wonder if someone can help and show me where I am going wrong. This is my Model
<?php class Widget { private $db; public function __construct(){ $this->db = new Database; } public function countVehicles(){ $this->db->query("SELECT * FROM vehicles"); return $this->db->rowCount(); } } This is my controller
<?php class Widgets extends Controller{ public function __construct(){ $this->widgetModel = $this->model('Widget'); public function widget (){ $data['total'] = $this->widgetModel->countVehicles(); $this->view('vehicletracker/widget', $data); } } And my view
<h2 class="text-white"><?php echo $data['total']; ?></h2>
Thanks in advance for any help you can give I have a shopping system set up and all works fine until the page where I ask for the clients invoice details etc... I am using php to validate the form data. This works fine but then after it has validated and you submit the form the data does not get passed as I am using a http location redirect. I have heard people mention curl to pass the data, but have never used this before and dont know where to start. Is there an alternate way of doing this. The form data is passed to another website url of a site that processes our payments. Please can someone tell me the best method? I know I could validate with javascript, but want to stay away from that. Alright, So i want to pass a session from www.mysite.com to mobile.mysite.com And i'm doing so by calling this on the top of every page on each site: <?php session_set_cookie_params(360000, "/",".mysite.com"); session_start(); print_r($_SESSION); ?> yet, the session data that is set on one subdomain is NOT printed on the other subdomain. I've even tried destroying the sessions several times to start over. But it won't work. What could be up? Thanks Hi, I have a (probably quite simple) question about passing form data to a php script that contains an iframe with another php script that also needs some of this form data. Basically, my problem is as follows: I have the following code in a file called example1.php: Code: [Select] <html> //some html stuff <?php if(isset($_POST['from'])) {$from1 = $_POST['from'];} else {$from1 = 'English';} $langList = array('English', 'French', 'German', 'Dutch'); print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; ?> //some more html stuff </html> As you can see, it retrieves a variable via POST and selects its value from a list. The variable is posted from an html file (example0.htm) containing the following: Code: [Select] <form method="post" action="example1.php"> This worked fine, until I put example1.php inside an iframe in example2.php as follows: Code: [Select] <html> //some html here <?php //some php here ?> <iframe src ='example1.php' id='something' name='something' > </iframe> </html> and changed: "post" action="example2.php" in my html form. My question is: how do I pass form data from example0.htm to example2.php to example1.php, so that example2.php gets loaded when the submit button on my form gets pressed, but so that example1.php (which gets loaded from the iframe in example2.php) can also access the form data? Thanks! I had been escaping my arguments before passing to exec(), and then type casting back on the other end. Recently needed to pass an array, and at first planned on json_encode(), but gave serialize/unserialize a try and discovered that it automatically took care of the type casting. The data is coming from me thus I am not (hopefully!) worried about malicious data. Any need to also use escapeshellarg() either before or after serializing? Thanks This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355809.0 Hi everybody. So I tried to do some research on this and the answers I found were pretty complicated and hard for me (as a newbie) to understand. What I am trying to do is send the results of an HTML form (radio buttons) to more than one php script (currently name_BB1.php but I would also like to send it to name_2.php). Is there a simple way to do this? Is it even possible?
All I need to pass from the script is the name of the department chosen (Music Books or Video) and the first script uses that information to access related databases. However the second script also needs to know the name of the department originally chosen and I don't know how to get that variable over there without asking the user a second time.
HTML:
<form action="name_BB1.php" method="POST"> </p>Which database would you like to select?<br \><br \> <input type="radio" name="choice" value="Music" />I want music!<br \> <input type="radio" name="choice" value="Books" />Give me books!<br \> <input type="radio" name="choice" value="Video" />I want to see videos!<br \><br \> <input type="submit" value="submit"> </p> </form> Thanks! Greetings... I have been staring at my whiteboard pondering a new architecture for processing data in an application. New for me anyways. I want to create a more centralized and modular method of handling data. For ease of explanation I will put it into the context of a login system which is where I first started thinking about this. I know there are a lot of login systems out there but I wanted to create one from scratch which utilizes PDO although that specific thing is not germane to my main question. Here we go... Lets say that for my Registration, Login and Forgot Password pages the forms on each page were directed to "Process.php" The idea is that process.php will provide the centralized platform to deal with data, acting as a choke point in the application making it easier to secure. This will also provide the means to quickly develop new parts of an application knowing that my methods of dealing with data area already well defined and secure. There is one hole in the idea that I can see though. If the user data being submitted to the process.php page does not meet the security requirements then the user must be sent back to the previous page. I dont' want to lose the data they have already entered into the forms. ie. I want to have it appear in the form fields... makes sense right. Now here comes my question... is there a way to pass POST data when using header("location: http://mySite/previousPage.php") It seems from my experiments that the data is lost. I do not use header(); often. In previous designs I have usually created each part of a login system as seperate and self contained entities apart from using a common db object. I know there are other ways around this, using session data for instance but this idea has been eating away at me for a little while and I feel its time to ask around for some advice. It has become a matter of curiosity. I have found some info on sending POST data using header but it did not seem to meet the requirement that the user and the POST data be sent to another page synchronously. At first I thought that maybe I would just do validation on the frontend / view pages (not to be taken as clientside) and if it was valid, then submit it to process.php, validate it again the let it be handled appropriately to its particular end but then I run into the same problem plus there is the extra overhead of validating the data twice. I guess thats it for now. Sorry if that was a little long-winded... its part of my process, helps me to better understand what I really want to know. Using header() on a receiving page from a form page... the redirecting header() with POST data, sending the user to a new/previous page. Possible? I've been poking around the Internet for the answer to this without any success. This query APPEARS to run, but NOTHING GETS INSERTED. The QuestionID in the Questions table is set to auto-increment, so I only need the QuestionText data for this table. the QuestionID in the Answers table is not because there might be four or five options per question. The snippets of code under consideration is pasted below snipped from index.php: Code: [Select] <form action="./newquestion.php" method="post"> Question Text:<br><input type="text" size=100 name="QuestionText" /><br><br> <input type="submit" value="Enter next question"/> </form> Then snipped from newquestion.php mysql_select_db(quiz); $query = mysql_query("INSERT INTO Questions VALUES ('$_POST[QuestionText]'"); $result = mysql_query($query); Thank you all. I'm sure I'll learn this pretty fast, but I still need a little help. Hello all, I'm hoping someone can help me out. Here is the code I have for a page that contains a user form: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> And here is the page that the user information is supposed to be passed to: <?php include "include/dbc.php"; include "include/header.inc"; $duration = $_POST["duration['.$row['Name'].']"]; echo '<h1>Added Activities</h1>'; echo $duration; ?> Well, this isn't working for me. The second page code returns this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING When I execute print_r, the values are returned to me. So I have two questions: 1) What do I need to do to change the code on the 2nd page to echo and POST the array? 2)The database contains multiple exercises under the same name. So, when the variables are passed to the 2nd page. All the values are returned regardless of whether they have been filled out or not. What can be done to only returned the user input and not the blank variables? |