NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Some PHP Help please :)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-01-2006, 01:39 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Camron's Avatar
Join Date: Jan 2006
Location: Portland, Oregon
Posts: 2,102
Camron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud of
 



VA Tech Memorial 9/11/01 :: Never Forget Cancer Survivorship Child Abuse

Some PHP Help please :)


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.
????: NamePros.com http://www.namepros.com/programming/233888-some-php-help-please.html
????: NamePros.com http://www.namepros.com/showthread.php?t=233888

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.
__________________
HostingFuze.com Premium Master Reseller Services | 99.9% Uptime Guaranteed SLA | Starting at $4.95/mo
Basic Reseller Hosting @ HostFz.com - Services starting as low as $1.95/mo!
Camron is offline  
Old 09-02-2006, 11:06 AM   #2 (permalink)
NamePros Member
Join Date: Mar 2006
Posts: 62
123finder.com is an unknown quantity at this point
 



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
__________________
123finder.com - Browse dictionary domains & 4-9 letter domains
123finder.com is offline  
Old 09-03-2006, 08:48 AM   #3 (permalink)
NamePros Member
Join Date: Jul 2006
Posts: 62
jasonphd will become famous soon enoughjasonphd will become famous soon enough
 



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>
????: NamePros.com http://www.namepros.com/showthread.php?t=233888
<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....
jasonphd is offline  
Old 09-03-2006, 11:04 AM   #4 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
PHP Code:
   $id2 "
????: NamePros.com http://www.namepros.com/showthread.php?t=233888
<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'];
????: NamePros.com http://www.namepros.com/showthread.php?t=233888
    }
    else
    {
        
$id2 .= 'By ' stripslashes($last_thread_info['author']) . ' At ' $last_thread_info['date'];
    }

    
$id2 .= "</span> </td>
</tr>"

Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:36 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger