Jump to content

Cannibal_Monkey

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by Cannibal_Monkey

  1. Could somone write a sample code that would retrieve a from row 1 of table b in database c. So far I have <?php $connection=mysql_connect("localhost","root","") or die ("You're dead1"); $db=mysql_select_db("c",$connection) or die ("You're dead2"); $query=mysql_query($a); ?> I'm not sure if that's all correct though, I mean to do what I want to do.
  2. Wait, I'm a little confused. I just want to print the database itself with fields and boxes and stuff.
  3. Okay I want to retrieve data from Database OPO and from Table B. How do I do that exactly? This is the code we have. [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <?php $connection=mysql_connect("localhost","root","") or die ("message"); $db=mysql_select_db("opo",$connection) or die ("message2"); $a = "SELECT * FROM b" ?> <body> </body> </html> [/code]
  4. We are having a problem with our program we have. The program is at the bottom of the post. Anyway, we are trying to create a table with this code: [code] CREATE TABLE a { 1 VARCHAR(3), 2 VARCHAR(3), 3 VARCHAR(3), 4 VARCHAR(3), 5 VARCHAR(3), PRIMARY KEY(1) }[/code] And we are getting this error: [quote]Error 1064: 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 '{ 1 VARCHAR(3), 2 VARCHAR(3), 3 VARCHAR(3), 4 VARCHAR(3), 5 VARCHAR(3), PR' at line 1[/quote] We can't figure out what the problem is. The code we are using for the program is here. Sorry for the slopiness. [code]<html> <head><title>SQL Query Sender</title></head> <body> <?php $host="localhost"; $user="root"; $password=""; /* Section that executes query */ if(@$_GET['form'] == "yes") { mysql_connect($host,$user,$password); mysql_select_db($_POST['database']); $query = stripSlashes($_POST['query']); $result = mysql_query($query); echo "Database Selected: <b>{$_POST['database']}</b><br> Query: <b>$query</b><h3>Results</h3><hr>"; if($result == 0) echo "<b>Error ".mysql_errno().": ".mysql_error(). "</b>"; elseif (@mysql_num_rows($result) == 0) echo("<b>Query completed. No results returned. </b><br>"); else { echo "<table border='1'> <thead> <tr>"; for($i = 0;$i < mysql_num_fields($result);$i++) { echo "<th>".mysql_field_name($result,$i). "</th>"; } echo " </tr> </thead> <tbody>"; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row = mysql_fetch_row($result); for($j = 0;$j<mysql_num_fields($result);$j++) { echo("<td>" . $row[$j] . "</td>"); } echo "</tr>"; } echo "</tbody> </table>"; } //end else echo " <hr><br> <form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\"> <input type='hidden' name='query' value='$query'> <input type='hidden' name='database' value={$_POST['database']}> <input type='submit' name=\"queryButton\" value=\"New Query\"> <input type='submit' name=\"queryButton\" value=\"Edit Query\"> </form>"; unset($form); exit(); } // endif form=yes @$query=stripSlashes($_POST['query']); if (@$_POST['queryButton'] != "Edit Query") { $query = " "; } ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> <table> <tr> <td align=right><b>Type in database name</b></td> <td><input type="text" name="database" value=<?php echo @$_POST['database'] ?> ></td> </tr> <tr> <td align="right" valign="top"> <b>Type in SQL query</b></td> <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Query"></td> </tr> </table> </form> </body></html> [/code]
  5. Ah, thanks :) It was from a book which I converted to .txt, and the quotes were wierd like that. Thanks :)
  6. There's a problem with a semicolon in our code on line 18 and we can't find out where it is supposed to be. We coppied the code from a book, and they don't have one. Please help us. Thanks :) [code]<!-- Program: mysql_send.php Desc: PHP program that sends an SQL query to the MySQL server and displays the results. --> <html> <head><title>SQL Query Sender</title></head> <body> <?php $host=”localhost”; $user=”root“; $password=””; /* Section that executes query */ if(@$_GET[‘form’] == “yes”) { mysql_connect($host,$user,$password); mysql_select_db($_POST[‘database’]); $query = stripSlashes($_POST[‘query’]); $result = mysql_query($query); echo “Database Selected: <b>{$_POST[‘database’]}</b><br> Query: <b>$query</b><h3>Results</h3><hr>”; if($result == 0) echo “<b>Error “.mysql_errno().”: “.mysql_error(). “</b>”; elseif (@mysql_num_rows($result) == 0) echo(“<b>Query completed. No results returned. </b><br>”); else { echo “<table border=’1’> <thead> <tr>”; for($i = 0;$i < mysql_num_fields($result);$i++) { echo “<th>”.mysql_field_name($result,$i). “</th>”; } echo “ </tr> </thead> <tbody>”; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo “<tr>”; $row = mysql_fetch_row($result); for($j = 0;$j<mysql_num_fields($result);$j++) { echo(“<td>” . $row[$j] . “</td>”); } echo “</tr>”; } echo “</tbody> </table>”; } //end else echo “ <hr><br> <form action=\”{$_SERVER[‘PHP_SELF’]}\” method=\”POST\”> <input type=’hidden’ name=’query’ value=’$query’> <input type=’hidden’ name=’database’ value={$_POST[‘database’]}> <input type=’submit’ name=\”queryButton\” value=\”New Query\”> <input type=’submit’ name=\”queryButton\” value=\”Edit Query\”> </form>”; unset($form); exit(); } // endif form=yes @$query=stripSlashes($_POST[‘query’]); if (@$_POST[‘queryButton’] != “Edit Query”) { $query = “ “; } ?> <form action=”<?php echo $_SERVER[‘PHP_SELF’] ?>?form=yes” method=”POST”> <table> <tr> <td align=right><b>Type in database name</b></td> <td><input type=”text” name=”database” value=<?php echo @$_POST[‘database’] ?> ></td> </tr> <tr> <td align=”right” valign=”top”> <b>Type in SQL query</b></td> <td><textarea name=”query” cols=”60” rows=”10”><?php echo $query ?></textarea> </td> </tr> <tr> <td colspan=”2” align=”center”><input type=”submit” value=”Submit Query”></td> </tr> </table> </form> </body></html> [/code]
  7. No it hadn't said anything about that. I guess they forgot that part? Thanks :)
  8. The c$ is supposed to be plugged into something to determine if a string ends in c. I don't know what to plug it into.
  9. Okay, I was reading a PHP book and I am up to Matching Strings to Patterns, and I have things, like C$ which is supposed to check if the last letter in a string is a C. So how do I use this? I tried putting it in the if () thing but that didn't work. So where do I put it?
  10. I've looked around and simply can't find the error. I've tried all combos of else, if, and or for the 2nd part of the code, with and without that stuff after it I can think of, and none of it works (though from what I've seen, what I have there currently should work). The error I get is "Parse error: parse error, unexpected T_LOGICAL_OR in H:\Program Files (x86)\xampp\htdocs\learn.php on line 15" Here's my code: [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <?php $b = 1; $c = 1; if ($b == $c) { $a = "They are equal"; echo $a; }; or else if ($b !=, <> $c) { $a = "They are not equal"; echo $a } ?> <body> </body> </html> [/code]
  11. I have a row C of several numbers. I want to add all the numbers of that row and create a new variable. I have this for that line of code "$e = mysql_query('SELECT SUM `c` FROM `b`');" If it's wrong what do I do? I've searched around and couldn't find the answer.
  12. I figured it out a few min ago (sorry for not saying). I think you got the last 3 parts switched around. Thanks for helping me get the script actually working (I spend a lot of time on it before I even came here. I know its some simple script but it's the first code I've made of any coding language) Anyway I have edited the code a little so now it's this: [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <? $dbhost = 'localhost'; $dbusername = 'root'; $dbpasswd = ''; $database_name = 'a'; $connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database_name", $connection) or die("Couldn't select database."); ?> <?php if (isset($_POST['update'])) {     mysql_connect('localhost', 'root', ''); mysql_select_db('a') or die(mysql_error());      mysql_query('CREATE TABLE IF NOT EXISTS `b` (         `d` INT NOT NULL AUTO_INCREMENT ,         `c` INT NOT NULL ,         PRIMARY KEY ( `d` )         ) TYPE = innodb;') or die(mysql_error());     mysql_query('INSERT INTO `b`(`c`, `d`)         VALUES (' . mt_rand(1, 3) . ', 0)         ON DUPLICATE KEY UPDATE `c` = `d` + ' . mt_rand(1,3)) or die(mysql_error());     $q = mysql_query('SELECT `c`         FROM `b`         WHERE `c` = 0         LIMIT 99999') or die(mysql_error());     $r = mysql_fetch_assoc($q);     print_r($r); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Berry Gatherer</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="update" type="submit" value="Gather Berries" /> </form> </body> </html>[/code] In the database it creates new D and C files each time you hit the button. That's what I want but I want it to add up all the Cs and desplay it on the page as variable E, and the last variable C in a different part of the code. I'm not sure how to go about creating variable E or how to desplay it. I tried a few things involving $c=mysql_query($query); for desplaying c. Am I even close with that?
  13. What do I put in place of integeral? I got this error when I tried to run the code before clicking the button with test on it. " Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'intergal'@'localhost' (using password: YES) in H:\Program Files (x86)\xampp\htdocs\Test.php on line 8 Couldn't connect to server." I shouldn't have a username or password I don't think.
  14. [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php if (isset($_POST['update'])) { mysql_query("CREATE DATABASE `a`") OR DIE ('Could not execute query: ' . mysql_error());     mysql_connect('localhost', 'root', ''); mysql_select_db('a') or die(mysql_error());      mysql_query('CREATE TABLE IF NOT EXISTS `b` (         `d` INT NOT NULL AUTO_INCREMENT ,         `c` INT NOT NULL ,         PRIMARY KEY ( `d` )         ) TYPE = innodb;') or die(mysql_error());     mysql_query('INSERT INTO `b`(`c`, `d`)         VALUES (' . mt_rand(1, 10) . ', 1)         ON DUPLICATE KEY UPDATE `c` = `c` + ' . mt_rand(1,10)) or die(mysql_error());     $q = mysql_query('SELECT `c`         FROM `b`         WHERE `d` = 1         LIMIT 1') or die(mysql_error());     $r = mysql_fetch_assoc($q);     print_r($r); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>This is my basic page!</title> Hello, if you got to this, you are hacking my computer. Please exit in a timely fashion otherwise I will be forced to <b>eat</b> your family. And I'll do it too. Don't believe me? Stay here then, when you get up to go to get something to eat, you'll see me cooking up your sister. </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="update" type="submit" value="Test" /> </form> </body> </html>[/code] (I just removed the semicolon)
  15. [quote author=sanfly link=topic=109633.msg442164#msg442164 date=1159328178] You need to put your database connection info in before the code you were given ie [code=php:0]<?php // YOUR DATABASE CONNECTION DATA HERE mysql_query("CREATE DATABASE `a`") OR DIE ('Could not execute query: ' . mysql_error()); ?>[/code] [/quote] That leaves me with exactly the same problem as described below... [quote author=Cannibal_Monkey link=topic=109633.msg442162#msg442162 date=1159328071] When I add that code I get errors " Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in H:\Program Files (x86)\xampp\htdocs\Test.php on line 4 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in H:\Program Files (x86)\xampp\htdocs\Test.php on line 4 Could not execute query: Access denied for user 'ODBC'@'localhost' (using password: NO)" I don't know why it's logging me in as ODBC though, I say root in the code, not ODBC. And when I create the database manually, 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 '; VALUES (2, 1) ON DUPLICATE KEY UPDATE `c` = `c` + 2' at line 1" Now I am assuming the 2 is the random number because when I did it before, I got 4 in place of both 2s there. Now I am assuming the problem is C can't equal C+2 (because we learned that in Pre-Algebra) But I'm not sure what exactly to do to fix that. What do I do? I want C to be replaced by the orginal value of C + a random number between 1 and 10 (in this case 2) [/quote]
  16. When I add that code I get errors " Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in H:\Program Files (x86)\xampp\htdocs\Test.php on line 4 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in H:\Program Files (x86)\xampp\htdocs\Test.php on line 4 Could not execute query: Access denied for user 'ODBC'@'localhost' (using password: NO)" I don't know why it's logging me in as ODBC though, I say root in the code, not ODBC. And when I create the database manually, 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 '; VALUES (2, 1) ON DUPLICATE KEY UPDATE `c` = `c` + 2' at line 1" Now I am assuming the 2 is the random number because when I did it before, I got 4 in place of both 2s there. Now I am assuming the problem is C can't equal C+2 (because we learned that in Pre-Algebra) But I'm not sure what exactly to do to fix that. What do I do? I want C to be replaced by the orginal value of C + a random number between 1 and 10 (in this case 2)
  17. I was under the impression that this would create database a, how do I create it then?
  18. I searched around, but I havn't found the answer. Basically there is a problem with my code, and I've had help but all the help has done was switch things from 1 problem to another. With this script below I have "Unknown database 'a'" as my problem. Basically the script is supposed to add a random number from 1 to 10 into a database (I am new to coding). Here is the script below: [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php if (isset($_POST['update'])) {     mysql_connect('localhost', 'root', ''); mysql_select_db('a') or die(mysql_error());      mysql_query('CREATE TABLE IF NOT EXISTS `b` (         `d` INT NOT NULL AUTO_INCREMENT ,         `c` INT NOT NULL ,         PRIMARY KEY ( `d` )         ) TYPE = innodb;') or die(mysql_error());     mysql_query('INSERT INTO `b`(`c`, `d`) ;         VALUES (' . mt_rand(1, 10) . ', 1)         ON DUPLICATE KEY UPDATE `c` = `c` + ' . mt_rand(1,10)) or die(mysql_error());     $q = mysql_query('SELECT `c`         FROM `b`         WHERE `d` = 1         LIMIT 1') or die(mysql_error());     $r = mysql_fetch_assoc($q);     print_r($r); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>This is my basic page!</title> Hello, if you got to this, you are hacking my computer. Please exit in a timely fashion otherwise I will be forced to <b>eat</b> your family. And I'll do it too. Don't believe me? Stay here then, when you get up to go to get something to eat, you'll see me cooking up your sister. </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="update" type="submit" value="Test" /> </form> </body> </html>[/code]
×
×
  • 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.