Re: PHP Udate MySQL command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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" />
> <title>Untitled Document</title>
> </head>
> 
> <body>
> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
> test<input 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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux