Jump to content

Recommended Posts

Hello everyone,

I am a hobbyist with programming. I have been playing with Php, sql, html for several years. I am building a program to organize my club. I am starting out fairly simple and hope in a year for it to be powerful. If anyone can point in the right direction to find out how I can do several things I can get my first version done this week maybe. Here are the things I am trying to accomplish.

 

1.) a page that I can view records with a First record, previous Record, next Record, last record buttons. The page will pull the information from a table or tables out of my mysql database. I would like to have an update button so I can update records as I go through them and to be able to search buy typing in first name or last name. I know there are functions that will help me and I have been trying to figure out what classes on php.net

 

2.) Last question for now. All my pages that deal with mysql I have included all the connection information. I was thinking about making a class and add using a class on the pages to open the connection. Not sure if this would be easy, or the best way.

 

 

Thanks in advance. I am new and I am not looking for the exact code just place to start. I really want to learn php and sql to be able to build my own applications and fix them.

Link to comment
https://forums.phpfreaks.com/topic/212643-new-to-php-a-few-questions-plase/
Share on other sites

1.) a page that I can view records with a First record, previous Record, next Record, last record buttons.

You'll want to look for some pagination tutorials, such as this one:

http://www.phpfreaks.com/tutorial/basic-pagination

 

I would like to have an update button so I can update records as I go through them and to be able to search buy typing in first name or last name. I know there are functions that will help me and I have been trying to figure out what classes on php.net

The core function you'll need to be using is mysql_query. To alter records in mysql you'll use an UPDATE query. To retrieve records from the database you'd use a SELECT query. Here is a tutorial on basic database handling

http://www.phpfreaks.com/tutorial/php-basic-database-handling

 

2.) Last question for now. All my pages that deal with mysql I have included all the connection information. I was thinking about making a class and add using a class on the pages to open the connection. Not sure if this would be easy, or the best way.

If you're starting out with PHP then I'd stick with the procedural functions. When start to get confident you can move on to the MySQLi class. If you learn OOP you can either modify the MySQLi class to your own needs or create your own database class.

Ok I have been going through the tutorials and this is what I have come up with. I have has many syntax errors and plain old errors that I have worked through. I have put the code for one of my add pages here to get some feed back. It works with inputting 1 field only at this time. I have not had success getting multiple fields. I was hoping to get the page to print "Student add success!!!!!!!!!!!!" when the add is success. It prints out error but the add was completed.

 

I would like some feed back so I know if I am on the right track. This is a basic page I am have not got into error checking, or string checking. Right now I want a table with input fields and a button to add a person to the database. When I get that working and understand it I plan on adding more to it.

 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>DaDz Add Skydiver</title>
    </head>
    <body>
        <h1>Far North Skydive Center in Alaska</h1>
        <h3>Add Student</h3>
<?php

if ( isset( $lName ) ) {
    // check user input here!
    $dberror = "";
    $ret = add_to_database( $lName );
    if ( ! $ret )
        print "Error: $dberror<BR>";
    else
        print "Student add success!!!!!!!!!!!!";
}
else {
    Write_form();
}
// Function add Last Name to Database
function add_to_database($lName, $fname){
// database connection info
$conn = mysql_connect("localhost", "dbuser", "dbpass") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR);
    if($_POST['lName']) {
   // little bit of cleaning...
   $lname = mysql_real_escape_string($_POST['lName']);
   // insert new name into table
   $sql = "INSERT INTO skydiver (skynum, lName) VALUES ('','$lName')";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

}// End Function


function Write_form()
{

    echo <<<TABLE
<form action = '{$_SERVER['PHP_SELF']}' method = 'post'>
<table border = '0'>
   <tr>
      <td>First Name</td>
      <td><input type="text" name="fName"></td>
      <td><input type="checkbox" name="chkId">Check ID</td
   </tr>
   <tr>
      <td>Last Name</td>
      <td><input type="text" name="lName"></td>
      <td><input type="checkbox" name="chkWaiverVideo">Waiver Video Complete</td>
   </tr>
   <tr>
      <td></td>
      <td align = 'center'><input type = 'submit' value = 'ADD'></td>
      <td></td>
   </tr>
</table>
</form>  
TABLE;

}// end Write_form function
?>

    </body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.