Jump to content
php.lv forumi

AJAX INSERT


Recommended Posts

Esmu sācis mācīties Ajax un man te kaut kas nesanāk. Kods:

 

http://paste.php.lv/48c21b2f980a1d669e6a298549dc3738?lang=javascript

 

un

 

<!-- Verify if user exists for login -->
<?php
include("include/header.php");
if(isset($_GET['name'])){

$namez= mysql_real_escape_string($_GET['name']);

$insertSite_sql = "INSERT INTO categories (name) VALUES ($namez)";
$insertSite= mysql_query($insertSite_sql) or die(mysql_error());

//<!-- If is set URL variables and insert is ok, show the site name -->
echo $namez;
} else {
echo 'Error! Please fill all fileds!';
}

headerī.php notiek piekonektēšanās pie db.

Vienmēr, kad kaut ko ierakstu, izmet: Unknown column 'Celtniecība' in 'field list'

 

tabulas struktūra:

CREATE TABLE `categories` (
 `id` int(11) NOT NULL auto_increment,
 `name` varchar(255) collate utf8_latvian_ci NOT NULL,
 `main_category` int(11) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_latvian_ci AUTO_INCREMENT=5 ;

Link to post
Share on other sites

kļūdai nav nekāda sakara ar ajax ;)

$namez= "'" . mysql_real_escape_string($_GET['name']) . "'";

vērtības priekš varchar laukiem sqlā padod kā tekstu, kas ir ielikts apostrofos

Edited by 2easy
Link to post
Share on other sites

Cik nu mazak - paskaties cik jQuery ir rindinu :)

 

jQuery ir verts likt, ja ir paliels uzsvars uz AJAX lapa un/vai tiek izmantotas visadas DOM manipulacijas n stuff. Turpretim, ja tikai viena vieta ir mazins AJAX'ins, tad jQuery ir overkill...

Link to post
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...