Jump to content

Cannibal_Monkey

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Cannibal_Monkey's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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?
×
×
  • 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.