NameSilo

Some PHP Help please

Spaceship Spaceship
Watch
Impact
44
Ok guys/girls, I been killing myself over this all morning.

This is what i'm trying to do, I need html to show up on another page, so I make an admin panel where someone puts in an ID an a Name.

This is what the code is,

Code:
<?php
include ("config.php");
//initilize PHP

if($_POST['submit']) //If submit is hit
{
   //convert all the posts to variables:
   $name = $_POST['name'];
   $id = $_POST['id'];
   
   

  
  $id2 = "<tr>
    <td width='55'><div align='center'><img src='nonew.png' width='32' height='32'></div></td>
    <td width='345'><a href='vforum.php?id=$id' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'><font color='#333333'>$name</font></a></td>
    <td width='60'><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>
      <?=mysql_num_rows(mysql_query('SELECT * FROM `thread` WHERE fid =$id'))?>
    </div></td>
    <td><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>
      <?=mysql_num_rows(mysql_query('SELECT * FROM `reply` WHERE fid =$id'))?>
    </div></td>
    <td>
      <span style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>
      <?php
     $last_thread_info = mysql_fetch_array(mysql_query('SELECT * FROM `thread` WHERE fid = '$id' ORDER BY `id` ASC LIMIT 1'));
     $last_reply_query = mysql_query('SELECT * FROM `reply` WHERE topicid = '$last_thread_info[id]' ORDER BY `id` ASC LIMIT 1');
     if (mysql_num_rows($last_reply_query) > 0){
     $last_reply_info = mysql_fetch_array($last_reply_query);
     echo 'By ".stripslashes($last_reply_info["author"])." At ".$last_reply_info["date"]';
     }
     else {
     echo "By ".stripslashes($last_thread_info["author"])." At ".$last_thread_info["date"];
     }
     ?>
      </span> </td>
  </tr>";
   
   
   //Insert the values into the correct database with the right fields
   //mysql table = news
   //table columns = id, title, message, who, date, time
   //post variables = $title, $message, '$who, $date, $time
   $result=MYSQL_QUERY("INSERT INTO forums (id,name)".
      "VALUES ('NULL', '$id2', '$name')"); 

mysql_query("INSERT INTO `forums` ( `id` , `name` ) VALUES ('$id2', '$name')") or die(mysql_error());

    //confirm
   echo "Query Finished"; 
}
else
{
// close php so we can put in our code
?>
<form method="post" action="send.php">
<TABLE>
<TR>
   <TD>ID:</TD>
   <TD><INPUT TYPE='TEXT' NAME='id' VALUE='' size=60></TD>
</TR>
<TR>
  <TD colspan="2"><strong>Please use a number higher than the previous forum. Example, your first forum is 1, your second would be 2, 3, and so on. Mixing up your id's may cause problems.</strong></TD>
  </TR>
<TR>
   <TD>Forum Name :</TD>
   <TD><INPUT TYPE='TEXT' NAME='name' VALUE='' size=60></TD>
</TR><br>
<TR>
   <TD></TD><br>
   <TD><INPUT TYPE="submit" name="submit" value="submit"></TD> 
</TR>
</TABLE>
</form>

<?
} //close the else statement
?>
<?

The config has the mysql info. I can send the info the db and everything else fine, my problem is the variable $id2.

I need variable $id and $name to be in it (as you can see) and to send to the mysql as it's doing.

I know $id2 is a bit messy but I am getting all sorts of erorrs on strings/etc. I tried many different ways, but I need it to have " and not ', so it can be readable when i put the viarable in a php (eg, <? echo "$id"; ?>) and taking it from the database.

Any help would be appreciated :)

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Yes, it's indeed messy, I suggest you at least to concat the string. eg:

$string = "abc";
$string .= "def";

It makes debugging easier (see the line number). However, there are many ways to improve this code snippet, for one, use functions or better yet an OOP class to make the code much more readable and maintainable. Good luck
 
0
•••
He's right..

Try something more like:

$id2 = $id2 = "<tr>
<td width='55'><div align='center'><img src='nonew.png' width='32' height='32'></div></td>
<td width='345'><a href='vforum.php?id=$id' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'><font color='#333333'>$name</font></a></td>
<td width='60'><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>"

$id2 .= mysql_num_rows(mysql_query('SELECT * FROM `thread` WHERE fid =$id'));

$id2 .= "</div></td>
<td><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>"

etc....
 
0
•••
PHP:
   $id2 = "
<tr>
   <td width='55'><div align='center'><img src='nonew.png' width='32' height='32'></div></td>
   <td width='345'><a href='vforum.php?id=$id' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'><font color='#333333'>$name</font></a></td>
   <td width='60'><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>" . mysql_num_rows(mysql_query("SELECT * FROM thread WHERE fid=$id")) . "</div></td>
   <td><div align='center' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>" . mysql_num_rows(mysql_query("SELECT * FROM reply WHERE fid=$id")) . "</div></td>
   <td><span style='font-family: Arial, Helvetica, sans-serif; font-size: 12px'>";

    $last_thread_info = mysql_fetch_array(mysql_query("SELECT * FROM thread WHERE fid=$id ORDER BY id ASC LIMIT 1"));
    $last_reply_query = mysql_query("SELECT * FROM reply WHERE topicid=$last_thread_info[id] ORDER BY id ASC LIMIT 1");

    if (mysql_num_rows($last_reply_query) > 0)
    {
        $last_reply_info = mysql_fetch_array($last_reply_query);
        $id2 .= 'By ' . stripslashes($last_reply_info['author']) . ' At ' . $last_reply_info['date'];
    }
    else
    {
        $id2 .= 'By ' . stripslashes($last_thread_info['author']) . ' At ' . $last_thread_info['date'];
    }

    $id2 .= "</span> </td>
</tr>";
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back