Darkwoods Posted October 9, 2008 Share Posted October 9, 2008 hey.. can anyone that check what i have typed wrong in this code mysql_query("INSERT INTO `changeimage` VALUES ('$name','$pic')") ; it is not sending the data to the database but if i write this way it works fine but the now date shows up in the name column mysql_query("INSERT INTO `changeimage` VALUES ('$name',NOW(),'$pic')") ; Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 9, 2008 Share Posted October 9, 2008 be more specific in your queries, define into which fields you're inserting. INSERT INTO `changeimage` (`name`, `date`, `picture`) VALUES ('$name', NOW(), '$pic') of course you replace the column names with your own. Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 be more specific in your queries, define into which fields you're inserting. INSERT INTO `changeimage` (`name`, `date`, `picture`) VALUES ('$name', NOW(), '$pic') of course you replace the column names with your own. in my database i just have 3 column id, name and photo the problem is with my insert into code is when i remove the NOW(), it wont send data to the database the VALUES should only be ('$name','$pic') so i have no idea what im doing wrong! here is the full codes <?php //This is the directory where images will be saved $target = "uploads/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("localhost", "**", "**") or die(mysql_error()) ; mysql_select_db("**") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `changeimage` VALUES ('$name',NOW(),'$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> <form enctype="multipart/form-data" action="uploadchangeimage.php" method="POST"> Name: <input type="text" name="name"><br> Photo: <input type="file" name="photo"><br> <input type="submit" value="Add"> </form> Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 9, 2008 Share Posted October 9, 2008 the problem is if you don't specify your fields you're trying to insert to the ID field which I assume is auto_increment int and can't take a name string. INSERT INTO `changeimage` (`name`, `picture`) VALUES ('$name', '$pic') Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 You really should let mysql tell you what is wrong, instead of guessing: <?php $q = "INSERT INTO `changeimage` VALUES ('$name','$pic')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> This should tell you what's wrong. Ken Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 You really should let mysql tell you what is wrong, instead of guessing: <?php $q = "INSERT INTO `changeimage` VALUES ('$name','$pic')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> This should tell you what's wrong. Ken here is error message im getting Problem with the query: INSERT INTO `changeimage` VALUES ('testname','helix.jpg') Column count doesn't match value count at row 1 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 9, 2008 Share Posted October 9, 2008 I feel like people don't listen to me. Quote Link to comment Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 I feel like people don't listen to me. sorry about that i did not see your post it is working fine now ill remember for next time to specify the fields and having mysql_error thanks problem solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.