Jump to content

Justafriend

Members
  • Posts

    101
  • Joined

  • Last visited

Everything posted by Justafriend

  1. when i tried that with all the code it give me an Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pawn\listtest.php on line 59 but if i i remove the having it works no problem here is the updated code $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT username,COUNT(*) as total, FROM games GROUP BY username HAVING total > 5') as $row) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['COUNT(*)'] . "</td>"; echo "</tr>"; } ?>
  2. I am still working on learning pdo slowly trying to migrate into the newest most secure operations and have an issue with the count and no idea where to look for it i have spent countless hours searching and am no further along so i thought id ask the people here if this is even possible What i have is a count total number of entries per person which i have working perfectly but the issue is i need to only count them when the total is greater then 5 $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT username,COUNT(*), WHERE COUNT(*)<5 FROM games GROUP BY username') as $row) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['COUNT(*)'] . "</td>"; echo "</tr>"; } ?> so if a user only has 4 entries it will skip his name I hope this makes sense and hope someone can help me
  3. I have this code that pulls data from a form and is supposed to check if the neptune and username are inserted 2 times it replies back with an error if not it posts the data to 2 lines with neptune username and email on one line and just email and username on the other The issue is the code i have gives me an error saying unexpected end of file below is my code any help will be appreciated <?php if(isset($_POST['choices']) && !empty($_POST['choices'])){ if($_POST['choices'] == 'four'){ //variables from form entered $username = $_POST['username']; $neptune = $_POST['neptune']; $email = $_POST['useremail']; //connect to the database $dbc = mysqli_connect('localhost', 'root', '', 'happygam_main') or die('Error connecting to MySQL server'); $check=mysqli_query($dbc,"select * from ballot where username='$username' and neptune='$neptune'"); $checkrows=mysqli_num_rows($check); if($checkrows>0) { echo "This combination of neptune and username has already been processed"; } else { //insert results from the form input in 2 rows one with neptune one without $query = "INSERT IGNORE INTO ballot(username, useremail, neptune) VALUES('$username', '$email', '$neptune')"; $query1 = "INSERT IGNORE INTO ballot(username, neptune) VALUES('$username', '$neptune')"; $result = mysqli_query($dbc, $query, $query1) or die('Error querying database.'); mysqli_close($dbc); } } ?>
  4. thank you for all you do and your help this table is only for a week long event we use each year and when its done it is backed up for next year
  5. that fixed the error but its still not updating the column here is an example of the table what im trying to do is count how many for each username that has a non null in the column neptune and if ithe same player has more then 5 Non Null values to mark the morethan5 column with yes
  6. Ok i have a table with headings username useremail randomnumber neptune morethen5 What im trying to do is if a username has more than 5 records where neptune isnt null update the morethan5 column for all username with yes this is the query i have update ballot set morethan5 = yes where username in ( select * from ( select neptune from ballot group by username having count(1) > 5 ) x ) i got first of all an error saying yes column didnt exist so i created a new column called yes and it isnt updating any records
  7. and as for the injections they are all being handled in the java verification of the form so that all data is verified before going into the php
  8. Update found the html error ty for the pointing me in right direction
  9. there are 4 different types of entries there is singles getting 2 ballots ​there is singles getting 1 ballot there is pards getting 2 ballots and there is pards getting 1 ballot Eventually each code will be going to its own confirm submission page as i stated above my post hence why i have 4 different queries ok i will have to look through the html code i just thought that once the php processes a query it doesnt use the code on the page that sent the info but i do appreciate your help and appreciate the direction
  10. first off i know all 4 headers im using are same its temporary for now eventually i will have 4 different confirmation pages The issue im having is all 4 are processing form correctly into the db but the confirmation pages are redirecting to a new tab here is the php code if needed i can supply the html code as well but seeing the header is being pulled from the php file i think thats where it is what i want is that when the html form processes that it redirects the page to one of the four confirmation pages instead of in a new tab $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } if(isset($_POST['choices']) && !empty($_POST['choices'])){ if($_POST['choices'] == 'four'){ $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')"; $sql1 = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; if (mysqli_query($conn, $sql)) ; if (mysqli_query($conn, $sql1)) ; mysqli_close($conn); { { header("Location: http://justtheway.com/wb/events/pawn/get2ticketconfirm.php") ; } } }elseif($_POST['choices'] == 'twoorless'){ $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')"; if (mysqli_query($conn, $sql)) ; mysqli_close($conn); { { header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ; } } }elseif($_POST['choices'] == 'sixseven'){ $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')"; $sql1 = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; if (mysqli_query($conn, $sql)) ; if (mysqli_query($conn, $sql1)) ; { { header("Location: http://justtheway.com/wb/events/pawn/get2ticketconfirm.php") ; } } }elseif($_POST['choices'] == 'fiveorless'){ $sql = "INSERT INTO ballot (username, useremail, randomnumber, neptune) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["randomnumber"]."','".$_POST["neptune"]."')"; if (mysqli_query($conn, $sql)) ; mysqli_close($conn); { { header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ; } } } }else{ echo "Please select once choice for submit query!"; } mysqli_close($conn); { { header("Location: http://justtheway.com/wb/events/pawn/get1ticketconfirm.php") ; } } ?>
  11. i emptied the table now its working properly ty for your help
  12. its when I run it through the code and paste it here if I copy from the list on results page and ran it through your script I get string(15) "​habs4stanley" E2 80 8B 68 61 62 73 34 73 74 61 6E 6C 65 79 string(12) "Habsfan4life" 48 61 62 73 66 61 6E 34 6C 69 66 65 string(4) "demo" 64 65 6D 6F but the names are still in the same order as above
  13. thank you all for your jhelp now i have one other ? the order by name is making it sort by count then name I thought ORDER BY username'; would make it alphabetical but its going by number of entries then alphabetical easiest way to explain what I'm looking for is this is how its resulting demo 2 Habsfan4life 2 habs4stanley 1 what id like is that it goes demo 2 habs4stanley 1 Habsfan4life 2
  14. $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT username,COUNT(*) FROM ballot GROUP BY username') as $row) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['COUNT(*)'] . "</td>"; echo "</tr>"; } the result is coming like this habs4stanley1 demo2 Habsfan4life2 ​I need it to put it like this ​habs4stanley 1 ​demo 2 ​habsfan4life 2 ​any help is greatly appreciated
  15. ok i am not sure if i have to do it via transactions i tried changing out the code to this // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["output"]."')"; $sql1 = "INSERT INTO bonus (username, useremail, randomnumber) VALUES ('".$_POST["username3"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; if (mysqli_query($conn, $sql, $sql1)) ; mysqli_close($conn); { header("Location: http://justtheway.com/wb/events/pawn/Preregisterconfirm.html") ; } ?> and i get it redirected to submission page BUT it is only entering into the bonus table not the ballot table
  16. Ok i have 2 issues i will start with the harder one first as it is more past my experties and i have spent time troubleshooting and cant get it solved i have 1 player name email address and 2 random numbers(ballots) that im trying to enter into my db after lengthy playing with the code i have 2 sql insert statements which will only grab the last one into the db Method 1 Steps i tried and results created 2nd table for the 2nd insert RESULT Only inserts to 2nd table echo only shows 2nd insert Method 2 name the sql insert to sql and sql1 same table RESULT gives me Warning: mysqli_multi_query() expects exactly 2 parameters, 3 given in but echos correctly ​ Method 3 Name the sql insert to sql and sql1 different table Result gives me same warning and echos correctly Ideally i would like it to go into 2 rows in same table but am ok with having 2 separate table here is the code // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["output"]."')"; $sql1 = "INSERT INTO bonus (username, useremail, randomnumber) VALUES ('".$_POST["username3"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; echo $sql ; if (mysqli_multi_query($conn, $sql, $sql1)) ; { echo "New records created successfully"; } mysqli_close($conn); ?>
  17. ​so change this to echo $query="INSERT INTO earlyreg (name, card1, card2, card3, date) VALUES ('playernick', '" . $checkBox . "', CURRENT_DATE())"; to this echo $query="INSERT INTO earlyreg (name, card1, card2, card3, date) VALUES ('playernick', ' . $checkBox . ', CURRENT_DATE())"; and where should I look to replace the if(isset($_POST['submit']))
  18. ok updated code as suggested about the insert query syntax echo $query="INSERT INTO earlyreg (name, card1, card2, card3, date) VALUES ('playernick', '" . $checkBox . "', CURRENT_DATE())"; Now when I run it and fill out the form I get INSERT INTO earlyreg (name, card1, card2, card3, date) VALUES ('playernick', '5,6,7', CURRENT_DATE())Column count doesn't match value count at row 1 even though I have 5 columns now and showing all 5 in the echo I am still getting Column count doesn't match value count at row 1 the reason I am using the 3 cards into one row is that I am trying to keep it as simple for the people that need to see it and change things so they arent having to look in the tables for 3 different entries for one player. as for the name column its just the title of the column it is actually getting the player nickname from the form
  19. yes only the checked boxes submit data there are 40 checkboxes users can only select a maximum of 3
  20. i used a code snippet to get the checkbox numbers into the db but im not sure if its pasting it right as now i get a error Column count doesn't match value count at row 1 to be more precise I have a form where they enter player name select 3 images that are named with just numbers and the current date I also moved the column for random which is something I will be implementing at a later date with random picks of images `Name` VARCHAR(16) `Card1` INT(2) `Card2` INT(2) `Card3` INT(2) `Date` DATE NOT NULL, `Random` TINYTEXT card 1 card 2 and card 3 are 3 card numbers that are used from the selection any help will be appreciated
  21. Ok i have a code that is supposed to put the checkbox number into a data base the table is set up as playernick card1 card 2 card 3 random(to be used later so null in this application) and the date but when i fill out the form i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_DATE()')' at line 1 here is the php code from below where it connects to database $checkBox = implode(',', $_POST['whatcard']); if(isset($_POST['submit'])) { $query="INSERT INTO earlyreg VALUES (playernick,'" . $checkBox . "',.,CURRENT_DATE()')"; mysql_query($query) or die (mysql_error() ); echo "Complete"; } ?>
  22. thhe iossue is that i have specific totals each points is a new entry the query that gives that list is an addition of all same entries between 2 dates why i was hoping to do it so that it wouuld just search the current list i have to give ypou a better idea of what i mean here is my php coding <?php $db = mysql_connect("localhost", "happyga1_points","Smkn4life"); mysql_select_db("happyga1_points",$db); $i = 0; $d = date("2014-10-01"); //$d = preg_replace("/-(\d+) /", "-01 ", $d); // echo("Extracting data since $d<br/>"); $r = mysql_query("select playername, sum(Points) as total from points where timestamp > '$d' Group by playername order by total DESC") or trigger_error(mysql_error()); while ($v = mysql_fetch_assoc($r)) { ++$i; echo("<tr><td>$i</td><td>${v["playername"]}</td><td>${v["total"]}</td></tr>\n"); } ?>
  23. Ok i have seen many solutions for using a search function to post onto webpage directly from the mysql db but my question is is there a way to seach the results that were already outputted via a php query, for instance i have a query that returns 1 MisFit_Kay1 811 2 sajoma 806 3 Atlfan 708 4 karlsbad70 633 5 Booo 570 6 MisFit_Mimi_shg 541 7 PRO_Viking 540 8 tm7_cryzal 540 9 TM7__mina 499 10 PRO_DRFRANK 488 11 PRO_FLAK 488 12 Mhoram 464 13 TM7__CEDAR 462 14 ProSultan 456 15 UBG_Steely1 450 but with lots more results now what im hoping for is a point in a direction where i could add a search box that will highlight the name from the list provided . any help will be appreciated
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.