473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

include.. but it doesn't!

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?

Jun 13 '07 #1
6 1623
vinnie wrote:
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?
Maybe the php.ini settings need to allow include files in the "current
directory" or perhaps DB_1.php is not in the same directory as your script?

Spartacus
Jun 13 '07 #2
Your SQL query may be wrong. Try this one:

$query_table="insert into table_name values('".$_POST['nome']."',
'".$_POST['cognome']."','".$_POST['indirizzo']."', '".
$_POST['telefono']."',
'".$_POST['cell']."','".$_POST['email']."')";

Jun 13 '07 #3
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 - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 14 '07 #4
On Wed, 13 Jun 2007 09:18:52 -0700, in comp.lang.php vinnie
<ce**********@gmail.com>
<11**********************@o11g2000prd.googlegroups .comwrote:
>| 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:
Rename www.yyyyyy.com/insert_form.html to
www.yyyyyy.com/insert_form.php then the web server will process your
page. At present, because of the extension, the web server isn't
looking at your file to see if it needs to anything with the files'
contents.

>| <?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?
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jun 14 '07 #5
vinnie wrote:
<?php
function connect()
{
// SERVER connection
$con=mysql_connect('host', 'My_user_ID', 'My_Pwd');
// DB selection
$sql=mysql_select_db('Database_name');
}
?>
<?php
function connect()
{
// SERVER connection
$con=mysql_connect('host', 'My_user_ID', 'My_Pwd');
// DB selection
$sql=mysql_select_db('Database_name');

return $con;
}
$con = connect();
?>

If you don't understand this, please read the PHP manual -- the part which
explains what a function is and how they work. Read the bits on variable
scope too.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 110 days, 20:10.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 14 '07 #6
<?php
include ("DB_1.php");
// connect();
$query_table="insert into table_name values('$_POST[nome]',
Why is the call to the connect function commented out? If you do want
the function to be called, remove the // at the start of that line.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Jun 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom Cat | last post by:
Is there anything wrong with using a lot of include files? On one part of my website, I have a form. The page it posts data to, includes a different file based on some of the values. The...
28
by: Ramesh | last post by:
Hi, I am currently maintaining a legacy code with a very very large code base. I am facing problems with C/C++ files having a lot of un-necessary #includes. On an average every C/C++ file has...
6
by: Puzzled | last post by:
This is a weird problem, but perhaps someone else has seen it before (I hope!) If I use a fully qualified include call include ( 'http://localhost/subtree/filename.php') I get an 'undefined...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
14
by: Julesh | last post by:
Hello, I am new to ASP and am trying to make some changes to some ASP 3.0 code I have inherited. I have a number of ASP pages with VBS as the base language, on each of these pages I have...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
16
by: Chris Shearer Cooper | last post by:
In our Visual Studio 2005 application, we have several of our application's H files that are #included into stdafx.h. What is odd, is that when we change those application H files, VS2005...
111
by: Nate | last post by:
Hello, I am looking for a method to automatically declare variables in C. I'm not sure if there is a good way to do this, but I had something like this in mind... int i; for(i = 1; i < 4;...
11
by: yawnmoth | last post by:
To quote from <http://php.net/function.include>, "Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value." ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.