Jump to content

attaboy

Members
  • Posts

    72
  • Joined

  • Last visited

Everything posted by attaboy

  1. for anyone reading the last example is the best but he had 2 typos it should be mysql_errno() !== 1062
  2. I think I like this last one best. So many people really know there s#$t here, I love this place!
  3. I have a field in a table named flights I hope to find a 1 line statement to bypass inserting a new row if $flight_no is already in the field flight_no btw flight_no is the primary key and won't allow a duplicate anyway but I want to avoid the error message this is what I tried but doesn't work if(SELECT * FROM flights WHERE flight_no !LIKE %$flight_no%) {
  4. Yippie Skippi!! that did it!! I thought somehow that since the values were in variables that they didn't need to be enclosed in quotes...but I was wrong. Thank you so much
  5. I created this database <?php $mysqli = mysqli_connect('localhost', 'admin', 'jce123', 'php_class'); if(mysqli_connect_errno()) { printf("connection failed: %s\n", mysqli_connect_error()); exit(); }else{ $q = mysqli_query($mysqli, "DROP TABLE IF EXISTS airline_survey"); if($q){echo "deleted the table airline_survey....<br>";} else{echo "damm... ".mysqli_error($mysqli);} $sql = "CREATE TABLE airline_survey ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, staff CHAR(10) NOT NULL, luggage CHAR(10) NOT NULL, seating CHAR(10) NOT NULL, clean CHAR(10) NOT NULL, noise CHAR(10) NOT NULL )"; $res = mysqli_query($mysqli, $sql); if($res === TRUE) { echo "table created"; } else { printf("Could not create table: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> When I look at it it looks fine. I have a form that sends data to this script: <?php $con = mysql_connect('localhost', 'admin', 'abc123'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("php_class", $con); foreach ($_POST as $key => $value) { $staff = ""; $luggage = ""; $seating = ""; $clean = ""; $noise = ""; switch($key){ case "staff": $staff = $value; break; case "luggage": $luggage = $value; break; case "seating": $seating = $value; break; case "clean": $clean = $value; break; case "noise": $noise = $value; break; default: echo "we must be in the twilight zone"; } echo $staff."<br>"; [color=red] mysql_query("INSERT INTO airline_survey (staff, luggage, seating, clean, noise) VALUES ($staff, $luggage, $seating, $clean, $noise)");[/color] } ?> as you can see right before the insert query I test one of the variables to see if it has the string I'm expecting and it does. The problem is the script runs without giving me an error message but the data never gets inserted into the table.
  6. Thanks!!! I didn't know what a back tick was till now.
  7. $q = mysqli_query($mysqli, "DROP TABLE IF EXIST 'airline_survey'"); if($q){echo "deleted the table airline_survey....<br>";} else{echo "damm... ".mysqli_error($mysqli);} $mysqli is my connection and it works I had no trouble creating the table but I decided to add these few lines in front of the code to create the table and I get this error. damm...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 'EXIST 'airline_survey'' at line 1 I gotta believe this is really simple but it's got me stumped.
  8. I have a table called inventory mysql> SELECT * FROM inventory; +------------+--------------------+--------+-----+ | make | model | price | mpg | +------------+--------------------+--------+-----+ | Ford | Model T | 22500 | 17 | | Studebaker | Hawk | 17500 | 20 | | Volkswagen | Bug | 19900 | 25 | | Ace | Continental | 33900 | 12 | | Lincoln | Continental | 33900 | 10 | | Ford | Model A | 33995 | 18 | | Packard | Series 1604 | 112700 | 15 | | AMC | AMX | 26995 | 21 | | Nash | Airflyte Statesman | 1500 | 13 | | Lincoln | Zephyr | 1800 | 12 | +------------+--------------------+--------+-----+ I need to order by make and model. I tried this: mysql> SELECT make, model, price -> FROM inventory -> WHERE make IN -> ( -> SELECT make -> FROM inventory -> ORDER BY model -> ) -> ORDER BY make; and this was the result, it's ordered by make but I need it to be ordered model under make so that Ford Model A comes before Ford Model T +------------+--------------------+--------+ | make | model | price | +------------+--------------------+--------+ | Ace | Continental | 33900 | | AMC | AMX | 26995 | | Ford | Model T | 22500 | | Ford | Model A | 33995 | | Lincoln | Continental | 33900 | | Lincoln | Zephyr | 1800 | | Nash | Airflyte Statesman | 1500 | | Packard | Series 1604 | 112700 | | Studebaker | Hawk | 17500 | | Volkswagen | Bug | 19900 | +------------+--------------------+--------+
  9. never mind I found a solution ; | +-------------------------------------------------------------------------------------------------------------- ------------------+ 1 row in set (0.00 sec) mysql> SELECT * -> FROM countries -> WHERE primary_language IN -> ( -> SELECT primary_language FROM countries -> GROUP BY primary_language -> HAVING COUNT(primary_language) > 1 -> ) -> ORDER BY primary_language; +-----------+------------------+------------+ | name | primary_language | population | +-----------+------------------+------------+ | Austrilia | English | 22851000 | | Canada | English | 34730000 | +-----------+------------------+------------+ 2 rows in set (0.00 sec)
  10. I have a table called countries with 3 columns name, language, and population. I need to find a query that list groups of countries that have the same language so if I have 10 countries and 3 of them speak English, 2 speak German and the other countries speak unique languages my output would list the English and German speaking countries. I have to do this with a mysql query only no php.
  11. It seems wamp runs this as a service so it can't be reached from the command line. It's not that important all I'm doing is taking a class and I can do all I need as root.
  12. 'Then try to login,' that's a problem when I bring up the MySql console it doesn't ask me for a user name, the user is already root and it just wants my password. From what I gather there is no login command so is there a ini file I should change?
  13. mysql> show grants for Jim; +------------------------------------------------------------------------------- ------------------------------------------------+ | Grants for Jim@% | +------------------------------------------------------------------------------- ------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'Jim'@'%' IDENTIFIED BY PASSWORD '*D84E02E1F52C 3CFB308DB32A53E53DAB7AE48348' WITH GRANT OPTION | +------------------------------------------------------------------------------- ------------------------------------------------+ 1 row in set (0.01 sec) mysql>
  14. I'm using Wampserver 2.2 when I click on the link for mySql console it comes up under root. I created a user but I don't see any way to log in as that user. I also try using phpmyadmin there I can logout and I'm presented with a login box if I enter the credentials of the new user it just presents the box over again and won't let me back in till I enter root.
  15. After reading your post I spent a few minutes looking and seems you have to use javascript for that maybe with a settimeout() function. I don't know enough about either javascript or php to be much help....good luck.
  16. When I hit the submit button I would like the answer to appear in the box labled answer. Is that possible? <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> input {position:absolute; left:120px;} p {margin-bottom:-10px;} </style> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p>first number:<input type="text" name="first_number" /></p> <p>second number:<input type="text" name="second_number" /></p> <p>answer:<input type="text" name="answer" /></p> <ul> <li>add: <input type="radio" name="group1" value="add" /></li> <li>subtract: <input type="radio" name="group1" value="subtract" /></li> <li>multiply: <input type="radio" name="group1" value="multiply" /></li> <li>divide: <input type="radio" name="group1" value="divide" /></li> </ul> <p><input type="submit" value="submit" /></p> </form> <?php $answer = $_POST['group1']; $first = $_POST['first_number']; $second = $_POST['second_number']; $ans=0; if ($answer == "add") { $ans = $first + $second; echo $ans; } else if ($answer == "subtract"){ $ans = $first - $second; echo $ans; } else if ($answer == "multiply"){ $ans = $first * $second; echo $ans; } else if ($answer == "divide"){ $ans = $first / $second; echo $ans; } else { echo 'damm...'; } ?> </body> </html>
  17. Thank you so much!!! I thought I tried that, obviously I did something wrong but now it works as intended.
  18. I'm trying to create a multidimensional array of movies organized by genre. This should take the form of an associative array with genres as keys. Each of the arrays elements should be an array containing movie names. This is what I have: <?php $movies = array( array("SF" => "", "Terminator", "Soylent Green", "I Robot", "frankenstein"), array("horror" => "exorcist", "IT", "frankenstein"), array("comedy" => "holy grail", "blazing saddles", "young frankenstein") ); //echo $movies[0][0]."<br>"; //echo $movies[1][0]."<br>"; //echo $movies[2][0]; foreach ($movies as $c) { while (list($k, $v) = each ($c)) { echo "$k ... $v <br/>"; } } ?> this is the output: SF ... 0 ... Terminator 1 ... Soylent Green 2 ... I Robot 3 ... frankenstein horror ... exorcist 0 ... IT 1 ... frankenstein comedy ... holy grail 0 ... blazing saddles 1 ... young frankenstein you'll see Terminator is only listed as element 0 because there's an empty string in front of it. The first item in the array is liated as the value to the key while the second value is listed as element 0. It doesn't seem right to me.
  19. I fixed it. 1. Opened wordpad as administrator 2. opened windows\system32\drivers\etc\hosts 3. edited it so the only entry is 127.0.0.1 localhost 4. saved
  20. I can access mysql console ok but not phpmyadmin, sqlbuddy, or webgrind Forbidden You don't have permission to access /webgrind/ on this server.
×
×
  • 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.