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

From: Date: Fri, 10 Feb 2006 10:41:25 +0000
Subject: Re: <Newbie Question> Can't insert values into MySQL DB via PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230195@lists.php.net to get a copy of this message
Hi, Friday, February 10, 2006, 8:16:41 PM, you wrote: DT> Hi, DT> I'd like to say in advance that I am sorry about the silly and very newbie DT> question I'm asking. DT> I am having a problem with a shop system. I can't add values into the MySQL DT> DB via a PHP statement. The values are being transferred from one page to DT> another (know that from the echo statement), but the SQL statement isn't DT> working. DT> The statement is as follows: DT> $conn = mysql_connect($DBhost,$DBuser,$DBpass) or die('Unable to connect to DT> database'); DT> $t = $_GET['newdvdtitle']; DT> $y = $_GET['newdvdyear']; DT> $c = $_GET['newdvdcost']; DT> $p = $_GET['newdvdpurchased']; DT> @mysql_select_db("$DBName") or die("Unable to select database $DBName"); DT> $sqladd = "INSERT INTO 'dvd' ('id', 'title', DT> 'year','cost','purchased') DT> VALUES ( NULL , '$t', '$y', '$c' , '$p' )"; DT> echo $sqladd; DT> $result = mysql_query($sqladd); DT> The information is sent from another page which has the following values: DT> <form name="add" method="get" action="addvalue.php"> DT> <?php DT> echo '<table><tr><td>Insert a DVD</td></tr>'; DT> echo '<tr><td><input type="text" DT> name="newdvdtitle"> DVD name</td></tr>'; DT> echo '<tr><td><input type="text" DT> name="newdvdyear"> DVD year</td></tr>'; DT> echo '<tr><td><input type="text" DT> name="newdvdcost"> DVD cost</td></tr>'; DT> echo '<tr><td><input type="text" DT> name="newdvdpurchased"> DVD date DT> purchased</td></tr>'; DT> echo '<tr><td><input type="submit" value="Insert new DT> dvd"></td></tr>'; DT> echo '</table>'; ?>> DT> </form> DT> Thanks in advance, DT> Douglas Don't put the table name in quotes, use the back tick dvd -- regards, Tom

« previous php.general (#230195) next »