Jump to content
php.lv forumi

query un php ievada datus iekš mysql


ziedinjsh

Recommended Posts

query:

$(function() {
$("#addtopic").click(function() {
var name = $("#name").val();
var title = $("#title").val();
var description = $("#description").val();
var content = $("#content").val();
var dataString = 'name='+ name + '&title='+ title + '&description'+ description + '&content'+ content;

if(name=='' || title=='' || description=='' || content=='')
{
$('.success').fadeOut(500).hide();
$('.error').fadeOut(500).show();
}
else
{
$.ajax({
type: "POST",
url: "misc/addtopic.php",
data: dataString,
success: function(){
$('.success').fadeIn(500).show();
$('.error').fadeOut(500).hide();
$('#name').fadeOut(600).val('');
$('#title').fadeOut(600).val('');
$('#description').fadeOut(600).val('');
$('#content').fadeOut(600).val('');
$('.titles').fadeOut(600).val('');
$('.button').fadeOut(600).val('');
}
});
}
return false;
});
});

formas:"

<form method='post' name='form'>

<p class='titles'>Tavs segvārds</p><p style='margin:0px;padding:0px;'><input type='text' name='name' id='name' class='inputs'></p>
<p class='titles'>Tēmas nosukums</p><p style='margin:0px;padding:0px;'><input type='text' name='title' id='title' class='inputs'></p>
<p class='titles'>Tēmas apraksts</p><p style='margin:0px;padding:0px;'><input type='text' name='description' id='description' class='inputs'></p>
<p class='titles'>Tēmas saturs</p><p style='margin:0px;padding:0px;'><textarea name='content' id='content' class='inputs2'></textarea></p>
<span class='error' style='display:none;color:red;text-align:center;'><h3>Kāds no lauciņiem ir palicis tukš.</h3></span>
<span class='success' style='display:none;color:green;text-align:center;'><h3>Paldies, tēma ir pievienota!</h3></span>
<p style='margin:0px;padding:0px;text-align:center;margin-bottom:10px;'><input type='submit' value='Pievienot' id='addtopic' class='button'></p>
</form>

addtopic.php:

$name = mysql_real_escape_string($_POST['name']);
$title = mysql_real_escape_string($_POST['title']);
$description = mysql_real_escape_string($_POST['description']);
$content = mysql_real_escape_string($_POST['content']);
$date = date("Y-m-d H:i:s");

$add = mysql_query("INSERT INTO topics (name, title, description, content, date) VALUES ('$name', '$title', '$description', '$content', '$date')") or die(mysql_error()); 

 

iekš datubāzēs pievienot tikai name, title un date, bet description un content netiek pievienosts! kapēc tā!?

Link to comment
Share on other sites

var dataString = 'name='+ name + '&title='+ title + '&description'+ description + '&content'+ content;

'&description' un '&content' vietā vajag '&description=' un '&content='

Vispār pirmo reizi redzu ka post datus šitā sagatavo, parasti tak bliež kā masīvu vai kā objektu.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...