www.webdeveloper.com
Results 1 to 8 of 8

Thread: I'm novice in PHP ( need help in using both PHP & PDO )

  1. #1
    Join Date
    Sep 2013
    Posts
    18

    I'm novice in PHP ( need help in using both PHP & PDO )

    Hi everyone. I've written a code that contains HTML & JS & PHP , in the code below There must be a list that you can enter your information , I'm thinking of using PHP & PDO (both together) to get the information entered , & store them & display the information in wherever part of the page, however I've used script in the code below (with no sense) but it's not necessary for me to use it , you can "comment" it , that's OKey. Just I need the exact code to see if the result is as the same as what I've wanted or not, so I'll be glad to write me the exact code & complete my code below: (however you can write me down more simplify , you can just focus on 2-3 fields of info , if you help me I'll complete the whole code myself)

    Thanks everyone



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Store it in a table</title>
    <script>
    {
    var fn=document.forms["myForm"]["fname"].value;
    var ln=document.forms["myForm"]["lname"].value;
    var x=document.forms["myForm"]["email"].value;
    var g=document.forms["myForm"]["gender"].value;
    //var birth=document.forms["myForm"]["year"].value + "/" document.forms["myForm"]["month"].value + "/" + document.forms["myForms"]["day"].value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    var adr=document.forms["myForm"]["info"].value;
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    {
    alert("Not a valid e-mail address");
    //return false;
    }
    }
    alert(fn);
    if (fn==null || fn=="")
    {
    alert("First Name must be filled out!");
    }

    if (ln==null || ln=="")
    {
    alert("Last Name must be filled out!");
    }

    if (g==null)
    {
    alert("Choose your gender!");
    }
    //}
    </script>
    </head>

    <body>
    <!--<form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post"> -->
    <form method="post" action="" name="myForm" onsubmit="return validateForm ();">
    <p>Please, Complete the information are required below:</p>
    First Name: <input type="text" name="fname" />
    Last Name: <input type="text" name="lname" /> <br/><br/>
    Email: <input type="email" name="email" placeholder="e.g:asmj@gmail.com"/> <br/><br/>
    Gender: <input type="radio" name="gender" /> male
    <input type="radio" name="gender"/> female <br/><br/>
    Select your Birth date:<br/>
    Year: <Select name="year">
    <?php for ($y=1920; $y<=2000; $y++){
    echo "<option> ".$y." </option>";
    } ?>
    </Select>

    Month: <Select name="month">
    <?php for ($m=1; $m<=12; $m++){
    switch ($m)
    {
    case "1":
    echo "<option> ".Jan." </option>";
    break;
    case "2":
    echo "<option > ".Feb." </option>";
    break;
    case "3":
    echo "<option> ".March." </option>";
    break;
    case "4":
    echo "<option> ".April." </option>";
    break;
    case "5":
    echo "<option> ".May." </option>";
    break;
    case "6":
    echo "<option> ".June." </option>";
    break;
    case "7":
    echo "<option> ".July." </option>";
    break;
    case "8":
    echo "<option> ".Agust." </option>";
    break;
    case "9":
    echo "<option> ".Sep." </option>";
    break;
    case "10":
    echo "<option> ".Oct." </option>";
    break;
    case "11":
    echo "<option> ".Nov." </option>";
    break;
    case "12":
    echo "<option> ".Dec." </option>";
    break;

    default:
    echo "<option> ".Dec." </option>";
    }
    }
    ?>
    </Select>


    Day: <select name="day">
    <?php for ($d=1; $d<=31; $d++){ ?>
    <option> <?php echo ($d); ?> </option>
    <?php } ?>
    </select>
    <br/><br/>

    Type your address in the below text area:<br/>
    <textarea name="info"></textarea><br/><br />

    <input type="submit" name="submit" value="Okey"/>
    <input type="reset" name="reset" value="Clear all"/>
    </form>
    <div>

    <?php
    print_r($_POST);
    if($_POST["fname"]== null)
    ?>

    </div>

    </body>
    </html>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    565
    Might help if you explained EXACTLY what your problem is. Your rambling intro is not saying much

  3. #3
    Join Date
    Sep 2013
    Posts
    18
    OK , ginerjim but would you please tell me which part you don't exactly get? then it would be easier for me to say in details

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    565
    That's your job!! Your wrote a long text about your work, but then intimated that you wanted to use PDO. But you aren't showing us the code that you have tried to use or showed us a problem.

    We are not a consulting service. You write the code and when it doesn't work, ask for help with it. Don't tell us about your hopes and dreams and ask us to write them for you.

    So now - you tell us exactly what is wrong with this script or else write some code and ask for help if you have problems with it.

  5. #5
    Join Date
    Sep 2013
    Posts
    18
    Ok ginerjim you're right ... actually I've tried to write PDO , but since I've got really confused with it , so I deleted the lines I've written in PDO , my problems are :

    1) why the Script code I've written doesn't make any sense ?! & how can I fix this problem?
    2) just show me a little part of PDO that will make sense here ( to fetch data) cause I'm confused with its syntax
    3) then how can I work with the data I've stored by PDO in my data base, & display them in my HTML page by using PHP?

    PM - Sorry if you thought I've ever want you to service me & I didn't have ever tried to write any codes, of course I've done a lot but unfortunately I'm novice somehow , & I need the result as soon as possible , But Thanks again for replying me & spending time to solve my problems here , I'm so grateful

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    565
    Show Us Your Code and we will help you I'm sure.

  7. #7
    Join Date
    Sep 2013
    Posts
    18
    Ok , the code below is what I've tried to use PDO , the first thing I've done is to create a database & a table using "easyPHP" ... the table has 9 col " id , First Name , ...... , address " & all I want to do is to write a code in php & PDO to fetch the data from the HTMl page that each user enter , & store them in the adta base using PDO , & again display the data in that HTML page :

    <?php

    try {
    $dbh = new PDO('mysql:host=localhost;dbname=practice;charset=utf8', 'root', '');
    $attributes = array(
    "First Name", "Last Name", "Email", "Gender", "year",
    "month", "day", "address"
    );

    $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
    $stmt->execute();
    while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
    $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
    print $data;
    foreach($dbh->query('SELECT * from FOO') as $row) {
    print_r($row);
    }
    $dbh = null;
    } catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
    }
    ?>

    I know the code above is really a fake one, but as I've said , I'm really confused with PDO & PHP & need a big help, Thanks

  8. #8
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    565
    I don't even see a query. At least Try and show us some code and stop making excuses. We all started at this just like you, so show us what you think will work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles