473,385 Members | 1,645 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,385 software developers and data experts.

How to insert these values to database in php

mmarif4u
Hi everybody,
I already post a thread like this but that was in mysql.
Here i have a problem with all the code,,

Expand|Select|Wrap|Line Numbers
  1. <?php // signup.php
  2.  
  3. include("common.php");
  4. include("db.php");
  5.  
  6. if (!isset($_POST['submitok'])):
  7.     // Display the user signup form
  8.     ?>
  9. <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
  10.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head>
  13.    <title> Access Code Generator Form </title>
  14.   <meta http-equiv="Content-Type"
  15.     content="text/html; charset=iso-8859-1
  16. </head><link href="style.css" rel="stylesheet" type="text/css">
  17. <body bgcolor="slate"><center>
  18.  
  19. <h3> <font color="#FFFFFF" face="verdana"><u>Registration Form For New Users</u><p>Please Fill The Form Below Carefully
  20. </font>
  21. </h3></body>
  22.  
  23. <form name="reg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  24.  
  25. <table align="center" border="0" cellpadding="0" cellspacing="5">
  26. <hr color="blue" />
  27.     <tr>
  28.         <td align="right">
  29.             <p><font color="#FFFFFF" face="verdana">IC Number :</font></p>
  30.         </td>
  31.         <td>
  32.             <input name="icnumber" type="text" maxlength="100" size="25" />
  33.             <font color="orangered" size="+1"><tt><b>*</b></tt></font>
  34.         </td>
  35.     </tr>
  36.  
  37.     <tr>
  38.         <td align="right">
  39.             <p><font color="#FFFFFF" face="verdana">Access Code :</font></p>
  40.         </td>
  41.         <td>
  42.             <input name="acccode" type="text" maxlength="100" size="25" />
  43.             <font color="orangered" size="+1"><tt><b>*</b></tt></font>
  44.         </td>
  45.     </tr>
  46.     <tr>
  47.         <td align="right">
  48.             <p><font color="#FFFFFF" face="verdana">Username :</font></p>
  49.         </td>
  50.         <td>
  51.             <input name="username" type="text" maxlength="100" size="25" />
  52.             <font color="orangered" size="+1"><tt><b>*</b></tt></font><td align="left">Enter a valid user name.</td>
  53.         </td>
  54.     </tr>
  55.     <tr>
  56.         <td align="right">
  57.             <p><font color="#FFFFFF" face="verdana">Full Name :</font></p>
  58.         </td>
  59.         <td>
  60.             <input name="fullname" type="text" maxlength="100" size="25" />
  61.             <font color="orangered" size="+1"><tt><b>*</b></tt></font>
  62.         </td>
  63.     </tr>
  64.     <tr>
  65.         <td align="right">
  66.             <p><font color="#FFFFFF" face="verdana">Email :</font></p>
  67.         </td>
  68.         <td>
  69.             <input name="email" type="text" maxlength="100" size="25" />
  70.             <font color="orangered" size="+1"><tt><b>*</b></tt></font><td>Email must be valid for password retreival.</td>
  71.         </td>
  72.     </tr>
  73.     <tr>
  74.         <td align="right">
  75.             <p><font color="#FFFFFF" face="verdana">Hand Phone :</font></p>
  76.         </td>
  77.         <td>
  78.             <input name="hp" type="text" maxlength="100" size="25" />
  79.             <font color="orangered" size="+1"><tt><b>*</b></tt></font>
  80.         </td>
  81.     </tr>
  82.     <tr><td>
  83.     <font  face="verdana" color="orangered" size="+1"><tt><b>*</b></tt></font>
  84.     <u><font face="arial" size="2" color="#FFFFFF">indicates a required field</u></font>
  85.     </td>
  86.     </tr>
  87.  
  88.     <tr>  
  89.         <td align="right" colspan="3">
  90.            <hr color="blue" />
  91.  
  92.             <input type="reset" value="Reset" />
  93.             <input type="submit" name="submitok" value="Register"  />
  94.  
  95.         </td>
  96.     </tr>
  97. </table>
  98. </form>
  99.  
  100. </body>
  101. </html>
  102.  
  103.     <?php 
  104.  
  105. else:
  106.     // Process signup submission
  107.     dbConnect('db');
  108.  
  109.     if ($_POST['icnumber']=='' or $_POST['acccode']=='' or $_POST['username']==''or $_POST['fullname']==''
  110.       or $_POST['email']=='' or $_POST['hp']=='')  { 
  111.          error ('One or more required fields were left blank.\\n'.
  112.               'Please fill them in and try again.');
  113.     }
  114.  
  115.     // Check for existing user with the new id
  116.     $sql = "SELECT * FROM m_users WHERE icnumber = '$_POST[icnumber]' AND acccode = '$_POST[acccode]'";
  117.     $result = mysql_query($sql);
  118.     if (!$result==0) {    
  119.         error('A database error occurred in processing your '.
  120.               'submission.\\nIf this error persists, please '.
  121.              'contact you@example.com.');
  122.     }
  123.     if (mysql_result($result) < 1) {
  124.         error('Your entered Ic number and Access code does not match\\n'.
  125.              'to the database data. Please try agian.');
  126.     }
  127.  
  128.     $newpass = substr(md5(time()),0,6);
  129.  
  130.     $sql = "INSERT INTO m_users where icnumber = '$_POST[icnumber]' SET
  131.              password = PASSWORD('$newpass'),
  132.              email = '$_POST[email]',
  133.              h/p = '$_POST[hp]',
  134.              username = '$_POST[username]',
  135.              fullname = '$_POST[fullname]'";
  136.     if (!mysql_query($sql))
  137.         error('A database error occurred in processing your '.
  138.               'submission.\\nIf this error persists, please '.
  139.               'contact admin@straight-a.com.my .\\n' . mysql_error());
  140.  
  141.     // Email the new password to the person.
  142.     $message = "G'Day!
  143.  
  144. Your personal account for the Straight-a program
  145. has been created! To log in, proceed to the
  146. following address:
  147.  
  148.     http://www.straight-a.com.my/
  149.  
  150. Your personal login ID and password are as
  151. follows:
  152.  
  153.     username: $_POST[username]
  154.     password: $newpass
  155.  
  156. You aren't stuck with this password! Your can
  157. change it at any time after you have logged in.
  158.  
  159. If you have any problems, feel free to contact me at
  160. <admin@straight-a.com.my>.
  161.  
  162. -Arif
  163.  Webmaster
  164. ";
  165.  
  166.     mail($_POST['email'],"Your Password for the Straight-a Program",
  167.          $message, "From:Arif <admin@straight-a.com.my>");
  168.  
  169.     ?>
  170.     <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
  171.       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  172.     <html xmlns="http://www.w3.org/1999/xhtml">
  173.     <head>
  174.       <title> Registration Complete </title>
  175.       <meta http-equiv="Content-Type"
  176.         content="text/html; charset=iso-8859-1" />
  177.     </head>
  178.     <body>
  179.     <p><strong>User registration successful!</strong></p>
  180.     <p>Your userid and password have been emailed to
  181.        <strong><?=$_POST['email']?></strong>, the email address
  182.        you provided in your registration form. To log in,
  183.        go to your email and click the link provided in your email.</p>
  184.     </body>
  185.     </html>
  186.     <?php
  187. endif;
  188. ?>
  189.  
Now the question arises are these:

IC number and Access Code are alredy given to users.

1: I want that when user enters the details like Ic number,access code,Full name,email,hp,username etc. The script 1st check that is their any IC number and access code exist in the table, if have than store the
others values to the table like email,username,hp etc to that row of table.
if no error msg showed.
2: Where i edit the script to give right results.Is there any thing wrong in the sql query.

Plz help me if any body have idea..
Thanks...
Dec 28 '06 #1
3 2731
ronverdonk
4,258 Expert 4TB
What is your problem? You already check that a user exists and, if so, update the table! So what is there to change?

Ronald :cool:
Dec 28 '06 #2
Ronald the problem is simple 1st i want to check the icnumber
& access code if it exists in the database than it insert the other values
like fullname,email,handphone,username etc, But if these 2 not exists in
the database than data not stored in the database...

For example my ic number is 123456 and access code is 456,i enter
these values to the text box with completing the form like name=arif,
email=mmarif4u@domain.com,username=mmarif4u etc and click submit
button,so 1st the query checks the ic number & access code if it is in the
database than my name,email,username stored to the database otherwise
cannot...


i think u will understand what i want to say here,,,

The problem is this script cannot work, i dont know something wrong with query
or script...
When i click the button it says the user already exists,thats the problem..

Thanks
Dec 29 '06 #3
ronverdonk
4,258 Expert 4TB
You cannot do an INSERT when the record already exists. Statement should be
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE m_users SET
  2.         password = PASSWORD('$newpass'),
  3.         email = '$_POST[email]',
  4.         h/p = '$_POST[hp]',
  5.         username = '$_POST[username]',
  6.         fullname = '$_POST[fullname]'
  7.         WHERE icnumber = '$_POST[icnumber]'";
I must also caution you should sanitize ANY input before using it with database functions. You should at least use the strip_tags or htmlentities commands.

Ronald :cool:
Dec 29 '06 #4

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
6
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a...
3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: AdamM | last post by:
Currently, my code reads from a database without knowing the order of the columns like this: string name = (string)datarow; However, is there a way to write or do an INSERT back to a database...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
7
by: Kevin Lawrence | last post by:
Hi all I want to do "INSERT INTO Table (Blob) Values('blobdataasstring')". ...rather than using the parameter driven method, is it possible? And if so what encoder do I use to convert the...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.