我在正在进行的大学项目中遇到此错误。每个用户都有一个配置文件,他们可以在其中上传“个人资料图片”并创建“关于我”。但是,当您尝试提交任何配置文件信息时,会发生错误...有任何想法吗?
Column count doesn't match value count at row 1
这两个与错误相关的PHP文件......
... rnprofile.php
<?php // rnprofile.php
include_once 'rnheader.php';
if (!isset($_SESSION['user']))
die("<br /><br />You need to login to view this page");
$user = $_SESSION['user'];
echo "<h3>Edit your Profile</h3>";
$UserData = mysql_fetch_assoc(mysql_query("SELECT * FROM `rnprofiles` WHERE `user` = '$user'"));//Grabbing all info on the user
//print_r($UserData);
$UserExists = ($UserData!=null) ? true : false; // Seeing if the user exists (returns true if so, false if not
/*if ($UserExists==false) {
echo "we don't exist";
exit();
}*/
?>
</br>
<div id="container_profile">
<?php
if (isset($_POST['about']))
{
$about = sanitizeString($_POST['about']);
$about = preg_replace('/\s\s+/', ' ', $about);
$query = "SELECT * FROM rnprofiles WHERE user='$user'";
if (mysql_num_rows(queryMysql($query)))
{
queryMysql("UPDATE rnprofiles SET text='$about' where user='$user'");
}
else
{
$query = "INSERT INTO rnprofiles VALUES('$user', '$about')";
queryMysql($query);
}
}
else
{
$query = "SELECT * FROM rnprofiles WHERE user='$user'";
$result = queryMysql($query);
if (mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
$about = stripslashes($row[4]);
}
else $about = "";
}
$about = stripslashes(preg_replace('/\s\s+/', ' ', $about));
if (isset($_FILES['profile']['name']))
{
$saveto = "$user.jpg";
move_uploaded_file($_FILES['profile']['tmp_name'], $saveto);
$typeok = TRUE;
switch($_FILES['profile']['type'])
{
case "profile/gif": $src = imagecreatefromgif($saveto); break;
case "profile/jpeg": // Both regular and progressive jpegs
case "profile/pjpeg": $src = imagecreatefromjpeg($saveto); break;
case "profile/png": $src = imagecreatefrompng($saveto); break;
default: $typeok = FALSE; break;
}
if ($typeok)
{
list($w, $h) = getimagesize($saveto);
$max = 600;
$tw = $w;
$th = $h;
if ($w > $h && $max < $w)
{
$th = $max / $w * $h;
$tw = $max;
}
elseif ($h > $w && $max < $h)
{
$tw = $max / $h * $w;
$th = $max;
}
elseif ($max < $w)
{
$tw = $th = $max;
}
$tmp = imagecreatetruecolor($tw, $th);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h);
imageconvolution($tmp, array( // Sharpen image
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1)
), 8, 0);
imagejpeg($tmp, $saveto);
imagedestroy($tmp);
imagedestroy($src);
}
}
Profile($user);
echo <<<_END
<form method='post' action='rnprofile.php'
enctype='multipart/form-data'>
Enter or edit your details and/or upload an image:<br />
<textarea name='about' cols='40' rows='3'>$about</textarea>
Image: <input type='file' name='profile' size='1' maxlength='32' />
<input type='submit' value='Save Profile' />
</pre></form>
_END;
... rnfunctions.php
function Profile($user)
{
if (file_exists("$user.jpg"))
echo "<p><a title='' class='fancybox' href='$user.jpg'><img src='$user.jpg' border='1' align='left' height='200' width='200' alt=''/></a></p>";
echo "</br>";
$result = queryMysql("SELECT * FROM rnprofiles WHERE user='$user'");
if (mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
echo stripslashes($row[2]) . "<br clear=left /><br />";
}
}
答案 0 :(得分:1)
看起来问题就在这里:
"INSERT INTO rnprofiles VALUES('$user', '$about')"
查询应采用以下形式:
"INSERT INTO table (column1, column2) VALUES('$column1value', '$column2value')"
虽然我没有时间查看整个代码。