|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in /home/smith/public_html/personal/ab_functions.php on line 30 line 30 is [mysql_query ($sql, $connect) or die(mysql_error());] 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 (); } ?> |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
my connect page is
<?PHP $db_server = "localhost"; $db_user = " "; $db_pass = " "; $db_name = "smith_website"; $db_table = "blog_category"; $db_table1 = "blog_entry"; $db_table2 = "quotes"; $db_table3 = "ab_category"; $db_table4 = "ab_person"; $connect = mysql_connect($db_server, $db_user, $db_pass) OR DIE ('I can not connect to server because: ' . mysql_error()); mysql_select_db($db_name, $connect) OR DIE ('I can not connect to database because: ' . mysql_error()); ?> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> 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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
New problem now
I made change and got: Warning: Missing argument 1 for addperson() in /home/smith/public_html/ personal/ab_functions.php on line 20 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(firstName, lastName, dob, category, address1, address2, city, state, zipcode, t' at line 2 I'm sure insert code works because if I just run it from page with form it is ok. This is the new add function function addPerson ($connect) { $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) or die(mysql_error()); echo "$db_name"; echo "added"; } |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> New problem now
> I made change and got: > > Warning: Missing argument 1 for addperson() in /home/smith/public_html/ > personal/ab_functions.php on line 20 > You have an error in your SQL syntax; check the manual that > corresponds to your MySQL server version for the right syntax to use > near '(firstName, lastName, dob, category, address1, address2, city, > state, zipcode, t' at line 2 > > I'm sure insert code works because if I just run it from page with > form it is ok. Did you change the following code as instructed:- if(isset($_POST['do_addperson'])) { addPerson (); } to the following:- if(isset($_POST['do_addperson'])) { addPerson ($connect); } The error message you posted suggests you did not. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
> $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')"; Also just noticed I presume that line is meant to actually read:- $sql = "INSERT INTO $db_table you have an eroneous 4 at the end of the table name |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Sorry, I didn't add it in original file. After adding it, i got:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(firstName, lastName, dob, category, address1, address2, city, state, zipcode, t' at line 2 function addPerson ($connect) { $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) or die(mysql_error()); echo "$db_name"; echo "added"; } <?PHP include("includes/connect.txt");?> <?PHP include("ab_functions.php");?> <?PHP if(isset($_POST['do_addperson'])) { addPerson ($connect); } ?> |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Jun 24, 5:42 pm, "peter" <sub...@flexiwebhost.com> wrote:
> > $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')"; > > Also just noticed I presume that line is meant to actually read:- > > $sql = "INSERT INTO $db_table > > you have an eroneous 4 at the end of the table name $db_server = "localhost"; $db_user = "smith_admin"; $db_pass = "password"; $db_name = "smith_website"; $db_table = "blog_category"; $db_table1 = "blog_entry"; $db_table2 = "quotes"; $db_table3 = "ab_category"; $db_table4 = "ab_person"; $connect = mysql_connect($db_server, $db_user, $db_pass) OR DIE ('I can not connect to server because: ' .mysql_errno(). " - " .mysql_error()); mysql_select_db($db_name, $connect) OR DIE ('I can not connect to server because: ' .mysql_errno(). " - " .mysql_error()); |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
|
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
> $db_server = "localhost"; > $db_user = "smith_admin"; > $db_pass = "password"; > $db_name = "smith_website"; > $db_table = "blog_category"; > $db_table1 = "blog_entry"; > $db_table2 = "quotes"; > $db_table3 = "ab_category"; > $db_table4 = "ab_person"; > > $connect = mysql_connect($db_server, $db_user, $db_pass) OR DIE ('I > can not connect to server because: ' .mysql_errno(). " - > " .mysql_error()); > mysql_select_db($db_name, $connect) OR DIE ('I can not connect to > server because: ' .mysql_errno(). " - " .mysql_error()); Ahh yes my fault never noticed that. The problem you have is similar to the $connect problem, the tables being defined outside of the function, you will need to also pass them as a parameter |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Jun 24, 7:02 pm, "peter" <sub...@flexiwebhost.com> wrote:
> > $db_server = "localhost"; > > $db_user = "smith_admin"; > > $db_pass = "password"; > > $db_name = "smith_website"; > > $db_table = "blog_category"; > > $db_table1 = "blog_entry"; > > $db_table2 = "quotes"; > > $db_table3 = "ab_category"; > > $db_table4 = "ab_person"; > > > $connect = mysql_connect($db_server, $db_user, $db_pass) OR DIE ('I > > can not connect to server because: ' .mysql_errno(). " - > > " .mysql_error()); > > mysql_select_db($db_name, $connect) OR DIE ('I can not connect to > > server because: ' .mysql_errno(). " - " .mysql_error()); > > Ahh yes my fault never noticed that. > > The problem you have is similar to the $connect problem, the tables being > defined outside of the function, you will need to also pass them as a > parameter my gratitude forever that fixed it |
|
![]() |
| Outils de la discussion | |
|
|