[PHP] PHP Udate MySQL command

2010-06-04 Thread Gary
I am trying to get an update command to work in PHP.  I am able to update 
records going directly to phpmyadmin command line. I have even let it 
produce the php code to insert, but have not been able to get it to work.

I have it stripped down to one command hoping to get it to work then 
replicate entire forms for clients to use direct.I get no error codes, I 
only get my message It did not enter into DB;

Anyone see where I am going wrong?

Gary

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titleUntitled Document/title
/head

body
form action=?php echo $_SERVER['PHP_SELF']; ? method=post
testinput name=test type=text /
input name=submit type=submit value=submit /
/form

?php


$batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for board
or die('Error connecting with MySQL Database');

$test=$_POST['test'];

//$sql=update contact set type = \'$test\' where item_id = \'164\'; //this 
is the code created by phpmyadmin

 $sql = INSERT INTO contact  comments, VALUES = $test WHERE contact_id = 
33;

mysql_query($sql,$batchconnetion);

$result = mysql_query($sql,$batchconnetion);

if($result == true) {
   echo Successfully Inserted Records;
   } else {
   echo It did not enter into DB;
}

mysql_close($batchconnetion);

?


/body
/html 



__ Information from ESET Smart Security, version of virus signature 
database 5171 (20100604) __

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Udate MySQL command

2010-06-04 Thread Ashley Sheridan
On Fri, 2010-06-04 at 06:46 -0400, Gary wrote:

 I am trying to get an update command to work in PHP.  I am able to update 
 records going directly to phpmyadmin command line. I have even let it 
 produce the php code to insert, but have not been able to get it to work.
 
 I have it stripped down to one command hoping to get it to work then 
 replicate entire forms for clients to use direct.I get no error codes, I 
 only get my message It did not enter into DB;
 
 Anyone see where I am going wrong?
 
 Gary
 
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 titleUntitled Document/title
 /head
 
 body
 form action=?php echo $_SERVER['PHP_SELF']; ? method=post
 testinput name=test type=text /
 input name=submit type=submit value=submit /
 /form
 
 ?php
 
 
 $batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for board
 or die('Error connecting with MySQL Database');
 
 $test=$_POST['test'];
 
 //$sql=update contact set type = \'$test\' where item_id = \'164\'; //this 
 is the code created by phpmyadmin
 
  $sql = INSERT INTO contact  comments, VALUES = $test WHERE contact_id = 
 33;
 
 mysql_query($sql,$batchconnetion);
 
 $result = mysql_query($sql,$batchconnetion);
 
 if($result == true) {
echo Successfully Inserted Records;
} else {
echo It did not enter into DB;
 }
 
 mysql_close($batchconnetion);
 
 ?
 
 
 /body
 /html 
 
 
 
 __ Information from ESET Smart Security, version of virus signature 
 database 5171 (20100604) __
 
 The message was checked by ESET Smart Security.
 
 http://www.eset.com
 
 
 
 
 

Your problem is the way you're trying to connect to the DB:

$batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for
board
or die('Error connecting with MySQL Database');

The 4th argument to this function isn't a database name, it's a boolean
value for whether PHP should create a new link or reuse the old one. You
have to use the mysql_select_db() function to select the database to use
on that connection in order for your queries to run the way you have
them.

There does seem to be a bit of an inconsistency with the way you're
using quotation marks on your query strings as well. Your first
commented out query is escaping the single quotes within a double quoted
string (which isn't necessary), you've omitted the single quotes on your
insert line, and then on your amended email you've omitted the double
quotes. If this is your actual code and not a mistake made when copying
it into an email, then it would also be a second reason why things
aren't working as expected even once you get PHP to connect properly.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] PHP Udate MySQL command

2010-06-04 Thread Gary

Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1275649100.2217.45.ca...@localhost...
 On Fri, 2010-06-04 at 06:46 -0400, Gary wrote:

 I am trying to get an update command to work in PHP.  I am able to update
 records going directly to phpmyadmin command line. I have even let it
 produce the php code to insert, but have not been able to get it to work.

 I have it stripped down to one command hoping to get it to work then
 replicate entire forms for clients to use direct.I get no error codes, I
 only get my message It did not enter into DB;

 Anyone see where I am going wrong?

 Gary

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 titleUntitled Document/title
 /head

 body
 form action=?php echo $_SERVER['PHP_SELF']; ? method=post
 testinput name=test type=text /
 input name=submit type=submit value=submit /
 /form

 ?php


 $batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for 
 board
 or die('Error connecting with MySQL Database');

 $test=$_POST['test'];

 //$sql=update contact set type = \'$test\' where item_id = \'164\'; 
 //this
 is the code created by phpmyadmin

  $sql = INSERT INTO contact  comments, VALUES = $test WHERE contact_id =
 33;

 mysql_query($sql,$batchconnetion);

 $result = mysql_query($sql,$batchconnetion);

 if($result == true) {
echo Successfully Inserted Records;
} else {
echo It did not enter into DB;
 }

 mysql_close($batchconnetion);

 ?


 /body
 /html



 __ Information from ESET Smart Security, version of virus 
 signature database 5171 (20100604) __

 The message was checked by ESET Smart Security.

 http://www.eset.com






 Your problem is the way you're trying to connect to the DB:

 $batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for
 board
 or die('Error connecting with MySQL Database');

 The 4th argument to this function isn't a database name, it's a boolean
 value for whether PHP should create a new link or reuse the old one. You
 have to use the mysql_select_db() function to select the database to use
 on that connection in order for your queries to run the way you have
 them.

 There does seem to be a bit of an inconsistency with the way you're
 using quotation marks on your query strings as well. Your first
 commented out query is escaping the single quotes within a double quoted
 string (which isn't necessary), you've omitted the single quotes on your
 insert line, and then on your amended email you've omitted the double
 quotes. If this is your actual code and not a mistake made when copying
 it into an email, then it would also be a second reason why things
 aren't working as expected even once you get PHP to connect properly.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





 __ Information from ESET Smart Security, version of virus 
 signature database 5171 (20100604) __

 The message was checked by ESET Smart Security.

 http://www.eset.com



Ashley

Thank you for your quick reply.

The $batchconnection works fine in numerous other files (the insert files) 
and is a c/p from one of those files. The db noted in my post was just to 
specify that the name of the database at this point, I thought it was a 
standard practice.  I will try your suggestion.

I will admit that I dont have the full grasp of the quotes, single or 
double.  Typically in a mysql command I start with a , however if I get a 
script that is not working, I will try to resolve the issue with switching 
up the singles with the doubles as well and adding parenthsis.

The mistake in the copying the code was I was trying to see if the insert 
command would work in place of the update.it did not..

Aside from that, do you see a problem with my update commands?

Thanks for your help.

gary




__ Information from ESET Smart Security, version of virus signature 
database 5171 (20100604) __

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Udate MySQL command Success

2010-06-04 Thread Gary

Gary gwp...@ptd.net wrote in message 
news:a9.ea.07323.381e8...@pb1.pair.com...

 Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
 news:1275649100.2217.45.ca...@localhost...
 On Fri, 2010-06-04 at 06:46 -0400, Gary wrote:

 I am trying to get an update command to work in PHP.  I am able to 
 update
 records going directly to phpmyadmin command line. I have even let it
 produce the php code to insert, but have not been able to get it to 
 work.

 I have it stripped down to one command hoping to get it to work then
 replicate entire forms for clients to use direct.I get no error codes, I
 only get my message It did not enter into DB;

 Anyone see where I am going wrong?

 Gary

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 titleUntitled Document/title
 /head

 body
 form action=?php echo $_SERVER['PHP_SELF']; ? method=post
 testinput name=test type=text /
 input name=submit type=submit value=submit /
 /form

 ?php


 $batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for 
 board
 or die('Error connecting with MySQL Database');

 $test=$_POST['test'];

 //$sql=update contact set type = \'$test\' where item_id = \'164\'; 
 //this
 is the code created by phpmyadmin

  $sql = INSERT INTO contact  comments, VALUES = $test WHERE contact_id 
 =
 33;

 mysql_query($sql,$batchconnetion);

 $result = mysql_query($sql,$batchconnetion);

 if($result == true) {
echo Successfully Inserted Records;
} else {
echo It did not enter into DB;
 }

 mysql_close($batchconnetion);

 ?


 /body
 /html



 __ Information from ESET Smart Security, version of virus 
 signature database 5171 (20100604) __

 The message was checked by ESET Smart Security.

 http://www.eset.com






 Your problem is the way you're trying to connect to the DB:

 $batchconnetion = mysql_connect(host, 'un', 'pw', 'db')//sanatized for
 board
 or die('Error connecting with MySQL Database');

 The 4th argument to this function isn't a database name, it's a boolean
 value for whether PHP should create a new link or reuse the old one. You
 have to use the mysql_select_db() function to select the database to use
 on that connection in order for your queries to run the way you have
 them.

 There does seem to be a bit of an inconsistency with the way you're
 using quotation marks on your query strings as well. Your first
 commented out query is escaping the single quotes within a double quoted
 string (which isn't necessary), you've omitted the single quotes on your
 insert line, and then on your amended email you've omitted the double
 quotes. If this is your actual code and not a mistake made when copying
 it into an email, then it would also be a second reason why things
 aren't working as expected even once you get PHP to connect properly.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





 __ Information from ESET Smart Security, version of virus 
 signature database 5171 (20100604) __

 The message was checked by ESET Smart Security.

 http://www.eset.com



 Ashley

 Thank you for your quick reply.

 The $batchconnection works fine in numerous other files (the insert files) 
 and is a c/p from one of those files. The db noted in my post was just to 
 specify that the name of the database at this point, I thought it was a 
 standard practice.  I will try your suggestion.

 I will admit that I dont have the full grasp of the quotes, single or 
 double.  Typically in a mysql command I start with a , however if I get a 
 script that is not working, I will try to resolve the issue with switching 
 up the singles with the doubles as well and adding parenthsis.

 The mistake in the copying the code was I was trying to see if the insert 
 command would work in place of the update.it did not..

 Aside from that, do you see a problem with my update commands?

 Thanks for your help.

 gary




 __ Information from ESET Smart Security, version of virus 
 signature database 5171 (20100604) __

 The message was checked by ESET Smart Security.

 http://www.eset.com





Ashley

Thanks for your input, I think what corrected the problem was I added single
qoutes to the $test variable.

I did also change to your suggestion.

The working code is

body
form action=?php echo $_SERVER['PHP_SELF']; ? method=post
testinput name=test type=text /
input name=submit type=submit value=submit /
/form

?php


$batchconnetion = mysql_connect(sanatized)
or die('Error connecting with MySQL Database');
mysql_select_db('sanatized', $batchconnetion)or die('Error connecting with
MySQL Database2');;
$test=$_POST['test'];

//$sql=update contact set type = \'$test\' where item_id = \'164\';

 $sql = UPDATE contact  SET comments = '$test' WHERE contact_id = 33;

mysql_query($sql,$batchconnetion);


$result =