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

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

 



Jochem Maas wrote:

Duggles Temple wrote:


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.

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;


using echo to find out whats' in your variable is a good start, also
take a look a print_r() and var_dump() - they given more feedback regarding
passed in vars.

it would have been useful if you had actually posted the output of the
echo statement.

$result = mysql_query($sqladd);


try adding something like:

if (!$result) {
    die(mysql_errno($conn) . ": " . mysql_error($conn) . "\n")
}


Very good habit to be into.  Also, adding the query will help during
the "debugging phase" of development.  I generally use something like:

mysql_query("$query") or die("Error in query: query was $query and MySql sez: ".mysql_error());

If, as the continuing thread suggests, the query is actually empty,
the above would make that rather obvious right away.

HTH,

Kevin Kinsey

--
Adler's Distinction:
	Language is all that separates us from the lower animals,
	and from the bureaucrats.

--
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