PHP - Vote System - Stop Multiple Votes?
Hey. I just needed a little help with a voting system for articles I've put together in PHP. Essentially what happens is someone clicks the "Vote up" button which takes them to the "voteup.php" page.
This is the "voteup.php" page where it updates the database for that given article and increments the "votes" column by one. This works perfectly. But the problem is people can do this infinite times and give articles infinite votes. I need it so that each IP address can only vote on each specific article once. Any ideas on how this could be done? Voteup.php Code: [Select] <?php include("connect.php"); $id2 = $_GET['id']; // Get the ID of the article that will be voted up $con = mysql_connect("localhost","lconditn_admin","hello"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("lconditn_database", $con); mysql_query("UPDATE base SET votes = votes+1 // Add one vote to the article WHERE id2 = '$id2'"); mysql_close($con); ?> Thanks a lot for any help with this. Similar TutorialsThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 Hello, I have a little thing I am making, and it is a Toplist. People can vote for a user, and then there vote will go up. But people can only vote once per day on one IP address. I am having a problem ordering my front page by votes though. Here is my code for it to load the votes, and to display the user's on the list. <?php include 'vote.php' $list_q = mysql_query("SELECT * FROM toplist WHERE premium='1' && activated='1' && ban='0' && staff='0' ORDER BY '$voteAmount'") or die (mysql_error()); while($list_f = mysql_fetch_assoc($list_q)) { list ($error, $message, $voteAmount) = voteAmount(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $list_f['id']); ?> <tbody style="" id="cat_1_e"> <!-- start: forumbit_depth2_forum --> <tr> <td class="trow2" align="center" valign="middle" width="1"></td> <td class="trow2" valign="middle"> <strong><a href="server.php?view=details&id=<?php echo $list_f['id'];?>"><?php echo capitalizeFirstCharacter($list_f['servername']);?></a></strong><div class="smalltext"><?php echo $list_f['shortdescription'];?></div> </td> <td class='trow1' valign='middle' align='left' style='white-space: nowrap'><span class='smalltext'><?php echo $list_f['revision'];?></span></td> <td class="trow2" valign="middle" align="right" style="white-space: nowrap"><font size="4px"><?php echo $voteAmount;?> Votes</font></td> </tr> <!-- end: forumbit_depth2_forum --> </tbody> <?php } ?> And here is the code to my vote.php file that it loads all of the data from. <?php function install($host, $user, $pass, $db) { $c = @mysql_connect($host, $user, $pass); if(mysql_select_db($db, $c)) { mysql_query('CREATE TABLE `'.$db.'`.`votes` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `ip` VARCHAR(50) NOT NULL, `serverId` INT(50) UNSIGNED NOT NULL, `date` DATETIME NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB;'); return true; } else { return false; } } function voteAmount($host, $user, $pass, $db, $serverId) { $c = @mysql_connect($host, $user, $pass); if($c) { if(mysql_select_db($db, $c)) { if($getVotes = mysql_query('SELECT * FROM `'. $db .'`.`votes` WHERE serverId='. $serverId)) { if(mysql_num_rows($getVotes) >= 1) { $getVoteQ = mysql_query('SELECT COUNT(id) AS total FROM `'. $db .'`.`votes` WHERE serverId='. $serverId); $vote = mysql_fetch_assoc($getVoteQ); return array(0, "", $vote['total']); } else { return array(0, "", 0); } } else { if(install($host, $user, $pass, $db)) { return array(1, "The vote script has successfully been installed.<br>Please reload the page.", 0, 0); } else { return array(1, "Could not connect to DB.", 0); } } } else { return array(1, "Error connecting to DB.", 0); } } else { if(install($host, $user, $pass, $db)) { return array(1, "The vote script has successfully been installed.<br>Please reload the page.", 0, 0); } else { return array(1, "Could not connect to DB.", 0); } } } // list ($error, $message, $voteAmount) = voteAmount('HOST', 'USER', 'PASS', 'DB', $_SERVER['REMOTE_ADDR'], SERVER_ID); function votedToday($host, $user, $pass, $db, $hours, $ip, $serverId) { $c = @mysql_connect($host, $user, $pass); if($c) { if(mysql_select_db($db, $c)) { if($getVotes = mysql_query('SELECT * FROM `'. $db .'`.`votes` WHERE ip="'. $ip .'"')) { if(mysql_num_rows($getVotes) >= 1) { $dateQ = mysql_query('SELECT MAX(date) AS lastVoteDate FROM `'. $db .'`.`votes` WHERE ip="'. $ip .'"') or die(mysql_error()); $getDate = mysql_fetch_assoc($dateQ); $diffrence = time() - strtotime($getDate['lastVoteDate']); if (($diffrence / 60 / 60) >= $hours) { mysql_query('INSERT INTO `'. $db .'`.`votes` (`ip`, `serverId`, `date`) VALUES ("'. $ip .'", '. $serverId .', NOW())') or die(mysql_error()); return array(0, "Your vote has been added."); } else { return array(1, "You can only vote every ". $hours ." hours. So far ". number_format(($diffrence / 60 / 60), 2) ." hours have past."); } } else { mysql_query('INSERT INTO `'. $db .'`.`votes` (`ip`, `serverId`, `date`) VALUES ("'. $ip .'", '. $serverId .', NOW())') or die(mysql_error()); return array(0, "Your vote has been added."); } } else { if(install($host, $user, $pass, $db)) { return array(1, "The vote script has successfully been installed.<br>Please reload the page."); } else { return array(1, "Could not connect to DB."); } } } else { return array(1, "Error connecting to DB."); } } else { if(install($host, $user, $pass, $db)) { return array(1, "The vote script has successfully been installed.<br>Please reload the page."); } else { return array(1, "Could not connect to DB."); } } } // list ($error, $message) = votedToday('HOST', 'USER', 'PASS', 'DB', HOURS, $_SERVER['REMOTE_ADDR'], SERVER_ID); ?> Once again, I am trying to make it so the list is ordered by how many votes that server has. Here is an example of the votes database. Code: [Select] CREATE TABLE IF NOT EXISTS `votes` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ip` varchar(50) NOT NULL, `serverId` int(50) unsigned NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; INSERT INTO `votes` (`id`, `ip`, `serverId`, `date`) VALUES (6, '::1', 4, '2010-08-07 11:44:44'); Hey all, i have a problem; i have 2 arrays: $haystack //contains all posible answers in the poll, it contains dates for possible meetings Array ( => 12-02-2011 [1] => 13-02-2011 [2] => 14-02-2011 [3] => 15-02-2011 ) $needles //contains the answers the user clicked Array ( => 12-02-2011 [1] => 13-02-2011 ) i have about 10 entries simulated and i want to count the corresponding dates into another array so: Array ( => 5 [1] => 3 [2] => 1 [3] => 1 ) keep in mind that the users can give multiple answers Dear All, I am developing a like/dislike voting system for a scientific experiment in which the user will cast vote on a number of images. I have already written the code for it but the code is unable to store the data in the database. Kindly help me out in this issue. Below is my code for it: HTML Form for Like/Dislike Button: Code: [Select] <html> <head> <title> Like/Dislike buttons </title> </head> <body> <h1> Like/Dislike buttons </h1> <form name="form1" action="likedislike.php" method ="post"> <input type="submit" name="Like" value="Like"> <input type="submit" name="Dislike" value="dislike"> </form> </body> </html> PHP code for retrieving data and storing the vote in the database: Code: [Select] <?php session_start(); ob_start(); $host="localhost"; $username="computat_abhi"; $password="1123581321"; $databasename="computat_button"; $tbl_name="record"; $db=mysql_connect ("localhost","computat_abhi","1123581321")or die("cannot connect"); mysql_select_db($databasename,$db); if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(Image Number,Like Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } elseif(isset($_POST['Dislike'])){ $sql = 'INSERT INTO record(Image Number,Dislike Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } ob_end_flush(); ?> Thank you for your help. I'm looking to know the best way to process a search query that has multiple words in the search: Code: [Select] elseif(isset($_GET['search'])){ $search=$_GET['search']; $keyword=explode(" ",$search); //database query } Should I do a while loop query the database for each keyword? Hey All, I'm tryin to make a log-in system for multiple usernames and passwords, but I don't really know how many if statements i'd need for it.. I'm also a noob.. Code: [Select] <?php session_start(); $users = array("user1" =>"3202", "user2" =>"2002", "user3" =>"1061", "user4"=>"1400", "user5"=>"1001"); if($_REQUEST['username'] == "infs" && $_REQUEST['password'] == "3202"){ $_SESSION['username'] = "user1" ; $_SESSION['password'] = "3202" ; $_SESSION['username'] = "user2" ; $_SESSION['password'] = "2002" ; $_SESSION['username'] = "user5" ; $_SESSION['password'] = "1001" ; $_SESSION['username'] = "user3" ; $_SESSION['password'] = "1061" ; $_SESSION['username'] = "user4" ; $_SESSION['password'] = "1400" ; header("Location: home.php "); }else{ After checking if the matching username and password exist in my array then save them in a session... What's the best way of doing it? Hello PHP mates! I am having some doubts and I am going to share them with you so maybe someone can help. Okay, I know how to make signup and login page. And here is the problem. How to make signup page for multiple types of users? For example, type A user has its own signup form, user type B also has its own and same goes for C type of user. How can I make that? Thanks in advance PHP freaks! Hi everyone, I have a like button on repeating regions that is used for keeping a record of votes on comments. People click it an it adds 1 to the votes column total. It works just fine. Problem is i only want to a allow a user one vote per comment only. can vote on other comments as well, but again, only one vote per day per comment. i wouldn't know where to start. Would i use a cookie or record an ip? switch ($_REQUEST['action']) { case 'likeit'; foreach($_REQUEST as $key=>$value){ $$key = $value; } $votes = $_GET['votes']; $total = ($votes + 1); $sql = mysql_query("UPDATE quotes SET votes = '$total' WHERE quoteid = '$quoteid'"); break; } I get to errors below and cannot figure out what im doign wrong i've tryed diffrent ways and have even rewritten this couple times (#1error) not sure how to re query and echo out the array?? (#2error) gives me error on line 14 if i echo anything past (echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. ->this Code: [Select] <?php $conn = mysql_connect("localhost", "root", ""); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); } if (!mysql_select_db("register_db")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'"); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } =========================(#1error)========================================== //THIS IS THE CODE I'M HAVING ISSUES WITH if (mysql_num_rows($result) == 0) { mysql_query("INSERT INTO register_vote (name) VALUES ('$_POST[user]')"); //need it to the query new results after insert //then // echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3']; }================================================= (#2error)=================================== while ($row = mysql_fetch_array($result)) { echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3']; } //when I put anything past $row['user2']. it gives me error on line 14 mysql_free_result($result); ?> Hi im trying to Make a Timer count down in this code function getTime($host, $user, $pass, $db, $hours, $ip, $serverId) { $c = @mysql_connect($host, $user, $pass); if(mysql_select_db($db, $c)) { $dateQ = mysql_query('SELECT MAX(date) AS lastVoteDate FROM `'. $db .'`.`votes` WHERE ip="'. $ip .'"') or die(mysql_error()); $getDate = mysql_fetch_assoc($dateQ); $diffrence = time() - strtotime($getDate['lastVoteDate']); $hours = number_format(($diffrence / 60 / 60)); $minutes = number_format(($hours / 60)); if(!$hours < 1){ return ("". $hours .""); } else { return ("0"); } } else { return array(1, "Error connecting to DB."); } } Hello, I have built a blog in php but. On each article in the blog people are able to comment. I would now like to build a system where people can vote on the comment up/down with Ajax. In my comments database I have a table that looks like this: id / article_id / user_id / dateposted / comment / voteup / votedown I would like it to look like this: Any ideas how I can do this? Tutorials online? Thanks a million I'm currently trying to break apart some PHP coding that a former coder created, but left no documentation to. Can anyone help e find the function in this mess that creates the vote button and passes the currently loaded data to the next page? Here's the original code: Code: [Select] <?php include("./templates/mysql_connect.php"); //FOR LETTER: A $query = "SELECT * FROM seniors WHERE last_name LIKE 'A%' ORDER BY last_name ASC"; $result = @mysql_query ($query); echo '<table><tr> <td> <p><span class="style19"><u>-A-</u></span><br />'; while ($row = mysql_fetch_array ($result)){ echo "<a href=\"$row[pic_url]\" rel=\"lightbox[seniors]\" title=\" <form action ="/sencha-tallyvote.php?sen_id=$row[sen_id]" method="post"> $row[first_name] $row[last_name] - $row[school] <br /> <input name="submit" align="right" type="submit" value="Vote" > </form> \">$row[last_name], $row[first_name]</a><br/>"; } echo '</p>'; ?> The original code used a lightbox feature with an added voting button tagged on near the bottom. We've Xed the lightbox feature and are trying to deconstruct it into tangible PHP pages. We have everything done except for the coding for the vote button. Here's our coding for the currently deconstructed page, and where the coding for the button needs to go: Code: [Select] <?php require_once('templates/mysql_connect.php'); ?> <?php $query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]"; $result = mysql_query ($query); $row = mysql_fetch_array ($result); ?> <div class="contents"> <h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1> <h4><?php echo $row['school']; ?></h4> </div> <?php echo '<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />'; ?> <?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />" ?> <br /> <br /> <a href="/">{{VOTEBUTTON}}</a> Any experienced help will be greatly appreciated. Hi, I run a top site which has incentives. Originally when a voter came and voted, the script in the background would run file() but I noticed that it sometimes lagged and caused the voter to wait a few secs before the page loads. I was then told by a developer to use file_get_contents(), but I was getting the same results. It occasionally lagged, even on my own websites that are voting on it. I decided to log the incentives now, and get a cron to check and process any incentives instead of the user lagging, but now it's starting to kill my server as you can see below Quote xxxxx.com 1.05 0.49 0.1 Top Process %CPU 77.2 php -q process_incentives.php Top Process %CPU 24.0 php -q process_incentives.php Top Process %CPU 8.0 php -q timers/5mins.php xxxxx.com 0.99 0.13 0.0 Top Process %CPU 9.0 php -q timers/30mins.php Top Process %CPU 7.0 php -q timers/5mins.php Code in process_incentives.php //REWARD VOTERS $get = mysql_query("SELECT id,url FROM incentives ORDER BY id DESC limit 50;"); while ($game = mysql_fetch_array($get)){ file_get_contents("$game[url]"); mysql_query("DELETE from incentives WHERE id='$game[id]'"); } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=333432.0 Hi, I'm currently using a voting script, but have a problem with people voting more then once, and want to add a way to keep the voting unique and 1 per person via IP check can anybody assist me how to implement it in the following script please?
<?php // the questions and the answers $pool_question="Do you think I should keep Galaxy Universe open?"; $pool_option[1]="Yes"; $pool_option[2]="No"; // If counter files are not available,they will be created // You may remove next lines after the first use of the script if (!file_exists("pool_5483543_1.txt")){ // next two lines will not work if writing permissions are not available // you may create the files bellow manualy with "0" as their unique content file_put_contents ("pool_5483543_1.txt",0); file_put_contents ("pool_5483543_2.txt",0); } // retrieve data saved in files $pool_responses[1]=file_get_contents("pool_5483543_1.txt"); $pool_responses[2]=file_get_contents("pool_5483543_2.txt"); // if user votes, increase corresponding value if ($_POST["5483543"] and $_POST["5483543b"]==""){ if ($_POST["5483543"]==1) {$pool_responses[1]++;file_put_contents("pool_5483543_1.txt",$pool_responses[1]);} if ($_POST["5483543"]==2) {$pool_responses[2]++;file_put_contents("pool_5483543_2.txt",$pool_responses[2]);} } // get percentajes for each answer in the pool // get total number of answers $total_responses=$pool_responses[1]+$pool_responses[2]; if ($total_responses==0){$total_responses=1;} // to avoid errors at start // compute percentajes (with one decimal number) $pool_percentaje[1] = round((100*$pool_responses[1])/$total_responses,1); $pool_percentaje[2] = round((100*$pool_responses[2])/$total_responses,1); // print the form, which includes de answers and the percentajes print "<center>\n"; print "<form method=post action=".$_SERVER["PHP_SELF"].">\n"; print "<b>".$pool_question."</b>\n"; print "<table cellpadding=4>\n<br>"; // answer 1 print "<tr>\n"; print "<td><input type=radio name=5483543 value=1> ".$pool_option[1]."</td>\n"; print "<td bgcolor=DDDDFF>" .$pool_responses[1]." (".$pool_percentaje[1]."%)</td>\n"; print "</tr>\n"; // answer 2 print "<tr>\n"; print "<td><input type=radio name=5483543 value=2> ".$pool_option[2]."</td>\n"; print "<td bgcolor=DDDDFF>" .$pool_responses[2]." (".$pool_percentaje[2]."%)</td>\n"; print "</tr>\n"; print "</table>\n"; // a simple control to avoid one user to vote several times if ($_POST["5483543"]){ print "<input type=hidden name=5483543b value=1>\n"; } print "<input TYPE=submit value=Add my answer>\n"; print "</form>\n"; print "</center>\n"; ?>The reason why I ask for IP check is I wan't to use $_SERVER["HTTP_X_MXIT_USERID_R"];in the place of the Ip since it give a unique name via the platform I want to implement it. Edited by cobusbo, 14 January 2015 - 01:49 PM. hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 I am using the dragdrop functionality on a page which also updates the database.Drag and drop is working fine But i am having difficulty to determine which events to use to update the database. Here is my code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Sortable - Portlets</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--<link rel="stylesheet" href="/resources/demos/style.css">--> <style> body { min-width: 520px; } .interview-questions-column { width: 400px; float: left; padding-bottom: 100px; } .question-bank { width: 500px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; padding: 0.3em; } .portlet-header { padding: 0.2em 0.3em; margin-bottom: 0.5em; position: relative; } .portlet-toggle { position: absolute; top: 50%; right: 0; margin-top: -8px; } .portlet-content { padding: 0.4em; } .portlet-placeholder { border: 1px dotted black; margin: 0 1em 1em 0; height: 50px; } .sortable { border: 1px solid #eee; width: 95%; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } .bank-quertion-sotrable { border: 1px solid #eee; width: 150px; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .bank-quertion-sotrable li{ margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 200px; } .ui-state-default { height: 1.5em; line-height: 1.2em; } </style> <script> $(function() { $( ".interview-questions-column" ).sortable({ connectWith: ".interview-questions-column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all" }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).click(function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); $(function() { $( ".sortable" ).sortable({ placeholder: "ui-state-default", connectWith: ".connectedSortable", /*receive: function(event, ui) { // only perform for sub drop downs if($(this).hasClass('question_bank')) { // if the item doesn't have the matching sub class if (!$(this).hasClass($(ui.item).attr('class'))) { // cancel the sortable $(ui.sender).sortable('cancel'); } } alert('receive'); alert(ui.sender.attr("dataid")); alert(ui.sender.toSource()); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); },*/ update: function (event, ui) { //serial = $('#sortableF').sortable('serialize'); var data = $(this).sortable('serialize'); alert(data); //alert('update sortable'); //alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); // POST to server using $.post or $.ajax /*$.ajax({ data: 'test', type: 'POST', url: '/your/url/here' });*/ } }).disableSelection(); }); $(function() { $( ".draggable" ).draggable({ connectToSortable: ".sortable", helper: "clone", /*revert: function(valid) { if(valid) { alert("drop is valid"); //Dropped in a valid location } else { alert("drop is invalid"); //Dropped in an invalid location } // return !valid; return false; }*/ stop: function( event, ui ) { // alert(ui); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); } }); }); $( "ul, li" ).disableSelection(); </script> </head> <body> <div class="interview-questions-column"> <div class="portlet"> <div class="portlet-header">Feeds</div> <div class="portlet-content"> <ul id="sortableF" class="connectedSortable sortable"> <li class="ui-state-default" id="item-1">Item 1</li> <li class="ui-state-default" id="item-2">Item 2</li> <li class="ui-state-default" id="item-3">Item 3</li> <li class="ui-state-default" id="item-4">Item 4</li> <li class="ui-state-default" id="item-5">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">News</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-6">Item 1</li> <li class="ui-state-default" id="item-7">Item 2</li> <li class="ui-state-default" id="item-8">Item 3</li> <li class="ui-state-default" id="item-9">Item 4</li> <li class="ui-state-default" id="item-10">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Shopping</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-11">Item 1</li> <li class="ui-state-default" id="item-12">Item 2</li> <li class="ui-state-default" id="item-13">Item 3</li> <li class="ui-state-default" id="item-14">Item 4</li> <li class="ui-state-default" id="item-15">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Links</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-16">Item 1</li> <li class="ui-state-default" id="item-17">Item 2</li> <li class="ui-state-default" id="item-18">Item 3</li> <li class="ui-state-default" id="item-19">Item 4</li> <li class="ui-state-default" id="item-20">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Images</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-21">Item 1</li> <li class="ui-state-default" id="item-22">Item 2</li> <li class="ui-state-default" id="item-23">Item 3</li> <li class="ui-state-default" id="item-24">Item 4</li> <li class="ui-state-default" id="item-25">Item 5</li> </ul> </div> </div> </div> <div class="question-bank"> <div class="portlet"> <div class="portlet-header">Question bank</div> <div class="portlet-content"> <ul id="question_back" class="connectedSortable bank-quertion-sotrable"> <li class="ui-state-default draggable" id="item-26">Item 1</li> <li class="ui-state-default draggable" id="item-27">Item 2</li> <li class="ui-state-default draggable" id="item-28">Item 3</li> <li class="ui-state-default draggable" id="item-29">Item 4</li> <li class="ui-state-default draggable" id="item-30">Item 5</li> </ul> </div> </div> </div> </body> </html>Basically above code will form few boxes with items(which are actually questions) in it. There is one box on the right side with heading "Question Bank". From the "Question Bank" we can drag the questions to other boxes but can't do the reverse(this is also working). Also we can sort the questions within the box or drag the questions from one box to another. Box heading are the categories and items are questions associated to that categories. What i need is : Event that updates the database when we drag the questions from "Question Bank" to any box on the left side. Please note Questions in the "Question Bank" are pre created coming from database. Event that updates the database when we sort the questions within the box. Event that updates the database when we drag the question from one box to another box. it should also do the sorting for that two boxes. Event that updates the database when we sort the boxes. Here is the JS Fiddle link jsfiddle.net/6o30rrzx Question Bank is comming on the bottom of the page instead of on the right side any advice and suggestions will be greatly appreciated Thank you for reading this post. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? Ok I'm trying to insert multiple rows by using a while loop but having problems. At the same time, need to open a new mysql connection while running the insert query, close it then open the previous mysql connection. I managed to insert multiple queries before using a loop, but for this time, the loop does not work? I think it is because I am opening another connection... yh that would make sense actually? Here is the code: $users = safe_query("SELECT * FROM ".PREFIX."user"); while($dp=mysql_fetch_array($users)) { $username = $dp['username']; $nickname = $dp['nickname']; $pwd1 = $dp['password']; $mail = $dp['email']; $ip_add = $dp['ip']; $wsID = $dp['userID']; $registerdate = $dp['registerdate']; $birthday = $dp['birthday']; $avatar = $dp['avatar']; $icq = $dp['icq']; $hp = $dp['homepage']; echo $username." = 1 username only? :("; // ----- Forum Bridge user insert ----- $result = safe_query("SELECT * FROM `".PREFIX."forum`"); $ds=mysql_fetch_array($result); $forum_prefix = $ds['prefix']; define(PREFIX_FORUM, $forum_prefix); define(FORUMREG_DEBUG, 0); $con = mysql_connect($ds['host'], $ds['user'], $ds['password']) or system_error('ERROR: Can not connect to MySQL-Server'); $condb = mysql_select_db($ds['db'], $con) or system_error('ERROR: Can not connect to database "'.$ds['db'].'"'); include('../_phpbb_func.php'); $phpbbpass = phpbb_hash($pwd1); $phpbbmailhash = phpbb_email_hash($mail); $phpbbsalt = unique_id(); safe_query("INSERT INTO `".PREFIX_FORUM."users` (`username`, `username_clean`, `user_password`, `user_pass_convert`, `user_email`, `user_email_hash`, `group_id`, `user_type`, `user_regdate`, `user_passchg`, `user_lastvisit`, `user_lastmark`, `user_new`, `user_options`, `user_form_salt`, `user_ip`, `wsID`, `user_birthday`, `user_avatar`, `user_icq`, `user_website`) VALUES ('$username', '$username', '$phpbbpass', '0', '$mail', '$phpbbmailhash', '2', '0', '$registerdate', '$registerdate', '$registerdate', '$registerdate', '1', '230271', '$phpbbsalt', '$ip_add', '$wsID', '$birthday', '$avatar', '$icq', '$hp')"); if (FORUMREG_DEBUG == '1') { echo "<p><b>-- DEBUG -- : User added: ".mysql_affected_rows($con)."<br />"; echo "<br />-- DEBUG -- : Query used: ".end($_mysql_querys)."</b></p><br />"; $result = safe_query("SELECT user_id from ".PREFIX_FORUM."users WHERE username = '$username'"); $phpbbid = mysql_fetch_row($result); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('2', '$phpbbid[0]', '0', '0')"); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('7', '$phpbbid[0]', '0', '0')"); mysql_close($con); } include('../_mysql.php'); mysql_connect($host, $user, $pwd) or system_error('ERROR: Can not connect to MySQL-Server'); mysql_select_db($db) or system_error('ERROR: Can not connect to database "'.$db.'"'); } So I need to be able to insert these rows using the while loop.. how can I do this? I really appreciate any help. |