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.
don't be - life's too short.
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
we generally call this submitting/posting. although it seems that technically your using the GET mechanism. passing variables from one page to another can be construed as meaning something quite different.
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") }
The information is sent from another page which has the following values: <form name="add" method="get" action="addvalue.php"> <?php echo '<table><tr><td>Insert a DVD</td></tr>'; echo '<tr><td><input type="text" name="newdvdtitle"> DVD name</td></tr>'; echo '<tr><td><input type="text" name="newdvdyear"> DVD year</td></tr>'; echo '<tr><td><input type="text" name="newdvdcost"> DVD cost</td></tr>'; echo '<tr><td><input type="text" name="newdvdpurchased"> DVD date purchased</td></tr>'; echo '<tr><td><input type="submit" value="Insert new dvd"></td></tr>'; echo '</table>'; ?> </form> Thanks in advance, Douglas
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php