| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Jan 2006 Location: Portland, Oregon
Posts: 2,102
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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
?>
<? ????: 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! |
| |
| | #2 (permalink) |
| NamePros Member Join Date: Mar 2006
Posts: 62
![]() | 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 |
| |
| | #3 (permalink) |
| NamePros Member Join Date: Jul 2006
Posts: 62
![]() ![]() | 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.... |
| |
| | #4 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |