|
Posted by Stefan Rybacki on 07/24/05 18:45
Luigi Donatello Asero wrote:
> "J.O. Aho" <user@example.net> skrev i meddelandet
> news:3khldfFue9aoU1@individual.net...
>
>>Luigi Donatello Asero wrote:
>>
>>>In the example below I have only written the html body to try to reduce
>
> the
>
>>>code to a minimum and find the error.
>>>
>>><?php
>>>if(isset($_POST['add']));
>>>$fornamn = $_POST['fornamn'];
>>>$efternamn = $_POST['efternamn'];
>>> $db = mysql_connect("local host", "user",
>>>"password");
>>> mysql_select_db("scaiecat_?", $db);
>>>$query = "INSERT INTO Formulär ('local host', 'user',
>>>'password');
>>
>>Avoid to use åäö in table and column names, those leads usually to
>
> problems.
>
>
> Well, it might be that it leads to problems
> But the table "semesterbostäder" works on although I used "ä"
> https://www.scaiecat-spa-gigi.com/sv/boende-i-italien.php
> and https://www.scaiecat-spa-gigi.com/sv/test27.php
>
>
>>>VALUES ('förnamn' ( '$fornamn'), efternamn('$efternamn')";
>>>mysql_query($query) or die('Error, insert query failed'};
>>>else {
>>
>>A query should look something like:
>>
>>$query="INSERT INTO Formular('fornamn','efternamn')
>>VALUES($fornamn','$efternamn')";
>
>
>
> Ok. I corrected it.
> I also used echo to display the labels in the form
> Unfortunately, I still get an error at
> https://www.scaiecat-spa-gigi.com/sv/form.php
>
>
> <?php
> if(isset($_POST['add']));
What is this if statement supposed to do? Its doing nothing!
> $fornamn = $_POST['fornamn'];
> $efternamn = $_POST['efternamn'];
> $db = mysql_connect("local host", "user",
> "password")
> or die('I could not connect)};
- Close the string you opened (or die('I could not connect');
- you don't need the } after die?!
> mysql_select_db("scaiecat_?", $db);
> $query="INSERT INTO Formular('fornamn','efternamn')
> VALUES($fornamn','$efternamn')";
> mysql_query($query) or die('Error, insert query failed')};
same here, the } is wrong there
Here you're mixing html with php?! I guess you forgot to close the closing php tag
?>
> <html>
> <body>
> <form method="post">
> <?php
> echo
> "<LABEL FOR="Fornamn">Förnamn</LABEL>";
Here is the next problem, you start a string by " and want to use " inside the string
In this case you need to escape the quote \"
-> echo "<LABEL FOR=\"Fornamn\">Förnamn</LABEL>";
> <INPUT TYPE="TEXT" NAME="fnamn" id="Fornamn"><br>
you're missing another echo command here
> echo
> "<LABEL FOR="Efternamn">Efternamn</LABEL>";
escape of quotes is needed here
> ?>
> <INPUT TYPE="TEXT" NAME="efternamn" id="efternamn"><br>
> <INPUT TYPE=SUBMIT VALUE=Skicka>
> </FORM> </form>
> </body>
> </html>
> ?>
>
After watching this piece of code I've the following recommendations for you:
- read the basics about PHP again/at all, especially parts about the syntax
- use an editor or IDE that shows line numbers, this way you can look for errors PHP is
reporting for yourself ;)
- use an editor that supports syntax high lightning, this way you see for example where
strings start and end
Regards
Stefan
[Back to original message]
|