Jump to content


Photo

Pulling Data from the mysql data base


  • Please log in to reply
3 replies to this topic

#1 samsbc12

samsbc12
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 26 May 2006 - 06:45 PM

This is the display page and when you click the edit link it opens up the edit.php but i can not get the text to display in the form of the edit page

<? 
                  $username="******";
                  $password="******";
                  $database="******";

                  mysql_connect(localhost,$username,$password);
                  @mysql_select_db($database) or die( "Unable to select database"); 
                  $query="SELECT * FROM links";
                  $result=mysql_query($query);
                
                  //Count Number of rows in table
                  $num=mysql_numrows($result);
                      
                  //Close Connection
                    mysql_close();
                  //loop through
                  $i=0;
                  while ($i < $num) {
                     $id=mysql_result($result,$i,"id");
                    $category=mysql_result($result,$i,"category");
                    $name=mysql_result($result,$i,"name");
                    $description=mysql_result($result,$i,"description");
                    $link=mysql_result($result,$i,"link");
                    $mirror=mysql_result($result,$i,"mirror");
                    
                    echo "<b>Category:</b> $category <br>
                    Title: $name<br>
                    Description: $description<br>
                    <a href =\"$link\"> -Link-</a>";
                    if($mirror != ""){
                    echo"<a href =\"$mirror\"> -mirror-</a>";    
                    }
                    echo"<a href =\"edit.php?id=$id\"> -Edit-</a>";
                    echo"<br><br>";

                 $i++;
                }
                  ?>

edit.php

id does however display because its passed in the url

<?
                  $id=$_GET['id'];
                   $username="******";
                  $password="******";
                  $database="******";

                  mysql_connect(localhost,$username,$password);
                 @mysql_select_db($database) or die( "Unable to select database");
                 
                 $query=" SELECT * FROM links WHERE id='$id'";
                
                    $result=mysql_query($query);
                    $num=mysql_numrows($result);
                    mysql_close();
                    
                    $i=0;
                    while ($i < $num) {
                    $id = mysel_result($result, $i, "id");
                    $category=mysql_result($result,$i,"category");
                    $name=mysql_result($result,$i,"name");
                    $description=mysql_result($result,$i,"description");
                    $link=mysql_result($result,$i,"link");
                    $mirror=mysql_result($result,$i,"mirror");
                    
                      ++$i;
                    }

                  
                  ?>
                    
                    
                  
                  <form action="update.php" method="post">
                    <div align="left"><br>
                      <br>
                      <br>
                      <table width="730" border="0">
  <tr>
    <td align="right" valign="top"><strong>Id: </strong></td>
    <td valign="top"><input type="text" disabled="disabled"  name="id" value="<? echo $id; ?> "></td>
  </tr>
  <tr>
    <td align="right" valign="top"><strong>Category: </strong></td>
    <td valign="top"><input name="category" type="text" value="<?  $category; ?>"></td>
  </tr>
  <tr>
    <td align="right" valign="top"><strong>Name: </strong></td>
    <td valign="top"><input type="text" name="name"  value="<? echo $name; ?>"></td>
  </tr>
  <tr>
    <td align="right" valign="top"><strong><br>
      Description: </strong></td>
    <td valign="top"><textarea name="description" cols="40" rows="8"  ><? echo $description; ?></textarea></td>
  </tr>
  <tr>
    <td align="right" valign="top"><strong>Link: </strong></td>
    <td valign="top"><input type="text" name="link" value="<? echo $link; ?>"></td>
  </tr>
  <tr>
    <td align="right" valign="top"><strong>Mirror: </strong></td>
    <td valign="top"><input type="text" name="mirror" value="<? echo $mirror; ?>"></td>
  </tr>
  <tr>
    <td align="right" valign="top">&nbsp;</td>
    <td valign="top"><input name="Submit" type="Submit"></td>
  </tr>
</table>
                      <br>
<br>
                    </div>
                  </form>


#2 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 May 2006 - 07:02 PM

You have a mispelling in this bit of code.

Change this:

$id = mysel_result($result, $i, "id");

to this:

$id = mysql_result($result, $i, "id");

Other than that I did not see anything else wrong.

#3 samsbc12

samsbc12
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 26 May 2006 - 07:13 PM

[!--quoteo(post=377380:date=May 26 2006, 03:02 PM:name=freakus_maximus)--][div class=\'quotetop\']QUOTE(freakus_maximus @ May 26 2006, 03:02 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You have a mispelling in this bit of code.

Change this:

$id = mysel_result($result, $i, "id");

to this:

$id = mysql_result($result, $i, "id");

Other than that I did not see anything else wrong.
[/quote]


thanks man i didnt even see that, is there a way to get php to echo the errors when the page doesnt load?

#4 l33t_script3r

l33t_script3r
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 May 2006 - 06:08 AM

[!--quoteo(post=377382:date=May 27 2006, 07:13 AM:name=samsbc12)--][div class=\'quotetop\']QUOTE(samsbc12 @ May 27 2006, 07:13 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
thanks man i didnt even see that, is there a way to get php to echo the errors when the page doesnt load?
[/quote]

i think you can use die() or mysql_error() not sure how to use them though...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users