Begginner, need help =D

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Begginner, need help =D

Post by myworldplz »

I am a begginer at Php and I want to make a script.

Its a script where people will have a form like this:

Username?:
Code?: 999-999-999


And it will be added automatically to a list of other codes that will be displayed in a web page. Also I want to know how other people can bump their code to the top.

My server has full capabilities (and bandwidth!) and can run all scripts such as POST and other things... If you need anything to make the script word I use CPanel and may be able to use that to install something to make it work.

I'd give credit to whoever makes it, however I would need to edit it as it is going into a mobile site (iphone) and I am going to use formatting. (I do know quite a bit about servers, html web etc just lacking in php :banghead: )

Hehe so any help would be greatly appreciated! Thanks to all that answer.

Also, I'm a beginner and like to study peoples codes I hope you don't mind.

-Myworldplz
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Begginner, need help =D

Post by Benjamin »

Code: Select all

 
<?php
 
if (isset($_POST['WHAT_AM_I_DOIN']) && $_POST['WHAT_AM_I_DOIN'] == 'I_BE_SUBMITTEN_YO') {
    $data = array(
        'username'  => $_POST['username'],
        'code'      => $_POST['code'],
        'bumpattop' => $_POST['bumpmeup']
    );
 
    mysql_query(
      "INSERT INTO submittentableyo
        (`" . implode("`, `", array_map('mysql_real_escape_string', array_keys($data))) . "`)
       VALUES
        ('" . implode("', '", array_map('mysql_real_escape_string', $data)) . "')"
    );
} else {
    $imnotgoingtofart = mysql_query("
        SELECT
          username,
          code,
          bumpattop
        FROM
          submittentableyo
        ORDER BY
          bumpattop DESC
    ");
 
    $candyBones = array();
 
    while ($ouchThisHurts = mysql_fetch_assoc($imnotgoingtofart)) {
        $candyBones[] = $ouchThisHurts;
    }
 
}
 
?>
<html>
<head>
  <title>HELLO WORLD DUDES IN THE HIZOUSE!</title>
  <style type="text/css">
    body {
        background-color: #88af23;
    }
 
    h1 {
        font-family: monospace;
        font-variant: small-caps;
    }
 
    table.homeboy {
        border-width: 1px 1px 0px 0px;
        border-style: dashed;
        border-color: #1100af;
    }
 
    table.homeboy th,  table.homeboy td{
        border-width: 0px 0px 1px 1px;
        border-style: dashed;
        border-color: #1100af;
        padding: 5px;
    }
 
    table.homeboy th,  table.homeboy td.submit{
        text-align: right;
    }
  </style>
</head>
<body>
  <h1>HALO WAS UP YO?</h1>
 
  <?php if (isset($candyBones) && is_array($candyBones) && count($candyBones) > 0) { ?>
    <?php foreach($candyBones as $rottenEgg) { ?> 
      <?php echo "{$rottenEgg['username']}<br /><strong>{$rottenEgg['code']}</strong>"; ?>
    <?php } ?>
  <?php } ?>
 
  <form name="THIS_IS_MY_FORM_YO" action="#wassup_i_am_postin" method="post">
    <table class="homeboy">
      <tr>
        <th>Username?:</th>
        <td><input type="text" name="username" value="" /></td>
      </tr>
      <tr>
        <th>Code?:</th>
        <td><input type="text" name="code" value="" /></td>
      </tr>
      <tr>
        <th>Bump At Top:/:|:\;)?:</th>
        <td>
          <select name="bumpmeup">
            <?php foreach (range(0, 100) as $battopvalue) { ?>
              <?php echo '<option value="' . $battopvalue . '">' . $battopvalue . '</option>'; ?>
            <?php } ?>
          </select>
        </td>
      </tr>
      <tr>
        <td class="submit" colspan="2">
          <input type="hidden" name="WHAT_AM_I_DOIN" value="I_BE_SUBMITTEN_YO" />
          <input type="submit" value="LETS DO THIS UP IN HERE" />
        </td>
      </tr>
    </table>
  </form>
 
</body>
</html>
 
Attachments
wassup.jpg
wassup.jpg (22.33 KiB) Viewed 546 times
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

I'm not getting the same view?

Image

You might have to hold my hand, do I need MySQL installed to do this? Or somekind of extension?

Its running at:

http://www.imobz.info
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

Alright, I removed the numbers. I use Cpanel for my server, how can I install a MySQL Database?

Sorry bear with me here :)
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

I've created a database and a user for that database, do I have to integrate the Username and password of that account into the PHP in order for it to access the MySQL Database?

Image
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Begginner, need help =D

Post by Benjamin »

Well I guess you'll need this stuff as well if you are really going to use that.

Here is MySQL code for creating the database table. You can run it in phpMyAdmin.

Code: Select all

 
CREATE TABLE `test`.`submittentableyo` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 255 ) NOT NULL ,
`code` VARCHAR( 255 ) NOT NULL ,
`bumpattop` TINYINT NOT NULL ,
INDEX ( `bumpattop` ) 
) ENGINE = MYISAM
 
You will also need to add the following code to the top of the script I already wrote so that it connects to the database. Just put it right after the <?php

Code: Select all

 
 try {
    if (false === ($link = mysql_connect('localhost', 'mysql_user', 'mysql_password'))) {
        throw new Exception("Could not connect to database");
    }
 
    if (false === mysql_select_db('databasename', $link)) {
        throw new Exception(mysql_error($link));
    }
} catch (Exception $e) {
    echo $e->getMessage();
    exit();
}
 
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

How can I run this code? Here's the PHPMYADMIN window that I see...

Image
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Begginner, need help =D

Post by Benjamin »

Click on your database name, then click on SQL.
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

Gah problem :X
Error

SQL query:

CREATE TABLE `test`.`submittentableyo` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 255 ) NOT NULL ,
`code` VARCHAR( 255 ) NOT NULL ,
`bumpattop` TINYINT NOT NULL ,
INDEX ( `bumpattop` )
) ENGINE = MYISAM

MySQL said: Documentation
#1142 - CREATE command denied to user 'matthew'@'localhost' for table 'submittentableyo'
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Begginner, need help =D

Post by Benjamin »

You'll have to contact your hosting provider or modify the permissions for that database if you have permissions to do so.
myworldplz
Forum Newbie
Posts: 7
Joined: Thu Mar 05, 2009 3:48 pm

Re: Begginner, need help =D

Post by myworldplz »

Ok, I got a book on PHP so I'll work with that. :D
Post Reply