Jump to content

MajorVictory

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

About MajorVictory

  • Birthday 11/08/1987

Contact Methods

  • AIM
    remixretsam
  • Website URL
    http://anythinggaming.com
  • Yahoo
    motor_man_876

Profile Information

  • Gender
    Male
  • Location
    Illinois, America

MajorVictory's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. :EDIT: I fixed that last one now can anyone tell me why this function:[code]function DBCreateTable_Static() { GLOBAL $INFO; if (!$INFO['cid']) { echo("<hr>ERROR: " . mysql_error() . "<hr>"); DBClose(); } else { $SQL = "CREATE TABLE nerdcavedata ( unique_id AUTO_INCREMENT NOT NULL, itemname VARCHAR(40) NULL, itemlink VARCHAR(100) NULL, datestamp VARCHAR(50) NULL );"; $result = mysql_db_query($INFO['dbName'], "$SQL" ,$INFO['cid']); if (!$result) { echo("<hr>ERROR: " . mysql_error() . "<hr><br>$SQL<br><hr>"); DBClose(); } } }[/code] produces this error:[quote]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 'AUTO_INCREMENT NOT NULL, itemname VARCHAR(40) NULL, ite[/quote] while using this SQL statement:[quote]CREATE TABLE nerdcavedata ( unique_id AUTO_INCREMENT NOT NULL, itemname VARCHAR(40) NULL, itemlink VARCHAR(100) NULL, datestamp VARCHAR(50) NULL );[/quote] Please help me as i've followed the manual to the letter, even copying and pasting but it will not work. I am connected to the database and i do have access to all the commands.
  2. ok i found those closing brace errors you mentioned and I added the globals in. I also replaced the code in my first post with the new code. now i have a question though, for my DBGetData() function i'm using[code]$SQL = " SELECT * FROM '$tablename "; $SQL = $SQL . " WHERE category = '$category' ";[/code] i want to be able to specify the tablename and category and then have it return everything in that category. The rest of the function seem like it would work bu i havn't tested it yet. i just wann know if it shouldn't be[code]$SQL = " SELECT * FROM '$tablename "; $SQL = $SQL . " WHERE '$category'  = somethingelse ";[/code] I'm not sure but i think the first code specifies a category called "category" and not the one i'm defining when i call my function.
  3. alright thanks, just wanted to make sure before i poated. Here are my functions, just tell me if you think thay'll work and what you would recommend. [code]$INFO = array( //Admin Settings "admin_username" => "adminname", "admin_password" => "adminpass", //mySQL Settings "dbHost" => "host", "dbName" => "name", "dbUser" => "dbname", "dbPass" => "pass", "cid" => "", "retid" => "", //Application Url(Use Trailing Slash) "app_url" => "href", ); function DBConnect($a_user,$a_pass) { global $INFO if ($a_user != $INFO['admin_username'] | $a_pass != $INFO['admin_password']) { include_once('./xtemplate.class.php'); $xtpl = new XTemplate('templates/confirmation.xtpl'); $xtpl -> assign('MESSAGE', "The Username or Password is incorrect!"); $xtpl -> assign('PAGETITLE', "Error"); $headerfile = "None"; //Full, Nav, Main, or None include_once('./headerfooter.php'); $xtpl -> rparse('main.inc'); $xtpl -> rparse('main.goback'); $xtpl -> parse('main'); $xtpl -> out('main'); die(""); } else { $usr = $INFO['dbUser']; $pwd = $INFO['dbPass']; $host = $INFO['dbHost']; $INFO['cid'] = mysql_connect($host,$usr,$pwd); } } function DBAddData($tablename = '', $category = '', $data) { global $INFO if (!$INFO['cid']) { echo("ERROR: " . mysql_error() . "\n"); } else { $SQL = " INSERT INTO '$tablename' "; $SQL = $SQL . " ('$category') VALUES "; $SQL = $SQL . " ('$data') "; $result = mysql_db_query($INFO['dbName'],"$SQL",$INFO['cid']); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } } } function DBGetData ($tablename = '', $category = '') { global $INFO $SQL = " SELECT * FROM '$tablename "; $SQL = $SQL . " WHERE category = '$category' "; $INFO['retid'] = mysql_db_query($INFO['dbName'], $SQL, $INFO['cid']); if (!$INFO['retid']) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } $row = mysql_fetch_array($INFO['retid']); while ($row = mysql_fetch_array($INFO['retid'])) { $returndata = $row["$data"]; } return $returndata } function DBUpdateData ($tablename = '', $category = '', $data) { global $INFO if (!$INFO['cid']) { echo("ERROR: " . mysql_error() . "\n"); } else { $SQL = " UPDATE '$tablename' SET";     $SQL = $SQL . " WHERE '$category' = $data ";     $result = mysql_db_query($db,"$SQL",$cid); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } } } function DBClose() { global $INFO mysql_close($INFO['cid']); }[/code] let me know what you think, -Major
  4. Hello everyone, over the last week or two i've been teaching myself php and updating myself on html. I've gotten to the point where i need to use MySQL to store data and retrieve it later. So far I understand most of the commands and syntax but there's still areas i need to explore. Over the last two days i've been learning MySQL and trying to make my own set of functions to access the DB easily and without a lot of code in my other scripts. right now the functions i have include connecting to the DB, getting data, setting data, and updating data. Now I havn't tried to test my code because i want to finish the functions as much as possible before i need to test. I know it can be a tough way to code but it's how I learn best. What I want from this community is a little help in making sure my functions are coded correctly. I also want to ask if it is ok if i post these functions here. I want to post the functions i do have done here and have you guys evaluate them and tell me if i'm on the right track and if not, how far off-base I am. For now i won't post any code until i get approval to do so as I know some forums disapprove of large text chunks. Thanks, -Major
×
×
  • 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.