Jump to content

[SOLVED] INSERT INTO VALUES


Darkwoods

Recommended Posts

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')") ;

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.