You are here: Re: Send data form to mysql « PHP SQL « IT news, forums, messages
Re: Send data form to mysql

Posted by Hilarion on 10/13/36 11:22

Luigi Donatello Asero wrote:
>> > The page https://www.scaiecat-spa-gigi.com/sv/form.php shows a form but
>> > when I enter data in the form the result is
>> > "Error, insert query failed".
>> > The question is what I missed this time.
>> >
>> > <html>
>> > <body>
>> > <?PHP
>> > if(array_key_exists('add', $_POST) && ($_POST['add']=="Skicka")) {
>> > $fornamn = $_POST['fornamn'];
>> > $efternamn = $_POST['efternamn'];
>> > $db = mysql_connect("local host", "user", "password")
>> > or die('I could not connect');
>> > mysql_select_db("scaiecat_?", $db);
>> > $query="INSERT INTO Formulär('förnamn','efternamn')
>> > VALUES('$fornamn','$efternamn')";
>> > mysql_query($query) or die('Error, insert query failed');
>> > echo "Följande har sparats till databasen:<br>\n
>> > Förnamn: $fornamn<br>\n
>> > Efternamn: $efternamn<br>\n";
>> > } else {
>> > ?>
>> > <form method="post">
>> > <label for="Fornamn">Förnamn</label>
>> > <input type="text" name="fornamn" id="Fornamn"><br>
>> > <label for="Efternamn">Efternamn</label>
>> > <input type="text" name="efternamn" id="efternamn"><br>
>> > <input type=submit name="add" VALUE="Skicka">
>> > </form>
>> > <?PHP
>> > }
>> > ?>
>> > </body>
>> > </html>

Hilarion wrote:
>> You should try testing your code before asking your question.
>>
>> Simple changing line:
>> > mysql_select_db("scaiecat_?", $db);
>> to
>> > mysql_select_db("scaiecat_?", $db) or die( 'Error switching DB: ' .
>> > mysql_error($db) );
>> would give you info if the switch worked or if not, why it did
>> not work.
>>
>>
>> Simple adding "echo $query;" after seting $query variable
>> would show you how your query looks like with entered values.
>>
>> Simple changing line:
>> > mysql_query($query) or die('Error, insert query failed' );
>> to
>> > mysql_query($query) or die('Error, insert query failed: ' .
>> > mysql_error($db) );
>> would show you more details why the INSERT failed (if it failed).
>>
>> Using results of those three changes you would probably solve
>> the problem yourself.

Luigi Donatello Asero wrote:
> They were good suggestions but the result shows something which I do not
> understand
> Error, insert query failed: Table 'scaiecat_?.Formular' doesn't exist
>
> When looking into the database I find the table "Formular" and the name of
> the database "scaiecat_?"
> was used for the table "semesterbostäder" as well
> which displays data on for example
> https://www.scaiecat-spa-gigi.com/sv/boende-i-italien.php
> So, why do I get a message that the table does not exist?

Something tells me that you havent checked the obvious possible causes.
Check if your table is named "Formular" or "Formulär" (those are
totally different words for MySQL). Also when different encodings
are used to transfer the query string, then word "Formulär" could
get to be some totally different than the two above. That's why
most of SQL users suggests NOT using national characters (like
"ä", "ą", "ö", "ó" etc.) in column names, database names, table
names etc. even if they are allowed by the specific SQL engine
you are using. Most of SQL users also suggests NOT using special
characters (like whitespaces or "?" or "," or "'" or '"' or ":") in
column names, database names, table names etc. even if they
are allowed by the specific SQL engine you are using (MySQL) cause
they can have special meaning for some other SQL engine (eg.
Oracle, MS SQL etc. to which you may want to move your DB in
the future) or database interface (ODBC, JDBC, ADO) which
parses and/or passes the query to the database engine. Safe names
are built like PHP variable names, I mean they consist only of
common US characters and digits and starts with character (not
digit). The names should also not be equal to SQL keywords (like
"table", "column", "order", "add", "delete" etc.).


Hilarion

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация