Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. Create a table, and log the users IP.

    Insert their IP into the table, and have something like:

    IP | Hits | Time | LastPage

    And check if the user's IP already exists in the database, and if it does then it won't create a new row each time. Then just do

    [code]
    $sql = "SELECT ip FROM stats WHERE ip ='$_SERVER[REMOTE_ADDR]'";
    $res = mysql_query($sql);
    $res2 = mysql_fetch_assoc($res);
    $num = mysql_numrows($res);

    if($num > 0){
    //update stats
    }else {
    $sql = "INSERT INTO stats (`ip`) VALUES('$_SERVER[REMOTE_ADDR]')";
    $res = mysql_query($sql);
    };
    [/code]
  2. Ok, I'm just making a news system with categories and what not. But I keep getting the mysql_error

    [code]Unknown column 'test2' in 'field list'[/code]

    Test 2 was the new category I was trying to name it.

    when trying to update the category name. Below is the code, and the main focus is on the bottom of the code

    [code]
    <?php

    function category(){
    $catsql = "SELECT * FROM cat";
    $catres = mysql_query($catsql);
    $num = mysql_numrows($catres);

    if($num == 0){
    echo "No Categories, <a href=".'news.php?act=cat'.">click here</a> to add one";
    }else {

    echo "Category: <select name=category>";
    while ($row1 = mysql_fetch_array($catres, MYSQL_BOTH)) {
        print "<option value=$row1[id]>$row1[catname]</option>";
    }
    mysql_free_result($catres);
    echo "</select>";
    }
    }

    if(!$act){
    ?>
    <table border=0 cellspacing=2 cellpadding=2>
    <tr><td colspan=2 align=right>
    <h3>Add A Category</h3>
    <form name=addcat method=post action="<?=$PHP_SELF?>">
    <tr><td class=cA>
    Category Name:<td><input type=text name=catname size=30>
    <tr><td colspan=2 align=left>
    <input type=hidden name=action value=addcat>
    <input type=submit value="Add Category">
    </form>
    <tr><td colspan=2 align=right>
    <h3>Rename A Category</h3>
    <form name=addcat method=post action="<?=$PHP_SELF?>">
    <tr><td class=cA>
    <? category() ?>
    <td>
    Rename To:<input type=text name=newcatname>
    <tr><td colspan=2><input type=hidden name=action value=rename>
    <input type=submit value="Rename">
    </form>
    </table>
    <?php
    };
    ?>
    <?php
    if($act == addcat){
    $catname = $_POST[catname];

    if(!$catname){
    echo "You did not specify a category name";
    }else{
    $add = "INSERT INTO cat (`catname`) VALUES('$catname')";
    $addres = mysql_query($add) or die(mysql_error());
    echo "Category $catname has been added to the categories list";
    };
    };

    if($act == rename){
    $newcat = $_POST[newcatname];
    $newid = $_POST[category];

    if(!$newcat){
    echo "You did not specify a new category name ID #$newid";
    }else{
    $ren = "UPDATE `cat` SET catname =$newcat WHERE id='$newid'";
    $rena = mysql_query($ren) or die(mysql_error());
    echo "Category ID #$newid has been changed to $newcat";
    };
    };
    ?>
    [/code]
  3. Ok, I'm trying to make something that the administrator can delete a certain news id by clicking the Delete $id button. Below is my code. I get no errors, it just doesn't work.

    [code]
    <?php
    $pg = $_GET[pg];
    if(!$pg){
    $pg = 1;
    };
    $amount = "$pg * 12";
    if(!$act){
    ?>
    <table border=0 cellspacing=2 cellpadding=2>
    <tr><td colspan=4 align=right>
    <h3>Delete News</h3>
    <tr><td colspan=4>&nbsp;
    <tr><td class=cA>
    ID<td class=cA>Title<td class=cA>Message<td class=cA>Author
    <?php
    $find = "SELECT * FROM news ORDER BY `id` ASC";
    $gofi = mysql_query($find);

    while($row1 = mysql_fetch_assoc($gofi)){
    echo "
    <tr><td>$row1[id]<td>$row1[title]<td>$row1[body]<td>$row1[poster]
    <tr><td colspan=4 align=right>
    <form name=delete$row1[id] method=post action='".$PHP_SELF."'><input type=hidden name=delid value=$row1[id]><input type=submit value='Delete ".$row1[id]."'></form>";
    }
    mysql_free_result($gofi);
    echo "</table>";
    };
    ?>
    <?php
    if($act == delid){
    $delid = $_POST[delid];
    $del = "DELETE FROM `news` WHERE id=$delid";
    $delgo = mysql_query($del) or die(mysql_error());
    echo "News ID $delid deleted";
    };
    ?>
    [/code]
  4. I stated that wrong.

    How would I be able to create a document that checks if the user submitted a word that was in an array. If they did submit a word it would come up with a message saying like "blah blah blah bad word." And if no word from the array was found it would complete the task.

    Something like:

    [code]
    <?php
    $mesg = $_POST[message];
    $array = array("words,that,the,user,cannot,submit");

    if($mesg == $array){
    echo "bad word";
    }else {
    echo "fine statement";
    };
    ?>
    [/code]

    something like that, but how would I make it to check if $mesg included any of the words in $array
  5. You aren't connecting correctly.

    [code]
    <?php
    $username = "username";
    $password = "password";
    $hostname = "localhost";
    $database = "database";
    $dbh = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");
    $db = mysql_select_db($database,$dbh) or die("Unable to connect to datase");
         
    $select = mysql_query("SELECT * FROM `dates_table`");
    echo "<table><tr><td>Week</td><td>Date Start</td><td>Notes</td><td>Date End</td></tr>";
    while ($info = mysql_fetch_assoc($select)) {
    $week = $info['week'];
    $date_start = $info['date_start']; 
    $notes = $info['notes'];
    $date_end = $info['data_end'];

    echo "<tr>
    <td>
    $week
    </td>
    <td>
    $date_start
    </td>
    <td>
    $notes
    </td>
    <td>
    $date_end
    </td></tr>";
    }

    mysql_free_result($select);
    echo "</table>";
    ?>
    [/code]

    you're going to have to select a database to connect to
×
×
  • 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.