SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Links Script

  1. #1
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Links Script

    I'm having a couple of problems:
    1. It's not successfully editing the row in the manage section.
    2. In the manage section, if there is more than one word in a value, it will only dislay the first word in the text box.

    Here are the script sources:

    manage.php
    PHP Code:
    <table>
    <?
    /*****  A much better way  ******/
    $dbcnx = mysql_connect('localhost','jokeun','pass');
    mysql_select_db('jokeun');

    $result = mysql_query("SELECT url, sitename, description, email, url, ID FROM links ORDER BY sitename ASC") or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
        extract($row);
        ?>
        <tr>
        <td><a href="<?=$url?>"><font color="#000000" face="Arial" size="2"><?=$sitename?></a> - <?=$description?> <a href="manage.php?id=<?=$ID?>"><font color="#000000" face="Arial" size="2">Edit</a></td>
        </tr>
        <?
        }
    ?>
    <?
    if ($id) {
    $result = mysql_query("SELECT url, sitename, description, email, url, ID FROM links WHERE id='$id'") or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
        extract($row);
    }
    echo "<form action=edit.php method=get>";
    echo "E-Mail: <input type=text value=$email name=email><br>";
    echo "Site Name: <input type=text value=$sitename name=sitename><br>";
    echo "Site URL: <input type=text value=$url name=url><br>";
    echo "<input type=hidden value=$ID name=ID>";
    echo "Description: <input type=text value=$description name=description><br><input type=submit name=change value=change it><br><br>";
    }
    ?>
    </table>
    edit.php
    PHP Code:
    <?
    $connect = mysql_connect('localhost', 'jokeun', 'pass')
            or die ('Could not connect');

    mysql_select_db('jokeun');

    mysql_db_query("jokeun","UPDATE links SET url = '$url', sitename = '$sitename', description = '$description', email = '$email' WHERE ID = '$id'" )
    or die("Error! " . mysql_error());

    echo "The link has been edited. ";
    ?>
    Click <a href="manage.php">here</a> to edit another link.
    Any ideas?
    Last edited by Silverado4x4; Dec 7, 2001 at 21:20.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remember to put your variables in quotes. So if there are spaces in the variables they will get passed correctly. Also use POST not GET so you won't have to worry about it. Also var names are case sensitive so $ID is not the same as $id. In your form you have ID in your update statement you have $id. Change it to ID = '$ID'

    PHP Code:
    ?>
    <form action=edit.php method="post">
    E-Mail: <input type=text value="<?=$email?> name="email"><br>
    Site Name: <input type=text value="<?=$sitename?>" name="sitename"><br>
    Site URL: <input type=text value="<?=$url?>" name="url"><br>
    <input type=hidden value="<?=$ID?>" name="ID">
    Description: <input type=text value="<?=$description?>" name="description"><br><input type=submit name=change value="change it"><br><br>
    <?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy:

    I hope you get paid well, because you are awesome! Works like a charm. I may have another question later on...but for right now, I'm all good!

  4. #4
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, my next two problems, and most likely the last.

    1. The links aren't even showing up at the URL below.
    2. I want it to display a random set of 9 links, but I want it to display them in a certain way.

    You can see how it should look here:
    http://www.jokeuniversity.com/links/random.php

    Here is my code:

    random.php
    PHP Code:
    <?
    $dbcnx = mysql_connect('localhost','jokeun','pass');
    mysql_select_db('jokeun');

    $result = mysql_query("SELECT * FROM links ORDER BY rand() LIMIT 9") or die(mysql_error());
    $row = mysql_fetch_array($result); 
    $url = $row["url"];  
    $sitename = $row["sitename"];  
    $description = $row["description"];  
    $email = $row["email"];  

    function listlinks() {
        //make table
        echo "<table>";
                echo "<tr>";
                echo "<td><a href=\"$url\" alt=\"$description\"><font color=\"#000000\" face=\"Arial\" size=\"2\">$sitename</a></td>";
                echo "</tr>";
        echo "</table></center>";
    }

    ?>

         <?



         listlinks();

         ?>

    this is how I want it to look:
    <table with="50%" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
    <tr>
    <td width="33%">
    link 1
    </td>
    <td width="33%">
    link 2
    </td>
    <td width="33%">
    link 3
    </td>
    </tr>
    <tr>
    <td width="33%">
    link 4
    </td>
    <td width="33%">
    link 5
    </td>
    <td width="33%">
    link 6
    </td>
    </tr>
    <tr>
    <td width="33%">
    link 7
    </td>
    <td width="33%">
    link 8
    </td>
    <td width="33%">
    link 9
    </td>
    </tr>
    </table>

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post the corrected code I gave you last night you seem to have reverted back to the code with errors in it.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm so stupid, stupid, stupid!



    http://www.jokeuniversity.com/links/random.php

    Here's the correct code:
    PHP Code:
    <table>
    <?
    /*****  A much better way  ******/
    $dbcnx = mysql_connect('localhost','jokeun','pass');
    mysql_select_db('jokeun');

    $result = mysql_query("SELECT * FROM links ORDER BY rand() LIMIT 9") or die(mysql_error());
    while($row = mysql_fetch_array($result)) {
        extract($row);
        ?>
        <tr>
        <td><a href="<?=$url?>" alt="<?=$description?>"><font color="#000000" face="Arial" size="2"><?=$sitename?></a></td>
        </tr>
        <?
        }
    ?>
    </table>

    this is how I want it to look:
    <table with="50%" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
    <tr>
    <td width="33%">
    link 1
    </td>
    <td width="33%">
    link 2
    </td>
    <td width="33%">
    link 3
    </td>
    </tr>
    <tr>
    <td width="33%">
    link 4
    </td>
    <td width="33%">
    link 5
    </td>
    <td width="33%">
    link 6
    </td>
    </tr>
    <tr>
    <td width="33%">
    link 7
    </td>
    <td width="33%">
    link 8
    </td>
    <td width="33%">
    link 9
    </td>
    </tr>
    </table>

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh...

    PHP Code:
    <?
    $dbcnx = mysql_connect('localhost','jokeun','pass');
    mysql_select_db('jokeun');
    ?>
    <table with="50%" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000"><tr>
    <?
    $result = mysql_query("SELECT * FROM links ORDER BY rand() LIMIT 9") or die(mysql_error());
    $i = 1;
    while($row = mysql_fetch_array($result)) {
        extract($row);
        ?>
            <td>
                   <a href="<?=$url?>" alt="<?=$description?>">
                   <font color="#000000" face="Arial" size="2">
                   <?=$sitename?>
                   </font>
                   </a>
                </td>
            <?=(!($i%3) && $i mysql_num_rows($result)) ? '</tr><tr>' : (!($i%3) && $i == 9) ? '</tr>' ''?>
        <?
        $i++;
        }
    ?>
    </tr></table>
    Last edited by freddydoesphp; Oct 25, 2001 at 19:47.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are so awesome, works great!

    http://www.jokeuniversity.com/links/random.php


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
  •