0

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.");
?>
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by chrisbliss18
0

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.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.