473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

I can't store in database from my form

elen
4
hi!
I wish for your help! I have a form and i want to store the results to my database and show me back what i sent to database,but my php script won't work.Can somebody help me ?I'm new in php

This is my html code for a form:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>ΦΟΡΜΑ ΣΤΟΙΧΕΙΩΝ ΤΑΥΤΟΤΗΤΑΣ ΑΣΘΕΝΟΥΣ</title>
  4. </head>
  5. <body bgcolor='fffaaa'>
  6. <form action="result_insert_stoixeia_tayt.php",method=post>
  7.  
  8. <table border=10 bgcolor=#aaafff align=center>
  9.  
  10. <tr bgcolor=#aaafff>
  11.   <td width=200> Επώνυμο συζύγου</td>
  12.   <td align=center ><input type="text" name="eponumsyzygval" size=20 maxlength=20></td>
  13. </tr>
  14.  
  15.  
  16. <tr bgcolor=#aaafff>
  17.   <td width=200> Επώνυμο πατρός</td>
  18.   <td align=center ><input type="text" name="eponumpatrval" size=20 maxlength=20></td>
  19. </tr>
  20.  
  21.  
  22. <tr bgcolor=#aaafff>
  23.   <td width=200> Όνομα</td>
  24.   <td align=center ><input type="text" name="onomval" size=20 maxlength=20></td>
  25. </tr>
  26.  
  27.  
  28.  
  29. <tr bgcolor=#aaafff>
  30.   <td width=200> Όνομα συζύγου</td>
  31.   <td align=center ><input type="text" name="onomsyzygval" size=20 maxlength=20></td>
  32. </tr>
  33.  
  34.  
  35.  
  36.  
  37. <tr bgcolor=#aaafff>
  38.   <td width=200> Όνομα πατρός</td>
  39.   <td align=center ><input type="text" name="onompatrval" size=20 maxlength=20></td>
  40. </tr>
  41.  
  42.  
  43.  
  44.  
  45.  
  46. <tr bgcolor=#aaafff>
  47.   <td width=200> Επάγγελμα</td>
  48.   <td align=center ><input type="text" name="epaggelval" size=20 maxlength=20></td>
  49. </tr>
  50.  
  51.  
  52.  
  53.  
  54.  
  55. <tr bgcolor=#aaafff>
  56.   <td width=200> Επάγγελμα συζύγου</td>
  57.   <td align=center ><input type="text" name="epaggelsyzygval" size=20 maxlength=20></td>
  58. </tr>
  59.  
  60.  
  61.  
  62.  
  63.  
  64. <tr bgcolor=#aaafff>
  65.   <td width=200> Ημερ/νία γέννησης</td>
  66.   <td align=center ><input type="text" name="imergenval" size=20 maxlength=20></td>
  67. </tr>
  68.  
  69.  
  70.  
  71.  
  72. <tr bgcolor=#aaafff>
  73.   <td width=200> Τόπος καταγωγής</td>
  74.   <td align=center ><input type="text" name="toposkatagval" size=20 maxlength=20></td>
  75. </tr>
  76.  
  77.  
  78.  
  79.  
  80.  
  81. <tr bgcolor=#aaafff>
  82.   <td width=200> Ασφαλιστικός Οργανισμός</td>
  83.   <td align=center ><input type="text" name="asfalistorgval" size=20 maxlength=20></td>
  84. </tr>
  85.  
  86.  
  87.  
  88.  
  89. <tr bgcolor=#aaafff>
  90.   <td width=200> Αρ.Αστυν.Ταυτότητας</td>
  91.   <td align=center ><input type="text" name="ap_ast_tayt" size=20 maxlength=20></td>
  92. </tr>
  93.  
  94.  
  95.  
  96.  
  97. <tr bgcolor=#aaafff>
  98.   <td width=200> Διεύθυνση</td>
  99.   <td align=center ><input type="date" name="dieythval" size=20 maxlength=20></td>
  100. </tr>
  101.  
  102.  
  103.  
  104.  
  105. <tr bgcolor=#aaafff>
  106.   <td width=200> Τηλέφωνο1</td>
  107.   <td align=center ><input type="text" name="til1val" size=20 maxlength=20></td>
  108. </tr>
  109.  
  110.  
  111. <tr bgcolor=#aaafff>
  112.   <td width=200> Τηλέφωνο2</td>
  113.   <td align=center ><input type="text" name="til2val" size=20 maxlength=20></td>
  114. </tr>
  115.  
  116.  
  117. <tr bgcolor=#aaafff>
  118.   <td colspan=2 align=center><input type=submit name=submit value="Καταχώρηση στοιχείων ταυτότητας"></td>
  119. </tr>
  120. </table>
  121. </form>
  122. </body>
  123. </html>
  124.  
  125. and this is the php script result_insert_stoixeia_tayt.php :
  126.  
  127.  
  128.  
  129. <?php
  130. $db = mysql_connect("127.0.0.1", "root");
  131. mysql_select_db("eleni");
  132.  
  133.  
  134.  
  135.  
  136.  
  137.   $sqlp = mysql_query("SELECT * FROM asthenis where ap_ast_tayt='$_POST[ap_ast_tayt]'");
  138.   $res = mysql_num_rows($sqlp);
  139.  
  140.  
  141. if (($_POST["eponumsyzygval"]!="")&&($_POST["onomval"]!="")&&($_POST["artaytval"]!=""))
  142. {
  143.  
  144.   if($res==0)
  145.   {
  146.      $sql = mysql_query("INSERT INTO asthenis VALUES ('$_POST[eponumsyzygval]', '$_POST[eponumpatrval]', '$_POST[onomval]', '$_POST[onomsyzygval]', '$_POST[onompatrval]', '$_POST[epaggelval]', '$_POST[epaggelsyzygval]', '$_POST[imergenval]', '$_POST[toposkatagval]', '$_POST[asfalistorgval]', '$_POST[ap_ast_tayt]', '$_POST[dieythval]', '$_POST[til1val]', '$_POST[til2val]')");
  147.  
  148.      $sql = mysql_query("SELECT * FROM asthenis WHERE ap_ast_tayt='$_POST[ap_ast_tayt]'");
  149.      $r = mysql_num_rows($sql);
  150.      if($r==0)
  151.        echo "<p>Η καταχώρηση σας δεν έγινε λόγω λάθους δεδομένων.Παρακαλώ προσπαθήστε ξανά<br>";
  152.      else
  153.      {
  154.        echo "<b><h2>Πραγματοποιήσατε επιτυχή εισαγωγή των στοιχείων της ασθενούς στη Βάση Δεδομένων</h2></b>";
  155.        echo "<br>";
  156.        echo " <b>Επώνυμο συζύγου:      </b>".$_POST["eponumsyzygval"]."<br>";
  157.        echo " <b>Επώνυμο πατρός:      </b>".$_POST["eponumpatrval"]."<br>";
  158.        echo " <b>Όνομα:      </b>".$_POST["onomval"]."<br>";
  159.        echo " <b>Όνομα συζύγου:      </b>".$_POST["onomsyzygval"]."<br>";
  160.        echo " <b>Όνομα πατρός:      </b>".$_POST["onompatrval"]."<br>";
  161.        echo " <b>Επάγγελμα:      </b>".$_POST["epaggelval"]."<br>";
  162.        echo " <b>Επάγγελμα συζύγου:      </b>".$_POST["epaggelsyzygval"]."<br>";
  163.        echo " <b>Ημερ/νία γέννησης:      </b>".$_POST["imergenval"]."<br>";
  164.        echo " <b>Τόπος καταγωγής:      </b>".$_POST["toposkatagval"]."<br>";
  165.        echo " <b>Ασφαλιστικός οργανισμός:      </b>".$_POST["asfalistorgval"]."<br>";
  166.        echo " <b>Αρ.Αστυν.Ταυτότητας:      </b>".$_POST["ap_ast_tayt"]."<br>";
  167.        echo " <b>Διεύθυνση:      </b>".$_POST["dieythval"]."<br>";
  168.        echo " <b>Τηλέφωνο1:      </b>".$_POST["til1val"]."<br>";
  169.        echo " <b>Τηλέφωνο2:      </b>".$_POST["til2val"]."<br>";
  170.     }
  171.   }
  172.   else
  173.     echo "<p>Υπάρχει ήδη καταχώρηση με αυτόν τον αριθμό ταυτότητας ";
  174. }
  175. else
  176.  
  177.     echo"<p>Τα πεδία επώνυμο συζύγου,όνομα ασθενούς και αριθμός αστυνομικής ταυτότητας δεν πρέπει να είναι κενά ";
  178.  
  179. ?>
  180.  
and this is the database and the table:
Expand|Select|Wrap|Line Numbers
  1. create database 'eleni';
  2. connect eleni;
  3. create table asthenis(
  4.        eponimo_sizigou varchar(20) not null,
  5.        eponimo_patros varchar(20) ,
  6.        onoma varchar(20) not null,
  7.        onoma_sizigou varchar(20) ,
  8.        onoma_patros varchar(20) ,
  9.        epaggelma varchar(20) ,
  10.        epaggelma_sizigou varchar(20) ,
  11.        hmerominia_gennisis date,
  12.        topos_katagogis varchar(20) ,
  13.        asfalistikos_org varchar(20) ,
  14.        ap_ast_tayt varchar(10) not null,
  15.        dieythinsi varchar(20) ,
  16.        tilefwno1 int(20),
  17.        tilefwno2 int(20),
  18.        primary key (ap_ast_tayt));
  19.  
Sep 9 '08 #1
4 1830
Atli
5,058 Expert 4TB
Hi. Welcome to Bytes!

Exactly how is the code not working?
What isn't it doing that it should be doing?
What is it doing that it shouldn't be doing.

Are you getting any error messages?
How you tried to turn on the debug messages?

Also, use [code] tags when posting code examples.
Please read the Posting Guidelines before posting.

Thank you
Sep 9 '08 #2
chelvan
90
why you not trying this syntax for the insert
Expand|Select|Wrap|Line Numbers
  1. $sql_ins=mysql_query("INSERT INTO [table_name] [inserting field names] VALUES ([inserting value])");
  2.  
table_name=your table name;
inserting field names=table colums;
inserting value=your variable;

this above kind syntax worked.
but i'm not sure about your syntax.


regards
chel-1
Sep 10 '08 #3
nine72
21
This works for me each time so have stuck with it....


ADD TO YOUR FORM

Expand|Select|Wrap|Line Numbers
  1. <?PHP
  2.     // before your session_start()
  3.     require_once('Connections/connect_to_your_db.php');
  4.     require_once('db_insert/insert_form_data.php');
  5. ?>
  6.  
  7. <form method="POST" name="name_of_form" action="<?php echo $editFormAction; ?>">
  8. <input type="hidden" name="MM_insert" value="name_of_form">
  9. </form>
  10.  


Create the include_once file insert_form_data.php...
[PHP]
<?PHP

session_start();

require_once('../../Connections/your_db_connection_page.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "name_of_form")) {
$insertSQL = sprintf("INSERT INTO fe (eponumsyzygval, eponumpatrval, onomval, onomsyzygval, onompatrval, epaggelval, epaggelsyzygval, imergenval, toposkatagval, asfalistorgval, ap_ast_tayt, dieythval, til1val, til2val) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['eponumsyzygval'], "text"),
GetSQLValueString($_POST['eponumpatrval'], "text"),
GetSQLValueString($_POST['onomval'], "text"),
GetSQLValueString($_POST['onomsyzygval'], "text"),
GetSQLValueString($_POST['onompatrval'], "text"),
GetSQLValueString($_POST['epaggelval'], "text"),
GetSQLValueString($_POST['epaggelsyzygval'], "text"),
GetSQLValueString($_POST['imergenval'], "text"),
GetSQLValueString($_POST['toposkatagval'], "text"),
GetSQLValueString($_POST['asfalistorgval'], "text"),
GetSQLValueString($_POST['ap_ast_tayt'], "text"),
GetSQLValueString($_POST['dieythval'], "text"),
GetSQLValueString($_POST['til1val'], "text"),
GetSQLValueString($_POST['til2val'], "text")
);

mysql_select_db($database_yourdb, $yourdb);
$Result1 = mysql_query($insertSQL, $yourdb) or die(mysql_error());

$insertGoTo = "page_to_go_to_after_insert.php"; //redirect page name
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

?>
[/PHP]

I know it is long, but has never faild to do just what I am asking it to do....

nine72
Sep 10 '08 #4
elen
4
thank you nine 72 for your help :-)
Sep 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Kurda Yon | last post by:
Hi, I would like to construct a web site that can do following. It contains a number of short stories, visitor can read this stories and give to them marks (story was good or bed). Stories have...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
1
by: Biva | last post by:
Hello, I have a drop down list control in a datagrid. I can't seem to populate the control. Here is what my code looks like: <EditItemTemplate> <asp:DropDownList ID= "ddlUser5" DataSource =...
9
by: charliewest | last post by:
Hello - I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#) is there any way to temporarily save an image to a session object, and after running some other operations, later...
4
by: Steven | last post by:
Hi, I have a database table field to store the form name, I want to create the particular windows form by using the value that read from that DB field. For examples, the table field has a value...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
5
by: JuAn2226 | last post by:
How do I create database which will store the random number that generated before I reset the random number and how do I check that new random number after I reset is exists in database. If exist...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.