PHP - Importing Csv Into Mysql Error
Am trying to import a csv file into mysql. below is the code am using.
<?php
//connect to the database include('mysql_connect.php');//select the table // if ($_FILES[csv][size] > 0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); //loop through the csv file and insert into database do { if ($data[0]) { mysql_query("INSERT INTO requisition (department, contact_last, contact_email) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."' ) "); } } while ($data = fgetcsv($handle,1000,",","'")); // //redirect header('Location: import.php?success=1'); die; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> ........................................................................................................................................... On page load, it gives some erros Notice: Use of undefined constant csv - assumed 'csv' in C:\wamp\www\orango\upload_data.php on line 7 Notice: Use of undefined constant size - assumed 'size' in C:\wamp\www\orango\upload_data.php on line 7 Notice: Undefined index: csv in C:\wamp\www\orango\upload_data.php on line 7 Notice: Use of undefined constant success - assumed 'success' in C:\wamp\www\orango\upload_data.php on line 43 I try to ignore the errors to see if it would work but it didn't save in the DB. please help me out Similar Tutorialsdoes anyone know who to resolve this issue of importing a CSV file from excel into sql? I get this error when I do. LOAD DATA LOCAL INFILE '/tmp/phpq2aAbU' INTO TABLE `Events` FIELDS TERMINATED BY ',' ENCLOSED BY '\\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\r\n' Hello,
I am trying to import a CSV file into an existing mysql table but it doesn't seem to work well.
Here is how my mysql is looking like:
1 a_id int(11) AUTO_INCREMENT 2 a_lobecoid int(7) 3 a_code varchar(30) utf8_general_ci 4 a_omschint varchar(60) utf8_general_ci 5 a_beveiligingniv int(5) 6 a_type varchar(5) utf8_general_ci 7 a_assortiment int(5) 8 a_discipline varchar(30) utf8_general_ci 9 a_brutoprijs varchar(50) utf8_general_ci 10 a_status varchar(5) utf8_general_ci 11 a_levcode varchar(10) utf8_general_ci 12 a_omschr_nl varchar(60) utf8_general_ci 13 a_omschr_fr varchar(60) utf8_general_cithese are some lines from my CSV file 16158|-H|Factory installed heater|10|S|400|CCTV|45.0|E| 1829|Factory installed heater|Factory installed heater 16159|-IR|Factory installed IR LED ring|10|S|400|CCTV|50.0|E| 1829|Factory installed IR LED ring|Factory installed IR LED ring 9001|00-SBN2|Smoke box niet geaspireerd,230VAC|10|S|267|BRAND|1587.03|D| 642|Smoke box niet geaspireerd,230VAC|Smoke box pas aspiré,230VCA 9003|00-TP1|Telescopische verlengstok voor Smoke box,2,4-4,6m|10|S|267|BRAND|644.09000000000003|D| 642|Telescopische verlengstok voor Smoke box,2,4-4,6m|Rallonge téléscopique pour Smoke box,2,4-4,6m 9004|00-TP2|Telescopische verlengstok voor Smoke box,2,4-9,2m|10|S|267|BRAND|944.64999999999998|D| 642|Telescopische verlengstok voor Smoke box,2,4-9,2m|Rallonge téléscopique pour Smoke box,2,4-9,2m 12161|001-0081|Thermistor probe,rood, high temp. 0-+150°C|10|S|52|INBRAAK|136.91|D| 1731|Thermistor probe,rood, high temp. 0-+150°C|Sonde température,rouge,high temp. 0-+150°CHere you have the code for the import: $upload_article_query = "LOAD DATA INFILE 'ARTIKELS.CSV' INTO TABLE artikelen FIELDS TERMINATED BY '|' LINES TERMINATED BY '\\r\\n' (a_lobecoid, a_code, a_omschint, a_beveiligingniv, a_type, a_assortiment, a_discipline, a_brutoprijs, a_status, a_levcode, a_omschr_nl, a_omschr_fr)"; $upload_article_stmt = $dbh->prepare($upload_article_query); $upload_article_stmt->execute();If i use the code then in the MYSQL table the first line is filled in but where the second line has to start it just writes it into the last column and doesn't start a new line. Also if i edit that first line it shows a lot of "?" (questionmarks) into a window symbol. Anyone has an idea what i am doing wrong? In attachment some printscreens of my table after the insert. Apologies for the Dutch language. Thanks in advance Attached Files pic1.jpg 6.13KB 0 downloads pic2.jpg 37.9KB 0 downloads Hey guys! So I have this script to import a CSV file into my database:
<?php $databasehost = "localhost"; $databasename = "import"; $databasetable = "import"; $databaseusername="username"; $databasepassword = "password"; $fieldseparator = ","; $lineseparator = "\n"; $csvfile = "test.csv"; if(!file_exists($csvfile)) { die("File not found. Make sure you specified the correct path."); } try { $pdo = new PDO("mysql:host=$databasehost;dbname=$databasename", $databaseusername, $databasepassword, array( PDO::MYSQL_ATTR_LOCAL_INFILE => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); } catch (PDOException $e) { die("database connection failed: ".$e->getMessage()); } $pdo->exec("TRUNCATE TABLE `$databasetable`"); $affectedRows = $pdo->exec(" LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." REPLACE INTO TABLE `$databasetable` FIELDS TERMINATED BY ".$pdo->quote($fieldseparator)." LINES TERMINATED BY ".$pdo->quote($lineseparator)." IGNORE 1 LINES"); echo "Loaded a total of $affectedRows records from this csv file.\n"; ?>So that script basically imports a csv replacing all of the other data. The issue I am having is that the data inside one of the columns contains commas, they are wrapped in quotations. Here is an example: ,"1 Registered Keeper, Full Service History, Central Locking, Electric Windows, Electric Mirrors, ABS, Traction Control, Climate Control, Power Steering, Drivers Airbag, Passenger Airbag, Side Airbags, Cruise Control, Alarm, Immobiliser, Half Leather Interior, Alloy Wheels", How could I make the script determine the text within those quotation marks as a whole value instead of separating them into individual columns? Thanks any help on this would be great! Hi everyone, I am currently making a page for a friend to upload a bunch of photos at a time. I was quite pleased that after a bit of googling and trial and error, I figured out how to do this so that multiple records could be added to my table with one submit button. However, my form has 10 browse iconcs. A few tests have revealed that my problem is that if only one picture is uploaded, I still get 9 entries in my database, which I don't want. My question is how can I alter the code so that a row is only populated in the database if an image is uploaded. I guess something that sort of says : if($imgx!="") { populate that row in the table } else { don't } ...and the same for $imgx002 through to $imgx010 The current query is below. Any pointers are much appreciated. Code: [Select] $query = "INSERT INTO photo_uploads (date, photo_name)" . "VALUES (NOW(), '$imgx'), (NOW(), '$imgx002'), (NOW(), '$imgx003'), (NOW(), '$imgx004'), (NOW(), '$imgx005'), (NOW(), '$imgx006'), (NOW(), '$imgx007'), (NOW(), '$imgx008'), (NOW(), '$imgx009'), (NOW(), '$imgx010')"; Hi all,
I'm working on a project involving an orders set of APIs, and having trouble coming up with the best logic to handle this - with the smallest amount of overhead and client facing slowness. Here's the jist of what I'm looking at...
There are 21 API methods to pull different types of orders, and each of them handle paging by requesting a number of records (10 - 500), and a page number. So I could say in my URI, "page-no=1&no-of-records=50", followed by "page-no=2&no-of-records=50", to get subsequent records. The API will return in each call the total records returned as well as the total records in their database.
Now, I want to insert all of this into my database, and so that means something like 21 APIs * 3 SQL requests each = 63 sql queries (check it exists, if so update - else insert).
This seems to me like way too much work for a client facing application. Any suggestions?
Hi friends i need a small help in importing csv files into mySQL database table i tried all possible options but i am no where... here is the example for what i am trying to do Mysql DB name = raw Table name is = dump +--------------------+--------------------+ + Account + Bal + +--------------------+--------------------+ + + + +--------------------+--------------------+ CSV Format 50************13, 11095 When they upload the file it should automatically get inserted into appropriate fields any help would be great i tried all possible scripts found in the net could nothing is happening Hi Guys Just need some advice to go in the right direction. I'm working on a csv upload script (part of a bigger thing i'm building), so i read in the csv to a multipdimensional array and then build a query that inputs all rows in one query - i read this is the most efficient way to import multiple rows of data at once(rather than multiple insert statements). Just for illustration here's the code i use to build the query so you understand what i'm on about: Code: [Select] $sql = "INSERT INTO teams (company, teamname, teamnum, amountraised, country, president) VALUES "; // $rows is a count of the rows in the csv for($i=1; $i<$rows; $i++){ $sql.="('{$myarray[$i][0]}','{$myarray[$i][1]}','{$myarray[$i][2]}','{$myarray[$i][3]}','{$myarray[$i][4]}','{$myarray[$i][5]}')"; echo $i . "<br/>"; if($i >= 1 && $i < $rows - 1) { $sql.= ","; } } Anyway, the issue is that one of the fields("teamnum") needs to be unique - so i've set this as unique on the table in mysql. But when i run my query it doesn't import anything if one of the records isn't unique. What i really want is for it to import the ones it can and catch the ones it cant import to present to the user. So my question is - to acheive the above would i need to rewrite the query so that it inserts each row one at a time, instead of all together? Or can someone point me in the right direction for a better solution? Probably something very simple i've missed i am sure... Thanks chaps! I have been pulling my hair out for the lasy 3 hours i am trying to update a MySql table but i cant get it too work, i just keep getting MySql error #1064 - You have an error in your SQL syntax; if i just update 1 field it works fine but if i try to update more than 1 field it dosent work, Help Please! <?php $root = $_SERVER['DOCUMENT_ROOT']; require("$root/include/mysqldb.php"); require("$root/include/incpost.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); mysql_query("UPDATE Reg_Profile_p SET build='$build' col='$col' size='$size' WHERE uin = '$uinco'"); ?> I'm attempting to import a mysql database backup via php unfortunately I keep getting this error: Code: [Select] 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 'SOURCE file.sql' at line 1 Code: mysql_query("SOURCE file.sql") or die (mysql_error()); I've researched this online and this seems to be the way everyone suggests to use, unfortunately it isn't working. If it helps here is the first 4 lines of file.sql as that may be the problem for all I know: -- phpMyAdmin SQL Dump -- version 3.2.4 -- http://www.phpmyadmin.net -- Hello I am tring to import a .txt file into an array. I am stuck will somone please help me. ?<php $fp = fopen("ArrayTestFile.txt", 'wb'); $X = fread("ArrayTestFile.txt" 'w'); for ($j = 0 ; $j < 6 ; ++$j) { $written = fwrite($fp, "ArrayTestFile.txt"); if ($written == FALSE) break; } print $fp[0] . " " . $fp[1] . " " . $fp[2] . " " . $fp[3] . " " . $fp[4]; fclose($fp); ?> Haven't really used traits much and am confused whether to import other classes in the trait or the class that uses the trait (might also be an annotation question but not sure). Must import statements (i.e. use Foo\Bar;) be included in the class or can they be included in just the trait which is used by a class? Does it depend and if so on what? Does having one class use another class impact the decision? Is it okay for one trait to use another and another trait to just use the first trait or should it use both? What is odd is I apparently must (to not get an error) import ApiProperty to the trait but doing so is not required for the class, and must import Groups, SerializedName, and Mapping in the class but doing so is not required for the trait. Instead of just a yes/no answer, would appreciate an explanation why it is what it is. Thanks! <?php namespace App\Entity\Document; use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; use App\Entity\MultiTenenacy\PublicIdTenantTrait; // Must Groups, SerializedName, Owner be imported in this class or just PublicIdTenantTrait // use Symfony\Component\Serializer\Annotation\Groups; // use Symfony\Component\Serializer\Annotation\SerializedName;use // use App\Entity\Owner\Owner; /** * @ORM\Entity() * @ApiResource() */ class Document { use PublicIdTenantTrait; }
<?php namespace App\Entity\MultiTenenacy; use ApiPlatform\Core\Annotation\ApiProperty; use Doctrine\ORM\Mapping as ORM; trait PublicIdTenantTrait { use PublicIdExtendedTenantTrait; /** * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ApiProperty(identifier=false) * @ORM\Column(type="integer") */ private $id; public function getId(): ?int { return $this->id; } }
<?php namespace App\Entity\MultiTenenacy; use ApiPlatform\Core\Annotation\ApiProperty; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; use Doctrine\ORM\Mapping as ORM; trait PublicIdExtendedTenantTrait { use TenantTrait; /** * @ORM\Column(type="integer") * @ApiProperty(identifier=true) * @Groups({"tenant_entity:read"}) * @SerializedName("id") */ private $publicId; public function getPublicId(): ?int { return $this->publicId; } public function setPublicId(int $publicId): PublicIdTenantInterface { $this->publicId = $publicId; return $this; } public function generatePublicId(): PublicIdTenantInterface { $this->getOwner()->setPublicId($this); return $this; } public function getPublicIdTag(): string { return lcfirst((new \ReflectionClass($this))->getShortName()).'Id'; } }
<?php namespace App\Entity\MultiTenenacy; use Doctrine\ORM\Mapping as ORM; use App\Entity\Owner\Owner; trait TenantTrait { /** * inversedBy performed in child where required * @ORM\ManyToOne(targetEntity=Owner::class) * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") */ private $owner; public function getOwner(): ?Owner { return $this->owner; } public function setOwner(?Owner $owner): TenantInterface { $this->owner = $owner; return $this; } }
I need to write a code were users can login to his/her email account from my site to import contacts to be selected and used. I know you need to use api's for this. Has anyone done this before who can give me some useful tips? I have a site where I have an admin panel set up to import an XML data feed into a database, but it's a large import and it takes a lot of time to update. I'm looking to upgrade the admin panel and offer the ability to be able to see the number of records as they're being imported instead of it hanging there until the query is completed. The tough part about a progress bar is obviously you have to know the # of items being imported beforehand, and that varies each time the feed is downloaded. So I'm just trying to get some suggestions from someone who may have written something similar. Thanks in advance! Hello, I've got two questions. Users can fill in a form with information that has to be in the following format: Value 1, Value 2, Value 3, Value 4 Value 1, Value 2, Value 3, Value 4 Now I want to return an error if ANY line isn't in that format. For example when it's like this: Value 1, Value 2, Value 3, Value 4 Value 1, Value 3, Value 4 I've got no clue how to do that... The second question is, how can I get a specific line of the posted information? I've already gotten an answer on how to count those lines, which is working. But I'm going to insert them into the database using a for loop, so I need to insert one row at a time. Thanks for your time and help, Chris I need someone to look over this and just see if they can see why this won't work anymore? It worked when the site was in development but when it came down to the day it's not working. Basically it reads a CSV and inserted the driver into a Quali or Results table in the correct order but it's not working anymore? If someone could have a read over it and suggest what might be going wrong that would be great. Edit: It basically just added the same driver 24 times in the table. Code: [Select] Public Function ProcessUpload($UR, $RaceID, $RaceName) { Global $MDB; // Configuration - Your Options $allowed_filetypes = array('.csv'); // These will be the types of file that will pass the validation. $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = './resultsfiles/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. If (strpos($filename, "Quali") == True) { $tbl_name = "QualiPositions"; $FN = " - Qualifying"; } Else { $tbl_name = "RacePositions"; $FN = " - Race"; } $SQL = "SELECT count(*) FROM $tbl_name WHERE RaceID = $RaceID"; $Count = $MDB->prepare($SQL); $Count->execute(); $Count = $Count->fetchColumn(); If ($Count == 24) { $Msg = "<div class='error'>Error: We already have 24 Results for this Session.</div>"; } // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) $Msg = "<div class='error'>Error: The file you attempted to upload is not allowed.</div>"; // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) $Msg ="<div class='error'>Error: The file you attempted to upload is too large.</div>"; // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) $Msg ="<div class='error'>Error: You cannot upload to the specified directory, please CHMOD it to 777.</div>"; If (strpos($Msg, "Error:") == False) { // Upload the file to your specified path. $filename = str_replace(" ", "", $RaceName)."$FN.csv"; if (move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { $FilePath = $upload_path . $filename; if (($handle = fopen($FilePath, "r")) !== FALSE) { $Pos = 0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { $Pos++; If ($Pos <= 24) { $Driver = explode(" ", $data[$c]); $FName = $Driver[0]; $LName = $Driver[1]." ".$Driver[2]." ".$Driver[3]; $STH = $MDB->query("SELECT * FROM Drivers WHERE FirstName = '$FName' AND LastName = '$LName'"); $STH->setFetchMode(PDO::FETCH_OBJ); while($row = $STH->fetch()) { $DriverID = $row->DriverID; $ChassisID = $row->ChassisID; $EngineID = $row->EngineID; } $STH = $MDB->prepare("INSERT INTO $tbl_name(RaceID, DriverID, ChassisID, EngineID, Position, DSQ) VALUES (:RID, :DID, :ChaID, :EngID, :Pos, :DSQ)"); $STH->execute(array('RID' => $RaceID, 'DID' => $DriverID, 'ChaID' => $ChassisID, 'EngID'=>$EngineID, 'Pos'=>$Pos, 'DSQ' => 0)); $Msg = "<div class='team_confirm'>The Results have been uploaded for the $RaceName</div>"; } Else { If ($tbl_name == "RacePositions") { $Driver = explode(" ", $data[$c]); $FName = $Driver[0]; $LName = $Driver[1]." ".$Driver[2]." ".$Driver[3]; $STH = $MDB->query("SELECT * FROM Drivers WHERE FirstName = '$FName' AND LastName = '$LName'"); $STH->setFetchMode(PDO::FETCH_OBJ); while($row = $STH->fetch()) { $DriverID = $row->DriverID; } $sql = "UPDATE RacePositions SET FastLap = 'Yes' WHERE RaceID=? AND DriverID = ?"; $q = $MDB->prepare($sql); $q->execute(array($RaceID, $DriverID)); } } } } fclose($handle); } } else { $Msg = 'There was an error during the file upload. Please try again.'; // It failed :(. } } Return $Msg; } That is the code, the CSV is basically like this: Code: [Select] Lewis Hamilton, Jenson Button, Romain Grosjean, Michael Schumacher, Mark Webber, Sebastian Vettel, Nico Rosberg, Pastor Maldonado, Nico Hulkenberg, Daniel Ricciardo, Jean-Eric Vergne, Fernando Alonso, Kamui Kobayashi, Bruno Senna, Paul di Resta, Felipe Massa, Kimi Raikkonen, Heikki Kovalainen, Vitaly Petrov, Timo Glock, Charles Pic, Sergio Perez, Pedro de la Rosa, Narain Karthikeyan Thanks for any help! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321126.0 Error: Code: [Select] 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' at line 1 Code: Code: [Select] <?php session_start(); include "includes/connect.php"; include "includes/config.php"; if(isset($_SESSION['admin2'])){ include 'includes/getuserinfo.php'; ?> <!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=utf-8" /> <title>Dashboard | Modern Admin</title> <link rel="stylesheet" type="text/css" href="css/960.css" webstripperwas="css/960.css" /> <link rel="stylesheet" type="text/css" href="css/reset.css" webstripperwas="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/text.css" webstripperwas="css/text.css" /> <?php if($acptheme == '') { echo '<meta http-equiv=Refresh content=0;url="nocss.php">'; } else { echo '<link rel="stylesheet" type="text/css" href="css/'.$acptheme.'.css" webstripperwas="css/<?php echo $acptheme ?>.css" />'; } ?> <link type="text/css" href="css/smoothness/ui.css" webstripperwas="css/smoothness/ui.css" rel="stylesheet" /> <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" webstripperwas="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script> <script type="text/javascript" src="js/blend/jquery.blend.js" webstripperwas="js/blend/jquery.blend.js" ></script> <script type="text/javascript" src="js/ui.core.js" webstripperwas="js/ui.core.js" ></script> <script type="text/javascript" src="js/ui.sortable.js" webstripperwas="js/ui.sortable.js" ></script> <script type="text/javascript" src="js/ui.dialog.js" webstripperwas="js/ui.dialog.js" ></script> <script type="text/javascript" src="js/ui.datepicker.js" webstripperwas="js/ui.datepicker.js" ></script> <script type="text/javascript" src="js/effects.js" webstripperwas="js/effects.js" ></script> <script type="text/javascript" src="js/flot/jquery.flot.pack.js" webstripperwas="js/flot/jquery.flot.pack.js" ></script> <![if IE]> <script language="javascript" type="text/javascript" src="js/flot/excanvas.pack.js" webstripperwas="js/flot/excanvas.pack.js" ></script> <![endif]> <![if IE 6]> <link rel="stylesheet" type="text/css" href="css/iefix.css" webstripperwas="css/iefix.css" /> <script src="js/pngfix.js" webstripperwas="js/pngfix.js" ></script> <script> DD_belatedPNG.fix('#menu ul li a span span'); </script> <![endif]> <script id="source" language="javascript" type="text/javascript" src="js/graphs.js" webstripperwas="js/graphs.js" ></script> </head> <body> <!-- WRAPPER START --> <div class="container_16" id="wrapper"> <!-- HIDDEN COLOR CHANGER --> <div style="position:relative;"> </div> <?php include 'inc/inc/logo.php'; include 'inc/inc/user.php'; ?> <!-- USER TOOLS END --> <div class="grid_16" id="header"> <!-- MENU START --> <div id="menu"> <ul class="group" id="menu_group_main"> <li class="item first" id="one"><a href="dashboard.php" class="main current"><span class="outer"><span class="inner dashboard">Dashboard</span></span></a></li> <li class="item middle" id="two"><a href="page.php" class="main"><span class="outer"><span class="inner content">Pages</span></span></a></li> <li class="item middle" id="three"><a href="#" class="main"><span class="outer"><span class="inner users">Users</span></span></a></li> <li class="item middle" id="four"><a href="#" class="main"><span class="outer"><span class="inner event_manager">Event Manager</span></span></a></li> <li class="item middle" id="five"><a href="#" class="main"><span class="outer"><span class="inner newsletter">Newsletter</span></span></a></li> <li class="item last" id="six"><a href="#" class="main"><span class="outer"><span class="inner settings">Settings</span></span></a></li> </ul> </div> <!-- MENU END --> </div> <div class="grid_16"> <!-- TABS START --> <div id="tabs"> <div class="container"> <ul> <li><a href="dashboard.html" class="current"><span>Dashboard elements</span></a></li> <li><a href="dash/news.php"><span>News</span></a></li> <li><a href="dash/topnews.php"><span>Top News</span></a></li> </ul> </div> </div> <!-- TABS END --> </div> <!-- CONTENT START --> <div class="grid_16" id="content"> <!-- TITLE START --> <div class="grid_9"> <h1 class="dashboard">Dashboard</h1> </div> <!--RIGHT TEXT/CALENDAR--> <div class="grid_6" id="eventbox"><a href="#" class="inline_calendar">You don't have any events for today! Yay!</a> <div class="hidden_calendar"></div> </div> <!--RIGHT TEXT/CALENDAR END--> <div class="clear"> </div> <!-- TITLE END --> <!-- #PORTLETS START --> <div id="portlets"> <!-- FIRST SORTABLE COLUMN START --> <div class="column" id="left"> <div class="portlet"> <div class="portlet-header">Insert News</div> <div class="portlet-content"> <p> </p> </div> </div> </div> <!-- FIRST SORTABLE COLUMN END --> <!-- SECOND SORTABLE COLUMN START --> <div class="column"> <!--THIS IS A PORTLET--> <div class="portlet"> <div class="portlet-header"><img src="images/icons/comments.gif" webstripperwas="images/icons/comments.gif" width="16" height="16" alt="Comments" />Change Theme</div> <div class="portlet-content"> <p class="info" id="success"><span class="info_inner">Change Theme To GEEN</span></p> <p class="info" id="error"><span class="info_inner">Change Theme To RED</span></p> <p class="info" id="info"><span class="info_inner">Change Theme To BLUE</span></p> </div> </div> <!--THIS IS A PORTLET--> <div class="portlet"> <div class="portlet-header"><img src="images/icons/feed.gif" webstripperwas="images/icons/feed.gif" width="16" height="16" alt="Feeds" />Current News </div> <div class="portlet-content"> <ul class="news_items"> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> </ul> <a href="#">» View all news items</a> </div> </div> </div> <!-- SECOND SORTABLE COLUMN END --> <div class="clear"></div> <!--THIS IS A WIDE PORTLET--> <div class="portlet"> <div class="portlet-header fixed"><img src="images/icons/user.gif" webstripperwas="images/icons/user.gif" width="16" height="16" alt="Latest Registered Users" /> Last Registered users Table Example</div> <div class="portlet-content nopadding"> <form action="" webstripperwas method="post"> <table width="100%" cellpadding="0" cellspacing="0" id="box-table-a" summary="Employee Pay Sheet"> <thead> <tr> <th width="34" scope="col"><input type="checkbox" name="allbox" id="allbox" onclick="checkAll()" /></th> <th width="136" scope="col">Name</th> <th width="102" scope="col">Username</th> <th width="109" scope="col">Date</th> <th width="129" scope="col">Location</th> <th width="171" scope="col">E-mail</th> <th width="123" scope="col">Phone</th> <th width="90" scope="col">Actions</th> </tr> </thead> <tbody> <tr class="footer"> <td colspan="4"><a href="#" class="edit_inline">Edit all</a><a href="#" class="delete_inline">Delete all</a><a href="#" class="approve_inline">Approve all</a><a href="#" class="reject_inline">Reject all</a></td> <td align="right"> </td> <td colspan="3" align="right"> </td> </tr> </tbody> </table> </form> </div> </div> <!-- END #PORTLETS --> </div> <div class="clear"> </div> <!-- END CONTENT--> </div> <div class="clear"> </div> <!-- This contains the hidden content for modal box calls --> <div class='hidden'> <div id="inline_example1" title="This is a modal box" style='padding:10px; background:#fff;'> <p><strong>This content comes from a hidden element on this page.</strong></p> <p><strong>Try testing yourself!</strong></p> <p>You can call as many dialogs you want with jQuery UI.</p> </div> </div> </div> <!-- WRAPPER END --> <!-- FOOTER START --> <div class="container_16" id="footer"> Website Administration by <a href="http://www.webgurus.biz" >WebGurus</a></div> <!-- FOOTER END --> </body> </html> <?php } else { echo 'You are not logged in as an administrator.'; } ?> Whats in Connect: Code: [Select] <?php include 'config.php'; DEFINE ('DB_HOST', DB_HOST); // This will most likely stay the same. DEFINE ('DB_USER', DB_USER); // Insert your database username into the quotes. DEFINE ('DB_PASSWORD', DB_PASSWORD); // Insert your database password into the quotes. DEFINE ('DB_NAME', DB_NAME);// Insert your actual database name in the quotes. $con = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //$con = mysql_connect(':/tmp/mysql', $dbuser, $dbpass); mysql_select_db(DB_NAME ,$con); include 'functions.php'; if (isset($_SESSION['user'])) { if($result = mysql_query("SELECT username, rights FROM users WHERE username='{$_SESSION['user']}'")); $n = mysql_fetch_assoc($result); if($n['banned'] == 1) { header("Location: logout.php"); } else { if($n['rights'] == 2) { $_SESSION['admin'] = $n['username']; $_SESSION['user'] = $n['username']; } elseif($n['rights'] == 1) { $_SESSION['mod'] = $n['username']; $_SESSION['user'] = $n['username']; } elseif($n['rights'] == 0) { $_SESSION['user'] = $n['username']; } } } Whats in Config.php: Code: [Select] <?php DEFINE ('DB_HOST', 'localhost'); // This will most likely stay the same. DEFINE ('DB_USER', 'root'); // Insert your database username into the quotes. DEFINE ('DB_PASSWORD', ''); // Insert your database password into the quotes. DEFINE ('DB_NAME', 'school');// Insert your actual database name in the quotes. $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() ); ?> whats in Functions.php: Code: [Select] <?php function ___($_) { return base64_decode($_); } function realEscape($string) { if(get_magic_quotes_gpc()) { return mysql_real_escape_string(stripslashes($string)); } else { return mysql_real_escape_string($string); } } function capitalize($value) { $capitalize = preg_replace('/[a-z]/ie', 'strtoupper($0);', $value, 1); return htmlspecialchars($capitalize); } function encrypt($value) { return md5(md5(base64_encode($value))); } $w = 1; function smileys($value) { global $ln; $codes = array( ':)', ':angel:', ':@', ':shy:', ':s', ':dodgy:', ':!:', ':heart:', ':confused:', ':idea:', ':tired:', ':-/', ';)', ':cool:', ':D', ':P', ':rolleyes:', ':('); $img = array( '<IMG alt="Smile" title="Smile" src="http://runelegend.com/images/smilies/smile.gif">', '<IMG alt="Angel" title="Angle" src="http://runelegend.com/images/smilies/angel.gif">', '<IMG alt="Angry" title="Angry" src="http://runelegend.com/images/smilies/angry.gif">', '<IMG alt="Shy" title="Shy" src="http://runelegend.com/images/smilies/blush.gif">', '<IMG alt="Confused" title="Confused" src="http://runelegend.com/images/smilies/confused.gif">', '<IMG alt="Dodgy" title="Dodgy" src="http://runelegend.com/images/smilies/dodgy.gif">', '<IMG alt="Exclamation" title="Exclamation" src="http://runelegend.com/images/smilies/exclamation.gif">', '<IMG alt="Heart" title="Heart" src="http://runelegend.com/images/smilies/heart.gif">', '<IMG alt="Confused" title="Confused" src="http://runelegend.com/images/smilies/huh.gif">', '<IMG alt="Idea" title="Idea" src="http://runelegend.com/images/smilies/lightbulb.gif">', '<IMG alt="Sleepy" title="Sleepy" src="http://runelegend.com/images/smilies/sleepy.gif">', '<IMG alt="Undecided" title="Undecided" src="http://runelegend.com/images/smilies/undecided.gif">', '<IMG alt="Wink" title="Wink" src="http://runelegend.com/images/smilies/wink.gif">', '<IMG alt="Cool" title="Cool" src="http://runelegend.com/images/smilies/cool.gif">', '<IMG alt="Biggrin" title="Biggrin" src="http://runelegend.com/images/smilies/biggrin.gif">', '<IMG alt="Tongue" title="Tongue" src="http://runelegend.com/images/smilies/tongue.gif">', '<IMG alt="Rolleyes" title="Rolleyes" src="http://runelegend.com/images/smilies/rolleyes.gif">', '<IMG alt="Sad" title="Sad" src="http://runelegend.com/images/smilies/sad.gif">'); return str_ireplace($codes, $img, $value); } function bbcodes($value) { $value1 = htmlspecialchars($value); $bbcodes = array( '/\[url=(.*)\](.*)\[\/url\]/isU', '/\[b\](.*)\[\/b\]/isU', '/\[img\](.*)\[\/img\]/isU', '/\[u\](.*)\[\/u\]/isU', '/\[i\](.*)\[\/i\]/isU', '/\[url\](.*)\[\/url\]/isU', '/\[s\](.*)\[\/s\]/isU', '/\[color=(#?[a-z0-9]+)\](.*)\[\/color\]/isU', '/\[center\](.*)\[\/center\]/isU', '/\[big\](.*)\[\/big\]/isU', '/\[small\](.*)\[\/small\]/isU', ); $html = array( '<a class="hrefblack" href="$1">$2</a>', '<b>$1</b>', '<img src="$1">', '<u>$1</u>', '<i>$1</i>', '<a href="$1">$1</a>', '<s>$1</s>', '<div style="color: $1">$2</div>', '<div style="text-align: center">$1</div>', '<div style="font-size: 3em">$1</div>', '<div style="font-size: 0.8em">$1</div>', ); $result = preg_replace($bbcodes, $html, $value1); return $result; } /* if(isset($_SESSION['admin']) || isset($_SESSION['user'])) { if($news1 = mysql_query("SELECT * FROM ".$prefix."users WHERE uname='". $_SESSION['user'] ."'")) { if(mysql_num_rows($news1) > 0) { while($n = mysql_fetch_array($news1)) { if($n['banned'] == 1) { header("Location: logout.php"); } } } } } if($checkipban = mysql_query("SELECT * FROM ". $prefix ."ipban WHERE ip='". $_SERVER['REMOTE_ADDR'] ."'")) { if(mysql_num_rows($checkipban) > 0) { header("Location: ipbanned.php"); } }*/ ?> <?php function capitalizeFirstCharacter($value) { $capitalize = preg_replace('/[a-z]/ie', 'strtoupper($0);', $value, 1); return $capitalize; } ?> Whats in getuserinfo.php: Code: [Select] <?php $result = mysql_query("SELECT * FROM main id=". $_SESSION['id']) or die(mysql_error()); $row = mysql_fetch_assoc($result); $acptheme = $row["acptheme"]; ?> Please Help. Code: [Select] $con=mysql_connect("****","****","****"); mysql_select_db("****"); $queryuser=mysql_query("SELECT * FROM users WHERE name='$name'"); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error = $name." is already in the database. <br /> <a href='****'>Return</a>"; $errortype = "1";} else { /* Now we will write a query to insert user details into database */ $insert = mysql_query("INSERT INTO users (name, group, sex, grouprank) VALUES ('$name', '$group', '$sex', '$grouprank')"); if($insert) { $error = $name. "Was successfully added to the database. <br /> <a href='****'>Return</a>"; $errortype = "0";} else { $error = "Error in registration: ".mysql_error(); $errortype = "1";} /* closing the if else statements */ } echo $error; ?>Error: Code: [Select] Error in registration: 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 'group, sex, grouprank) VALUES ('ljkh', 'lnkb', 'female', 'lkjh')' at line 1 Please help. THanks hey guys; Another problem with sql. Code: [Select] { echo "Welcome " . $row['username']; echo "<br />"; echo "<br />"; echo "<br />"; $msgquery = "SELECT * FROM spotty_messages WHERE (id_receiver = '" . $userid . "') AND message_read = '0'"; $messageres = mysql_query($msgquery); $messrow = mysql_fetch_array($messageres); $messagenum = mysql_num_rows($messageres); } $i = 0; while ($i < $messagenum) { $f1 = "From:" . mysql_result($messrow,$i,"sender"); echo " <tr> <td>" . $f1 ."</font></td> " ; $i++; } This is returning the error : Warning: mysql_result() expects parameter 1 to be resource, null given in /customers/klueless.net/klueless.net/httpd.www/daisysite/messages.php on line 106 Please help, thanks! |