我正在使用<?php
$encryptedpassword = md5($_POST['password']);
$db_myHost = "SERVERNAME";
$db_myUser= "sa";
$db_myPassword = "PASWORD";
$db_myDatabase = "DATABASE"
$dbconn = new PDO("sqlsrv:server=$db_myHost;Database=$db_myDatabase",$db_myUser,$db_myPassword);
try
{
$dbPDO = new PDO('sqlsrv:server='.$db_myHost.';Database='.$db_myDatabase, $db_myUser, $db_myPassword);
$dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
echo "Error!: " . $e->getMessage() . "
";
die();
}
//Check user credentials
$sth = $dbconn->prepare("SELECT * FROM wblgntst WHERE uname = :username AND upass = :password");
//CODE CAUSING ISSUE
$sth->execute(array("uname" => $_POST["username"], "upass" => $encryptedpassword));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
session_start();
$_SESSION['userName'] = $row['uname'];
header("Location: list.php");
}
?>
,我在管理表单覆盖方面遇到了一些问题。我创建了下一个代码来更改multichoice字段的小部件。
Django ModelForms
当我保存时,我收到此错误:media_outlet = forms.ModelMultipleChoiceField(
label= _(u'Media outlet'),
queryset=MediaOutlet.objects.all(),
widget=forms.CheckboxSelectMultiple()
)
。有没有办法验证或定义编码?当我选择其他值时,这是另一个错误:UnicodeDecodeError
。
回溯:
"Entry.media_outlet" must be a "MediaOutlet" instance
这是模型
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
551. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
224. return view(request, *args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
1508. return self.changeform_view(request, None, form_url, extra_context)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
1408. return self._changeform_view(request, object_id, form_url, extra_context)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/contrib/admin/options.py" in _changeform_view
1440. if form.is_valid():
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
183. return self.is_bound and not self.errors
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/forms/forms.py" in errors
175. self.full_clean()
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
386. self._post_clean()
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/forms/models.py" in _post_clean
403. self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/forms/models.py" in construct_instance
65. f.save_form_data(instance, cleaned_data[f.name])
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in save_form_data
853. setattr(instance, self.name, data)
File "/Users/lebel/WebProjects/mediacorruption/env/lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py" in __set__
216. self.field.remote_field.model._meta.object_name,
Exception Type: UnicodeDecodeError at /admin/dc_report/entry/add/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128)
任何想法都会发生吗?
感谢。