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/43 11:22

> [...] I do not see the data in the form.

What do you mean by that?



> The code follows:

Now your code is even worse than before.


> <?php
> if(isset($_POST['add']) && ($_POST['add']=="Skicka")) {

You do not have any form element named "add". (I assume
that the submit button should have that name, as it
had before.)


> $fornamn = $_POST['fornamn'];

You do not have any form element named "fornamn". You
have textbox named "Fnamn".


> $efternamn = $_POST['efternamn'];

You do not have any form element named "efternamn". You
have textbox named "Efternamn".


> $db = mysql_connect("local host", "user", "password")
> or die('I could not connect');
> mysql_select_db("scaiecat_?", $db);

> $query="INSERT INTO Formular('Fornamn','Efternamn')
> VALUES($Fornamn','$Efternamn')";

Should not put single quotes around column names, so:
INSERT INTO Formular( Fornamn, Efternamn )
You do not have variables $Fornamn or $Efternamn. Probably
should be $fornamn and $efternamn (variable names ARE
case sensitive).
You do not have opening single quote around fornamn value.
So should be something like:

$query = 'INSERT INTO Formular( Fornamn, Efternamn ) '
. "VALUES( '$fornamn', '$efternamn' )";

The query you used (without opening single quote) probably
caused differen error than before, but you probably - as
usual - did not check it (you should have and also you
should have posted the error message if it's not same as
the one before or state that you are still having the
same error, so readers of your post do not have to guess
what is it about this time).


> mysql_query($query) or die('Error, insert query failed');
> }?>
> <html>
> <body>


> <form method="post">

You should provide "action" attribute in <form> tags.
If you do not, then user browser decides where to send
the data. You probably want to send the data to the
same script, so something like that should be used:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">


> <?php
> echo
> "<LABEL FOR='Fornamn'>Förnamn</LABEL>";
> ?>

Why not simple:
<LABEL FOR='Fornamn'>Förnamn</LABEL>


> <INPUT TYPE="TEXT" NAME='Fnamn' id='Fornamn'><br>

Check this input name and $_POST value you used above.


> <?php
> echo
> "<LABEL FOR='Efternamn'>Efternamn</LABEL>";
> ?>

Again the same.


> <INPUT TYPE="TEXT" NAME='Efternamn' id='Efternamn'><br>

Check this input name and $_POST value you used above.


> <INPUT TYPE=SUBMIT VALUE=Skicka>

Should have "name" set to "add".


> </FORM> </form>

Why double closing? You opened only one <form> tag.


> </body>
> </html>


You also again skipped all error checking (mysql_error).


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

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