Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Anomaly , mysql insert doesnt work

Codes here !

Moderators: macek, egami, gesf

Anomaly , mysql insert doesnt work

Postby Kostikz » Wed Oct 03, 2012 9:35 am

Hello i creating code which let you add news to database but it doesnt work , however , his copy code works perfect! And i dont know where is problem :(
I will give 2 codes one html and other is PHP which makes all work. Please help couse it my exam test :(
HTML:

Code: Select all
<?php 
require ("../database/connect.php");
include ('../database/functions.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
      <?php
      trackgoogle();
      ?>
<form action="sukurtiSkelbimaScriptas.php" method="post">
<b>*Vardas ir Pavarde</b>
<br>
<input type="text" name="VardasPavarde" size="40" maxlength="80" value="">
<br>
<br>
<b>Nuotrauka (Prasome irasyti visa adresa)</b><BR><input type="text" name="Nuotrauka" size="40" maxlength="140" value="">
<!--
<br>
Or Upload Own(Doesnt work)
<br>
<input type="file" name="Image" id="Image" />
-->
<br>
<br>
<b>Gimimo Metai</b><BR><input type="text" name="GimimoMetai" size="40" maxlength="12" value="">
<br>
<br>
<b>*&#154;alys: </b><BR><input type="text" name="Salys" size="40" maxlength="40" value="">
<br>
<br>
<b>*Miestas </b><BR><input type="text" name="Miestas" size="40" maxlength="40" value="">
<br>
<br>
<b>*Lytis </b><BR><input type="text" name="Lytis" size="40" maxlength="40" value="">
<br>
<br>
<b>*Dingo: </b><BR><input type="text" name="Dingo" size="40" maxlength="40" value="">
<br>
<br>
<b>*Apibudinimas: </b><BR><textarea name="Apibudinimas" rows="3" cols="40"></textarea>
<br>
<br>



<b>Iesko :</b>
<br>
<input type="text" name="Inkele" size="30" maxlength="40" value="">
<br>
<br>
<input type="submit" value="submit"> <input type="reset" value="reset">
<a href="../../index.php"><input type="button" value="Sugri&#154;ti"></a>
<h2> * - Viskas kas pazymeta juo reika BUTINAI u&#158;pildyti! </h2>
</form>
</body>
</html>


PHP:

Code: Select all
<?php
require ('../database/connect.php');

   $VardasPavarde = mysql_real_escape_string($_POST["VardasPavarde"]);
   $GimimoMetai = mysql_real_escape_string($_POST["GimimoMetai"]);
   $Salys = $_POST["Salys"];
   $Miestas = $_POST["Miestas"];
   $Lytis = $_POST["Lytis"];
   $Dingo = mysql_real_escape_string($_POST["Dingo"]);
   $Apibudinimas = $_POST["Apibudinimas"];
   $Nuotrauka = $_POST["Nuotrauka"];
   $Statusas = "IESKOMAS";
   $DATA = date('l \t\h\e jS');
   $Inkele = mysql_real_escape_string($_POST["Inkele"]);
   
   if(!empty($_POST['VardasPavarde']) && !empty($_POST['Dingo']) && !empty($_POST['Apibudinimas'])) {
      // Connected
      // Now inserting News
      if (!$Inkele) $Inkele = "Ne&#158;inomas";
         $Inkelti = mysql_query("INSERT INTO `Ieskomi`(ID, VardasPavarde, GimimoMetai, Salys, Miestas, Lytis, Dingo, Apibudinimas, Nuotrauka, Statusas, KadaInkele, Inkele)
         VALUES(NULL, '".$VardasPavarde."', '".$GimimoMetai."', '".$Salys."', '".$Miestas."', '".$Lytis."' '".$Dingo."', '".$Apibudinimas."', '".$Nuotrauka."', '".$Statusas."', '".$DATA."', '".$Inkele."')");
         echo("Skelbimas Patalpinta!<br>");
         echo("<a href=\"../../index.php\">Pagrindinis Puslapis</a><br>");
         echo("<a href=\"sukurtiSkelbima.php\">Sugri&#154;ti</a><br>");
   } elseif(!$VardasPavarde) {
      echo("Pra&#154;ome ira&#154;yti dingusio &#158;mogaus varda ir pavarde.");
      echo("<a href=\"sukurtiSkelbima.php\">Sugri&#154;ti</a><br>");
   } elseif(!$Dingo) {
      echo("Pra&#154;ome ivesti diena kai dinko &#158;mogus.");
      echo("<a href=\"sukurtiSkelbima.php\">Sugri&#154;ti</a><br>");
   } elseif(!$Apibudinimas || !$Lytis || !$Miestas)   {
      echo("Noredami greiciau rasti dingusi , pra&#154;ome suteikti daugau informacijos apie ji(a).");
      echo("<a href=\"sukurtiSkelbima.php\">Sugri&#154;ti</a><br>");
}
?>
Kostikz
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Oct 03, 2012 9:30 am

Re: Anomaly , mysql insert doesnt work

Postby rwhite35 » Wed Oct 03, 2012 10:50 am

Instead of the literal and double quotes, try it with just the literals.

Code: Select all
$Inkelti = mysql_query("INSERT INTO `Ieskomi`(ID, VardasPavarde, GimimoMetai, Salys, Miestas, Lytis, Dingo, Apibudinimas, Nuotrauka, Statusas, KadaInkele, Inkele)
         VALUES(NULL, '$VardasPavarde', '$GimimoMetai', '$Salys', '$Miestas', '$Lytis' '$Dingo', '$Apibudinimas', '$Nuotrauka', '$Statusas', '$DATA', '$Inkele')");


Also if the column tab order is the same as your value list, you can shorten the INSERT statement to:

Code: Select all
$Inkelti = mysql_query("INSERT INTO `Ieskomi` VALUES('', '$VardasPavarde', '$GimimoMetai', '$Salys', '$Miestas', '$Lytis' '$Dingo', '$Apibudinimas', '$Nuotrauka', '$Statusas', '$DATA', '$Inkele')");


Note that the first value (ID) is empty. This assumes you are auto_incrementing the column. Finally, you should consider using prepared statements instead mysql_* functions.

Good luck
rwhite35
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu Sep 27, 2012 10:55 am

Re: Anomaly , mysql insert doesnt work

Postby Kostikz » Thu Oct 04, 2012 4:08 am

I dont know i tried , as you said but it dosnt work :( , I VERIFY mysql, and it is correct to database :| , please help :(
Kostikz
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Oct 03, 2012 9:30 am

Re: Anomaly , mysql insert doesnt work

Postby Kostikz » Sat Oct 06, 2012 3:01 am

any one? :(
Kostikz
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Oct 03, 2012 9:30 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron