RE: Re: <Newbie Question> Can't insert values into MySQL DB via PHP

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

 



Also when specifying the field list (and table name) it may be a better idea
to wrap the values in backticks (`) rather than quotes (')

Always works for me

Dan

-----Original Message-----
From: Barry [mailto:barry@xxxxxxxxxxxxxx] 
Sent: 10 February 2006 10:31
To: php-general@xxxxxxxxxxxxx
Subject:  Re: <Newbie Question> Can't insert values into MySQL DB via
PHP

Duggles Temple wrote:
> Hi,
> 
> I'd like to say in advance that I am sorry about the silly and very newbie
> question I'm asking.
> 
> I am having a problem with a shop system. I can't add values into the
MySQL
> DB via a PHP statement. The values are being transferred from one page to
> another (know that from the echo statement), but the SQL statement isn't
> working.
> 

What error do you get?


> The statement is as follows:
> 
> $conn = mysql_connect($DBhost,$DBuser,$DBpass) or die('Unable to connect
to
> database');
> $t = $_GET['newdvdtitle'];
> $y = $_GET['newdvdyear'];
> $c = $_GET['newdvdcost'];
> $p = $_GET['newdvdpurchased'];
> @mysql_select_db("$DBName") or die("Unable to select database $DBName");
> $sqladd = "INSERT INTO 'dvd' ('id', 'title', 'year','cost','purchased')
> VALUES (  NULL , '$t', '$y', '$c' , '$p' )";
> echo $sqladd;
> $result = mysql_query($sqladd);

Insert Into dvd (title, year,cost,purchased)

When the id is auto_increment you dont have to add it to the query.
Barry


-- 
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

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

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


[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