![]() ![]() |
Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 51 Pomógł: 0 Dołączył: 16.03.2009 Ostrzeżenie: (0%)
|
Hej,
Mam podstawowe pytanie. Dlaczego jesli tworze ponizsza tabele z ID auto increment i dodaje do niej rekordy z poziomu php to nie dodaja sie one do tabeli? Gdy mam tabele bez tego ID to rekordy sie dodaja. CODE <?php // Make a MySQL Connection mysql_connect("localhost", "logme_gracz", "3bj0IQ2R") or die(mysql_error()); mysql_select_db("logme_gracze") or die(mysql_error()); // Create a MySQL table in the selected database mysql_query("CREATE TABLE TIM( id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, flag VARCHAR(60) NOT NULL, name VARCHAR(30) NOT NULL, function VARCHAR(30) NOT NULL, age VARCHAR(10) NOT NULL, location VARCHAR(30) NOT NULL, activity VARCHAR(60) NOT NULL, pic VARCHAR(60) NOT NULL, guid VARCHAR(30) NOT NULL )") or die(mysql_error()); echo "Table Created!"; ?> CODE <?php
//This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $flag=$_POST['flag']; $name=$_POST['name']; $function=$_POST['function']; $age=$_POST['age']; $location=$_POST['location']; $activity=$_POST['activity']; $pic=($_FILES['photo']['name']); $guid=$_POST['guid']; // Connects to your Database mysql_connect("localhost", "logme_gracz", "3bj0IQ2R") or die(mysql_error()) ; mysql_select_db("logme_gracze") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `TIM` VALUES ('$flag', '$name', '$function', '$age', '$location', '$activity', '$pic', '$guid')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> |
|
|
|
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 1 933 Pomógł: 460 Dołączył: 2.04.2010 Skąd: Lublin Ostrzeżenie: (0%)
|
Jeśli tworzysz zapytanie w ten sposób:
to SQL wstawia po kolei do komórek tabeli, czyli id, flag, name, function... itd. A że zamiast ID próbujesz wrzucić $flag (który jak widzę jest VARCHAR), to wyrzuca błąd. Prawidłowe zapytanie:
lub
|
|
|
|
Post
#3
|
|
|
Grupa: Zarejestrowani Postów: 51 Pomógł: 0 Dołączył: 16.03.2009 Ostrzeżenie: (0%)
|
Dzięki ci wielkie. Będę o tym już wiedział na przyszłość.
|
|
|
|
![]() ![]() |
|
Aktualny czas: 25.12.2025 - 10:32 |