Reply to Re: having problem getting php to connect

Your name:

Reply:


Posted by peter on 06/24/07 21:09

> function addPerson ()
> {
> $firstName = $_POST['firstName'];
> $lastName = $_POST['lastName'];
> if( $_POST{'dobMonth'} and $_POST{'dobDay'})
> $dob = ($_POST{'dobMonth'}.'/'.$_POST{'dobDay'}.'/'.
> $_POST{'dobYear'});
> else
> $dob = ' ';
> $category = $_POST['category'];
> $address1 = $_POST['address1'];
> $address2 = $_POST['address2'];
> $city = $_POST['city'];
> $state = $_POST['state'];
> $zipcode = $_POST['zipcode'];
> $telephone = $_POST['telephone'];
> $cellphone = $_POST['cellphone'];
> $email1 = $_POST['email1'];
> $email2 = $_POST['email2'];
> $aimid = $_POST['aimid'];
> $url = $_POST['url'];
> $notes = $_POST['notes'];
>
> $sql = "INSERT INTO $db_table4
> (firstName, lastName, dob, category, address1, address2, city,
> state, zipcode, telephone, cellphone, email1, email2, aimid, url,
> notes)
> VALUES
> ('$firstName', '$lastName', '$dob', '$category', '$address1',
> '$address2', '$city', '$state', '$zipcode', '$telephone',
> '$cellphone', '$email1', '$email2', '$aimid', '$url', '$notes')";
>
> mysql_query ($sql, $connect) or die(mysql_error());
>
> echo "added";
> }
>
> function is called on this page
>
> HTML>
> <HEAD>
> <?PHP include("includes/headsectionp.txt")?>
> </HEAD>
>
> <BODY>
> <?PHP include("includes/connect.txt");?>
> <?PHP include("ab_functions.php");?>
> <?PHP
> if(isset($_POST['do_addperson']))
> {
> addPerson ();
> }
> ?>

In your function you are using the variable $connect. This variable is not
in the scope of the function.

You have 2 options you can do this:-

function addPerson ()
{
global $connect

I you change the start of your function to this then you will be able to use
the $connect variable within your function.

The better option however is to do this:-

function addPerson ($connect)
{

and when calling the function do addPerson($connect), this makes the
$connect variable a parameter of the function. The reason the $_POST array
works without doing this is because they are already global.
http://www.php.net/global

[Back to original 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

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