473,406 Members | 2,345 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,406 software developers and data experts.

how to make a form using php

3
hiiiii, i am beginer in php. i want to make a form in which four field there ie name, roll, subject and picture. name and roll must be string and numbers if not then give red box input field and save picture in a folder and also thier is two button, one is submit and other is showlist. when i click on submit button, the data is save into database and when click on showlist, the data is retrieve and show 20 rows as a table .
Sep 20 '13 #1
3 1163
Dormilich
8,658 Expert Mod 8TB
i want to make a form in which four field there ie name, roll, subject and picture. name and roll must be string and numbers if not then give red box input field and save picture in a folder and also thier is two button, one is submit and other is showlist.
that’s an HTML question, not a PHP question.

when i click on submit button, the data is save into database and when click on showlist, the data is retrieve and show 20 rows as a table .
what have you tried?

remember, we’re not a free coding service, we’re a help forum.
Sep 20 '13 #2
rabi41
3
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.   <head>
  4.   <meta http-equiv="content-type" content="text/html; charset=windows-1251">
  5.   <style>
  6.     .errText {
  7.         font-family: Arial;
  8.         font-size: 10px;
  9.         color: #CC0000;
  10.         text-decoration: none;
  11.         font-weight: normal;
  12.     }
  13.     a{
  14.         text-decoration: none;
  15.     }
  16.   </style>
  17.   <title></title>
  18.   </head>
  19.   <?php
  20.  
  21.     $con=mysqli_connect("localhost","root","");
  22.     if (mysqli_connect_errno())
  23.     {
  24.         echo "Failed to connect to MySQL: " . mysqli_connect_error();
  25.     }
  26.  
  27.     mysql_select_db("test") OR DIE ("Unable to select db".mysql_error());
  28.  
  29.     $sql = "CREATE TABLE details (
  30.         pid int primary key not null auto_increment,
  31.         name CHAR(30),
  32.         roll INT(10).
  33.         subject VATCHAR(50),
  34.         picture longblob)";
  35.  
  36.  
  37.       $errName     = "";
  38.       $errroll  = "";
  39.  
  40.       $name=$_POST["name"];
  41.       $roll=$_POST["roll"];
  42.       $subject=$_POST["subject"];
  43.       $picture=$_POST["picture"];
  44.  
  45.  
  46.       if($_POST["ac"]=="login"){
  47.  
  48.         if(preg_match("/^[A-Z][a-zA-Z -]+$/", $name) === 0)
  49.           $errName = '<p class="errText">Name must be from letters, dashes, spaces and must not start with dash</p>';
  50.  
  51.         if(preg_match("/^[0-9]+$/", $roll) === 0)
  52.           $errroll = '<p class="errText">roll must be only numbers </p>';
  53.  
  54.       }
  55.  
  56.         if (!isset($_POST['submit'])) {
  57.  
  58.         $allow = array("jpg", "jpeg", "png");
  59.  
  60.         $todir = 'uploads/';
  61.  
  62.         if ( !!$_FILES['file']['tmp_name'] )
  63.         {
  64.             $ext = explode('.', strtolower( $_FILES['file']['picture']) );
  65.  
  66.             if ( in_array( $ext, $allow) )
  67.             {
  68.                 if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['picture'] ) ) )
  69.                 {
  70.                     echo "Upload: " . $_FILES["file"]["picture"] . "<br>";
  71.                     echo "Type: " . $_FILES["file"]["type"] . "<br>";
  72.                     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  73.                     echo "Stored in: " . $_FILES["file"]["tmp_name"];
  74.                 }
  75.             }
  76.             else
  77.             {
  78.                 echo "Invalid file";
  79.             }
  80.         }
  81.  
  82.         $result="INSERT INTO details (name,roll,subject,picture) VALUES ('$name', '$roll', '$subject', '$picture')";
  83.         if (!mysqli_query($con,$result))
  84.         {
  85.             echo "there was some error";
  86.         }
  87.   ?>
  88.   <body>
  89.   <center>
  90.   <form name="main" action="<?php $PHP_SELF ?>" method="POST">
  91.     <input type="hidden" name="ac" value="login">
  92.     <table width="500" border="0" cellpadding="4" cellspacing="0" bordercolor="#000000" bgcolor="#EDEFF1">
  93.       <tr align="center" bgcolor="#FD9003">
  94.         <td colspan="2" bgcolor="#A6B39D">Registration Form</td>
  95.       </tr>
  96.       <tr>
  97.         <td>Name:</td>
  98.         <td>
  99.           <input name="name" type="text" size="50" maxlength="100" value="<?php echo $_POST['name']; ?>"/>
  100.           <?php  if(isset($errName)) echo $errName; ?>
  101.         </td>
  102.       </tr>
  103.       <tr>
  104.         <td>Roll:</td>
  105.         <td>
  106.           <input name="roll" type="text" size="50" maxlength="10" value="<?php echo $_POST['roll']; ?>"/>
  107.           <?php  if(isset($errroll)) echo $errroll; ?>
  108.         </td>
  109.       </tr>
  110.       <tr>
  111.         <td>Subject:</td>
  112.         <td>
  113.           <input name="subject" type="text" size="50" />
  114.         </td>
  115.       </tr>
  116.       <tr>
  117.         <td>Picture:</td>
  118.         <td>
  119.           <input name="picture" type="file" />
  120.         </td>
  121.       </tr>      
  122.         <td>&nbsp;</td>
  123.         <td><input type="submit" name="Submit" value="Submit"></td>
  124.         <td><a href="test2.php"><input type="button" name="Submit" value="Show List" /></a></td>
  125.       </tr>
  126.     </table>
  127.   </form>
  128.   </center>
  129.   </body>
  130.   <?php
  131.     }
  132.   ?>
  133. </html>

What's wrong in above code
Sep 20 '13 #3
Dormilich
8,658 Expert Mod 8TB
What's wrong in above code
you’re mixing mysql and mysqli.
Sep 20 '13 #4

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

Similar topics

2
by: vishal | last post by:
hello friends i have one php script which generates html page containing form. what i want is submit this form using php script. pls give me some idea that how can i submit form using php...
4
by: Chris | last post by:
Dear all, I would like to figure out a way to add controls to a form using specs stored in a table. Any assistance in fleshing this idea out would be greatly appreciated. I'm using VB6. ...
4
by: btopenworld | last post by:
I am submitting a form using an image as the link to a js file. The image calls a js function which checks fields- issuing alerts for errors - if no errors it then submits the form. I would like...
3
by: Justin Sane | last post by:
I haven't been able to select a form using getElementById. I only can select a form using the "name" property of the <form> tag. Is there another way to select a form, or is it even possible to use...
6
by: Cc | last post by:
hi, how do I make form background colour transparent when I set border style to none?
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
2
by: Michael Creager | last post by:
I am using VB NET 2002. How can I programmatically create a new windows form using the value of a string variable as the name of the new form? Public FrmName As String = "MDIChildFrm1" Public...
4
by: listerofsmeg01 | last post by:
I think I probably know that answer, but I will ask anyway. Is it possible to submit a form using a standard anchor link, rather than a submit button? The reason I ask is that I have a standard...
3
by: noks | last post by:
Hi guys Can you please help me with the syntax to save data within a form using tblA to tblB (whicheva changes i make on the form, i want saved on both tables) i've tried this whenever i click...
6
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.