genau Posted January 29, 2009 Report Share Posted January 29, 2009 Esmu jauniņais PHP, varat palīdzet atrisināt vienu problēmu. Vēlos izveidot tabulu ar nosaukumu, kādā ir nosaukts lauks citā tabulā. Kods: .... $title= $_GET['title']; $sql = "CREATE TABLE $title ( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `email` varchar(65) NOT NULL default '', `comment` longtext NOT NULL, `datetime` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"; ...... $result = mysql_query($sql,$connect); .... Šāds kods nedarbojas, esmu pagooglejis arī šādi kodi CREATE TABLE `$title`...;CREATE TABLE `($title)`...; CREATE TABLE `DBvārds`.$title nedarbojas. Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Kā tu zini, ka nedarbojas? Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 phpmyadmin neizveidojas tabula Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Tā noteikti nav pārbaude, uz ko tev jāskatās. Tev ir jāpārbauda tā CREATE kverija rezultātu ($result). Un ja rezultāts saka, ka ir kļūda, tad izvadi kļūdas paziņojumu (mysql_error). Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 kā tas ir??? Link to comment Share on other sites More sharing options...
marcis Posted January 29, 2009 Report Share Posted January 29, 2009 mysql_query($sql)or die(mysql_error()); Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 izdeva šādu paziņojumu: "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 '( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT ' at line 1" izpildot: ($title vietā a) "CREATE TABLE a ( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `email` varchar(65) NOT NULL default '', `comment` longtext NOT NULL, `datetime` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"; query izpildās bez problēmām. Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 Lūdzu nevajag taisīt bezjēdzīgas QUOTEs man šada MySQL 5.0 versija Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Izdrukā kveriju (echo $sql) un pārbaudi tā sintaksi. Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 Izdrukā kveriju (echo $sql) un pārbaudi tā sintaksi. Laikam esmu stūlbs, bet kļūdu es neredzu CREATE TABLE ( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `email` varchar(65) NOT NULL default '', `comment` longtext NOT NULL, `datetime` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Kur tev tur ir pazudis tabulas nosaukums? CREATE TABLE te_jābūt_tabulas_nosaukumam ( ... kolonnas ...) Pārbaudi savu $title mainīgo. Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 paldies visiem par palīdzību, centos izmantot mainīgo kuram vēl nebiju piešķīris mainīgo. Vēl viens jautājums vai tabulas nosaukumam var piešķirt skaitli piem 1 vai 1-posts? Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Kāpēc gan tu kautko tādu gribētu? Link to comment Share on other sites More sharing options...
genau Posted January 29, 2009 Author Report Share Posted January 29, 2009 Lūdzu nevajag taisīt bezjēdzīgas QUOTEs Tāpat, likt pārbaudi pie ievades vai nelikt. Link to comment Share on other sites More sharing options...
bubu Posted January 29, 2009 Report Share Posted January 29, 2009 Par kādu pārbaudi tu runā? Es tev prasu kāpēc tu gribi likt tabulai nosaukumu "1" vai "1-posts". Tas ļoti aizdomīgi izskatās pēc tā, ka tu nepareizi izmanto SQL datubāzi, jo man šķiet, ka tu taisi visparastāko 1:N relāciju starp divām tabulām līkā veidā. Link to comment Share on other sites More sharing options...
Recommended Posts