|
Posted by Schraalhans Keukenmeester on 06/14/07 05:39
At Wed, 13 Jun 2007 09:18:52 -0700, vinnie let h(is|er) monkeys type:
> this is my include file that i have uploaded on the server called
> DB_1.php
>
> <?php
> function connect()
> {
> // SERVER connection
> $con=mysql_connect('host', 'My_user_ID', 'My_Pwd');
> // DB selection
> $sql=mysql_select_db('Database_name');
> }
> ?>
>
> when i point my browser to www.yyyyyy.com/insert_form.html and i
> submit the form, it recalls the follwing file:
>
> <?php
> include ("DB_1.php");
> // connect();
> $query_table="insert into table_name values('$_POST[nome]',
> '$_POST[cognome]','$_POST[indirizzo]', '$_POST[telefono]',
> '$_POST[cell]','$_POST[email]')";
> $insert=mysql_query($query_table) or die(mysql_error());
> if (mysql_query($query_table, $con))
> {
> header ("Location: http://www.yyyyyy.com/thanks.html");
> exit;
> }
> else
> {
> echo '<br>something went wrong<br>';
> }
> ?>
>
> nothing happens, and no record are added to my database. Why? What
> should i change?
You open the connection in a function, this makes $con a local variable to
the function which goes out of scope as soon as the function ends. So your
quesry isn't sent to the db.
you could instead return $con from the function, call it like so:
$conn = connect();
and then execute your query.
Note that you should _never_ trust POST userdata (nor GET for that
matter); first validate it, sanitize it and only then put stuff into a db
table.
HTH
--
Schraalhans Keukenmeester - schraalhans@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]
"strcmp('apples','oranges') < 0"
Navigation:
[Reply to this message]
|