473,804 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I can't store in database from my form

elen
4 New Member
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 1855
Atli
5,058 Recognized Expert Expert
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 New Member
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 New Member
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_dat a.php...
[PHP]
<?PHP

session_start() ;

require_once('. ./../Connections/your_db_connect ion_page.php');

if (!function_exis ts("GetSQLValue String")) {
function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "", $theNotDefinedV alue = "")
{
$theValue = get_magic_quote s_gpc() ? stripslashes($t heValue) : $theValue;

$theValue = function_exists ("mysql_real_es cape_string") ? mysql_real_esca pe_string($theV alue) : mysql_escape_st ring($theValue) ;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValu e) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValu e : $theNotDefinedV alue;
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)",
GetSQLValueStri ng($_POST['eponumsyzygval '], "text"),
GetSQLValueStri ng($_POST['eponumpatrval'], "text"),
GetSQLValueStri ng($_POST['onomval'], "text"),
GetSQLValueStri ng($_POST['onomsyzygval'], "text"),
GetSQLValueStri ng($_POST['onompatrval'], "text"),
GetSQLValueStri ng($_POST['epaggelval'], "text"),
GetSQLValueStri ng($_POST['epaggelsyzygva l'], "text"),
GetSQLValueStri ng($_POST['imergenval'], "text"),
GetSQLValueStri ng($_POST['toposkatagval'], "text"),
GetSQLValueStri ng($_POST['asfalistorgval '], "text"),
GetSQLValueStri ng($_POST['ap_ast_tayt'], "text"),
GetSQLValueStri ng($_POST['dieythval'], "text"),
GetSQLValueStri ng($_POST['til1val'], "text"),
GetSQLValueStri ng($_POST['til2val'], "text")
);

mysql_select_db ($database_your db, $yourdb);
$Result1 = mysql_query($in sertSQL, $yourdb) or die(mysql_error ());

$insertGoTo = "page_to_go_to_ after_insert.ph p"; //redirect page name
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insert GoTo, '?')) ? "&" : "?";
$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 New Member
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
1946
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 to be ordered (by php) according to the given notes. Any user can add a new story (just fill field and press button "Send"). Can I do it with php? Thank you.
17
5636
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 constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
1
1911
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 = '<%# ddlUser5Bind() %>' Runat =server> </asp:DropDownList> </EditItemTemplate>
9
9789
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 retrieve the image from the session object, convert it back to an image, and re-save it to the database? Thanks?
4
1758
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 "ThisForm", then I want to create the form with class name "ThisForm" (Suppose I have already defined the class "ThisForm"). Can I do this by using late bindnig? Any source code for reference? Thanks! Steven.
52
6361
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
4
12454
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
5
2554
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 then generate again and store new number in to database. I have created 10 label in the form which display the random number and at the same time I want random number generated to be stored in database. I don’t know how to start Plz help me with...
8
2180
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 the user can edit those particular values and also that should be updated in the mysql database.kindly reply me as early as possible. Thanks
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.