Jump to content
php.lv forumi

INSERT INTO


BRabbit

Recommended Posts

Sveiki.

Tātad es meiģinu dabūt iekš datubāzes uzrakstīto informāciju, bet nekas nesanāk, un nekādu erroru ari nav! :(

Esmu jauniņais @ PHP! :D

 

Kodi:

form.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="lv">
<head>
<meta charset="utf-8" />
<meta name="keywords" content="huh.lv, help, forum, php, css, html, psd, js. skripti" />
<meta name="description" content="HUH.LV - Help forum, join us" />
<title>HUH.LV - Help forum</title>
<link rel="stylesheet" href="style_css/main_style.css" />  
<link rel="stylesheet" href="style_css/menu_style.css" />
</head>
<body>
<form name="post news" action="insert.php" method="post">
Title: <input type="text" name="title" />
Text: <input type="text" name="text" />
<input type="submit" name="Submit" value="SUBMIT" />
</form>
</body>
</html>

 

insert.php

<?
include('connect.php');
$query = "INSERT INTO news(title, text)VALUES('".$_POST['title']."','".$_POST['text']."', now())";
mysql_query($query);
?>

 

connect.php

 

<?php

$connect = mysql_connect('localhost','user','12345') or die(mysql_error());
$select_db = mysql_select_db('home', $connect) or die (mysql_error());
$result = mysql_query('SELECT * FROM news ORDER BY id') or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>

Edited by BRabbit
Link to comment
Share on other sites

Tev kļūda vaicājumā, Tu norādi divas kolonas: title un text, bet ievietot centies trīs, liekot klāt vēl now().

 

Nav izveidota eskeipošana, tāpēc nevarēsi ievietot rezervētus simbolus, piemēram apostrofu, vienlaicīgi tas ir arī nedroši.

 

Paskaties šo mysql_real_escape_string un pameklē googlē "sql injection".

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...