i have made a script that adds to a tabel in mysql, one problem is, even though it echos that it worked. it doesnt add them :(

<?php
$dbhost = 'localhost';
$dbuser = 'tezzana_cams';
$dbpass = '**********';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
echo ("Connected...");
$dbname = 'tezzana_camera';
mysql_select_db($dbname);
echo ("Selected...");
mysql_query("INSERT INTO `camera` (`id`, `name`, `type`, `link`) VALUES (' ', 'noob cam 2', 'webcam', 'www.alinktothecam.com');");
echo ("Added...");
mysql_close();
echo ("Closed.");
?>

There are a couple issues here:

  1. You don't need to put single-quotes around the table name or the field names. Most table formats do not allow empty id fields. If you want it to autofill the number and you have the table set up to do so, just omit the id field from the query. It should look like this:
    INSERT INTO camera (name, type, link) VALUES ('noob cam 2', 'webcam', 'www.alinktothecam.com');
  2. Your program doesn't do any checking to see if the query actually works, it just prints "Added...". So of course it's going to tell you that it worked every time, you told it to.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.