Results 1 to 6 of 6

Thread: Need some verification

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some verification

    Hello, i am working on a script that will take info from a form and input it into a mysql database for later use. I am looking to make it so that I can search for the title or description and it will return the corresponding data. I know how to make forms and process them in PHP, but I am not sure on how to use MySQL to hold the data because I have only used .txt files in the past.

    I believe the first step is to create the mysql columns like this:
    HTML Code:
    CREATE TABLE `job_recorder` (
      `id` mediumint(8) unsigned NOT NULL auto_increment,
      `job_title` varchar(20) NOT NULL default '',
      `client_email` varchar(20) NOT NULL default '',
      `client_name` varchar(20) NOT NULL default '',
      `description` varchar(20) NOT NULL default '',
      `price` varchar(20) NOT NULL default '',
    ) ENGINE=MyISAM ;
    If anything in there is wrong, i would appreciate someone letting me know .

    The next step should be to insert the data into the database like this:
    HTML Code:
    INSERT INTO `job_recorder` VALUES (1, '$job_title', '$client_email', '$client_name', '$description', '$price',
     '');
    Correct?

    And to call it up again I would do:
    PHP Code:
    <?php
    $query 
    mysql_query("SELECT * FROM `site_config`");
    while (
    $get mysql_fetch_array($query))
    {
    echo 
    '<title>$get[job_title]</title>';
    echo 
    'Email: $get[client_email]';
    echo 
    'Name: $get[client_name]';
    echo 
    'Description: $get[description]';
    echo 
    'Price: $get[price]';
    }
    ?>
    Correct?

    I guess this kinda turned out to be just me needing verification on if my ideas are right or not. But i do have a few questions, if I run this more than once, will it insert a second entry so that I can call that one too? Also, how might I go about searching for a certain entry?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Upon quick glance, looks like you're definitely doing the right general thing.
    Note that your table names don't match.
    At first, it's 'job_recorder', then, later 'site_config'. If they are supposed to be the same, change one.

    Also, here's a good reference for this stuff. I found it helpful.
    http://php-mysql-tutorial.com
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Upon quick glance, looks like you're definitely doing the right general thing.
    Note that your table names don't match.
    At first, it's 'job_recorder', then, later 'site_config'. If they are supposed to be the same, change one.

    Also, here's a good reference for this stuff. I found it helpful.
    http://php-mysql-tutorial.com
    Thanks for the help, and thanks for noticing the difference in names, i'll be sure to fix that

  4. #4
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well, i set the script up and ran it, but ran into a problem. When I try to display the data, i get: Email: $get[client_email]Name: $get[client_im]Description: $get[description]Price: $get[price]Conversation Link: $get[conversation_link]. Any idea why? Here is my code for displaying it:
    PHP Code:
    <?php
    include("config.php");
    $query mysql_query("SELECT * FROM `job_recorder`");
    while (
    $get mysql_fetch_array($query))
    {
    echo
    '
    Title: $get[job_title]
        <br />
    Email: $get[client_email]
        <br />
    Name: $get[client_im]
        <br />
    Description: $get[description]
        <br />
    Price: $get[price]
        <br />
    Conversaton Link: $get[conversation_link]
        <br />
    '
    ;
    }
    ?>
    Last edited by Titan85; 12-27-2006 at 03:48 PM.

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Titan85 View Post
    PHP Code:
    <?php
    include("config.php");
    $query mysql_query("SELECT * FROM `job_recorder`");
    while (
    $get mysql_fetch_array($query))
    {
    echo
    '
    Title: $get[job_title]
        <br />
    Email: $get[client_email]
        <br />
    Name: $get[client_im]
        <br />
    Description: $get[description]
        <br />
    Price: $get[price]
        <br />
    Conversaton Link: $get[conversation_link]
        <br />
    '
    ;
    }
    ?>
    You have the form of quotes backwards: single quotes don't expand variables.

    PHP Code:
    <?php
    include('config.php');

    $query mysql_query('SELECT * FROM `job_recorder`');
    while (
    $get mysql_fetch_array($query)) {
        echo 
    "Title: {$get['job_title']}<br>\r\n"
            
    "Email: {$get['client_email']}<br>\r\n"
            
    "Name: {$get['client_im']}<br>\r\n"
            
    "Description: {$get['description']}<br>\r\n"
            
    "Price: {$get['price']}<br>\r\n"
            
    "Conversation Link: {$get['conversation_link']<br>\r\n";
    }
    ?>
    I suggest you read the section on strings, as well as Why is $foo[bar] wrong? in the PHP manual.

    Mike


    The forum breaks the last escape sequence in the code I posted, for some reason. It should, of course, be \r\n.

  6. #6
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, i got it working with the new way you showed me, but now when i try to create tables in mysql, i get the error: "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ENGINE=MyISAM' at line 9". Here is the code i am using:
    PHP Code:
    CREATE TABLE `job_recorder` (
      `
    job_titlevarchar(20NOT NULL default '',
      `
    client_emailvarchar(40NOT NULL default '',
      `
    client_imvarchar(20NOT NULL default '',
      `
    descriptionvarchar(100NOT NULL default '',
      `
    conversation_linkvarchar(70NOT NULL default '',
      `
    pricevarchar(20NOT NULL default '',
      `
    date_startedvarchar(20NOT NULL default '',
    ENGINE=MyISAM 
    I don't know what to do with the ENGINE=MyISAM since it worked before.

Bookmarks

Posting Permissions

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