+ Reply to Thread
Results 1 to 4 of 4

Thread: ok what am looking for help ??

  1. #1
    shaunNO2007's Avatar
    shaunNO2007 is offline x10Hosting Member shaunNO2007 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    57

    ok what am looking for help ??

    hi again people r8 am still looking for a rating script last time a posted i dont think a tell you what sort of raing script i want ok this is what sort i want...



    <select name="1-5">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>

    that. just a easy one but i want it to connect to a database and that please if anyone one how please reply

    Very much thanks

    Shaun

    Please ;)

  2. #2
    xprtweb is offline x10Hosting Member xprtweb is an unknown quantity at this point
    Join Date
    Jul 2007
    Posts
    30

    A simple tutorial that could help

    Hi

    If you want a simple script to enter data from a form into a database, here are some scripts you can use or actually improve on to do what u want. I'm sure there are better scripts around, though.
    For my purposes, I will create
    1. sample database table: "yourdbtable" (I know u might already be having one)
    2. the database script I call "db.php"
    3. a form for submiting the data: form.php
    4. a script to process it: postdata.php

    The 3 php files must be in the same folder, unless you know what you are doing.

    I put some basic form validation, with the database data submission succeeding only if first name, second name & "choice" are selected.
    After successfull submission, you are returned to the form with a confirmation message.
    I tried to comment to show what some portions of code do.
    I tested & it functions. If you rename any of them, make sure you change all places in the scripts any of the names appears or it will not work.

    I hope it helps, or at least someone else may find it useful.

    The database table:

    Code:
    CREATE TABLE `yourdbtable` (
      `id` tinyint(50) NOT NULL auto_increment,
      `fname` varchar(50) NOT NULL,
      `sname` varchar(50) NOT NULL,
      `choice` varchar(50) NOT NULL,
      `comment` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    The db.php:
    Code:
    <?php
    
    $dbhost = "localhost"; //your database host server, eg. localhost
    $dbname = "yourdatabasename";
    $dbusername = "yourdatabseusername";
    $dbpassword = "yourdbpassword";
    
    $dbconnect = mysql_pconnect("$dbhost", "$dbusername", "$dbpassword") or die("Could not connect to server!");
    
    $db = mysql_select_db("$dbname", $dbconnect) or die(mysql_error());
    
    ?>

    I will call the form "form.php".
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <meta name="generator" content="PSPad editor, www.pspad.com">
      <title></title>
      </head>
      <body>
    <h2>A sample form to post data to a database</h2>
    
    <?
    if($error1 || $error2 || $error3)
    {
    echo "<font color='red'><b>Please fill in the following: ";
      if($error1)
        {echo $error1;}
        if($error2)
        {echo $error2;}
        if($error3)
        {echo $error3;}
    echo "</b></font>";   
    }
    ?>
    <?
    if($posted)
      {echo $posted;}
    ?>
      
    <form name="form1" method="post" action="postdata.php">
    
    <table width="500">
    <caption>A simple form to post Data</caption>
    <tr>
    <td>First name</td><td><input type="text" name="fname"></td>
    </tr>
    <tr>
    <td>Second name</td><td><input type="text" name="sname"></td>
    </tr>
    <tr>
    <td>Your Choices</td><td><select name="choice">
    <option value=""></option>
    <option value="1">Choice 1</option>
    <option value="2">Choice 2</option>
    <option value="3">Choice 3</option>
    <option value="4">Choice 4</option>
    <option value="5">Choice 5</option>
    </select></td>
    </tr>
    <tr>
    <td>Comment</td><td>
    <textarea name="comment"></textarea></td>
    </tr>
    <tr>
    <td><input type="submit"></td><td><input type="reset"></td>
    </tr>
    </table>
    </form>
    
      </body>
    </html>
    The script to get the data into the data base which I called "postdata.php":
    Code:
    <?php
    include "db.php";
    
    //Change post field values into variables
    $fname = $_POST['fname'];
    $sname = $_POST['sname'];
    $choice = $_POST['choice'];
    $comment = $_POST['comment'];
    
    //strip slashes
    $fname = stripslashes($fname);
    $sname = stripslashes($sname);
    $choice = stripslashes($choice);
    $comment = stripslashes($comment);
    
    //If you want fist name, second name & choice to be compulsory, include this to check if something has not been filled in.
    //Simply add comment in the same if u want to be compulsory.
    
    if((!$fname) || (!$sname) || (!$choice))
      {
        if(!$fname)
          {$error1 = "first name - ";}
        if(!$sname)
          {$error2 = "second name - ";}
        if(!$choice)
          {$error3 = "choice";}  
        include "form.php";
        exit(); //We exit so no incomplete data is entered
      }
    //If all form info is there, enter data into database
    
    $postdata = mysql_query("INSERT INTO yourdbtable (id, fname, sname, choice, comment) values('', '$fname', '$sname', '$choice', '$comment')") or die(mysql_error());
    
    if(!$postdata)
      {
        echo "<font color='red>'<b>The data could not be entered into database. Please contact the webmaster.</b></font>";
      }
     else
      {
        $id = mysql_insert_id();
      }
    $posted = "<font color='red'><b>Your data has been successfully entered into database.</b></font>";  
    include "form.php";  
       
    ?>

  3. #3
    shaunNO2007's Avatar
    shaunNO2007 is offline x10Hosting Member shaunNO2007 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    57

    Re: ok what am looking for help ??

    hey thanks a lot m8 you have help me a lot ::

  4. #4
    xprtweb is offline x10Hosting Member xprtweb is an unknown quantity at this point
    Join Date
    Jul 2007
    Posts
    30

    Re: ok what am looking for help ??

    I'm glad it was of some help to you.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers