Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 04-01-2005, 08:27 AM   #1 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
[PHP] Report Script Help

Hi i am making my own bug system so that if a user has a problem with my website they can report it and it will get fixed.

However no i am trying to add the ability so I can comment/reply to there report.

This is the code i use:
Code:
<?php require "connect.php"; $query = "SELECT bugreport_id, website, title, type, status, author, os, browser, report, DATE_FORMAT(date, '%c/%d/%Y') as date2 FROM bugreports WHERE bug_id='$id'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo "<tr><td colspan=\"2\" style=\"text-align: center;\">Failed to find bug report.</td></tr>"; } while ($row = mysql_fetch_assoc($result)) { $row['report'] = str_replace("\n", "\n<br />\n", $row['report']); echo "<tr style=\"background: #000033; font-weight: bold; color: #FFFFFF;\"> <td style=\"text-align: left;\" colspan=\"2\">Track ID: ".$row['bug_id']."</td> </tr> <tr> <td style=\"background: #D9D9D9; width: 15%; text-align: right; padding-right: 5px;\">Website:</td> <td style=\"background: #EFEFEF;\">".$row['website']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Title:</td> <td style=\"background: #EFEFEF;\">[".$row['type']."] ".$row['title']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Report written at:</td> <td style=\"background: #EFEFEF;\">".$row['date2']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Report written by:</td> <td style=\"background: #EFEFEF;\">".$row['author']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Operating System:</td> <td style=\"background: #EFEFEF;\">".$row['os']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Web Browser:</td> <td style=\"background: #EFEFEF;\">".$row['browser']."</td> </tr> <tr> <td style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Status:</td> <td style=\"background: #EFEFEF;\">".$row['status']."</td> <tr> <td valign=\"top\" style=\"text-align: right; padding-right: 5px; background: #D9D9D9;\">Report:</td> <td style=\"background: #EFEFEF;\">"; echo stripslashes($row['report']); echo "<br /><br /></td> </tr> </table>"; echo "<br /><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" style=\"width: 100%; border-collapse: collapse\"> <tr> <td valign=\"top\" style=\"text-align: left; background: #000033; font-weight: bold; color: #FFFFFF;\">Developer Reply</td> </tr> <tr> <td style=\"padding: 5px; background: #EFEFEF;\">reply here</td> </tr>"; } ?>
I have 2 tables bugreports and replys. Here is the layout for each table.

bugreports
bugreport_id
website
title
type
status
author
os
browser
report
date

replys
reply_id
bugreport_id
reply



How can i make my script pull the reply and put it under the correct report. And if this is no reply how can i make it show and error like 'There is no reply currently'?

Last edited by Limit : 04-01-2005 at 08:31 AM.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-02-2005, 10:47 PM   #2 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
do another query, this time, of the replys table. Add "WHERE bugreport_id = '[id here]'" to the query string. Use a while loop to cycle through the results and echo them wherever you want them to show up.

So... english to code translation:

Code:
$query2 = "SELECT * FROM replys WHERE bugreport_id='" . $row['bugreport_id'] . "'"; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)) { // Do all of your echoing here }
Hope this help you out. Let me know if you need more help.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-03-2005, 06:45 AM   #3 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
k they worked fine it now pulls them out. thx

How do i make the script you gave me so if there is no reply echo 'There is no reply currently'.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-03-2005, 04:26 PM   #4 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
Code:
$results = mysql_num_rows($result2); if ($results < 1) { echo "There is no reply currently."; }
add to the end.
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 07:52 AM   #5 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
thanxs that works

I'm now having a problem with the submit form. I fill in the details in the form and it gets sent to another page where it inserts it into the database. However i only want it to input the $_POST variables from the form instead of $_GET aswell. Because if someone enters insert.php?title=232&website=32423& it will input it into the DB and i don't want this to happen.

Any ideas how to fix it:-
Code:
<? // ********************************************************************** begin checking for characters if ($status == "") { $status = ""; } if ($website == "") { $website = ""; } if ($type == "") { $type = ""; } if(!ereg("[a-zA-z]+", $title)) { $title = ""; } if(!ereg("[a-zA-z]+", $name)) { $name = ""; } if ($os == "") { $os = ""; } if ($browser == "") { $browser = ""; } if ($version == "") { $version = ""; } if(!ereg("[a-zA-z]+", $report)) { $report = ""; } // ********************************************************************** end checking for characters // ********************************************************************** begin error messages if ($status == ""){ $error .= "<li>Please select a status</li>"; } if ($website == ""){ $error .= "<li>Please select a website</li>"; } if ($type == ""){ $error .= "<li>Please select a type</li>"; } if ($title == ""){ $error .= "<li>Please write a bug title</li>"; } if ($name == ""){ $error .= "<li>Please type your full name</li>"; } if ($os == ""){ $error .= "<li>Please select an operating system</li>"; } if ($browser == ""){ $error .= "<li>Please select a web browser</li>"; } if ($version == ""){ $error .= "<li>Please write a version for the browser</li>"; } if ($report == ""){ $error .= "<li>Please fill in a bug report</li>"; } // ********************************************************************** end error messages echo " <table align=\"center\" width=\"50%\" cellpadding=\"4\" cellspacing=\"0\" border=\"0\" style=\"border-collapse: collapse\"> <tr> <th style=\"background: #000033; font-weight: bold; color: #FFFFFF; text-align: center;\">Information</th> </tr> <tr> <td class=\"row1\" height=\"80\">"; if ($error != ""){ echo "<div class=\"text\" align=\"center\">The following fields are either incomplete or invalid:</div>"; echo "<div class=\"text\"><ul>"; echo "$error"; echo "</ul></div>"; echo "</td></tr>"; echo "<tr><th style=\"background: #EFEFEF;\"><input type=\"button\" name=\"button\" value=\"Try Again\" onClick=\"javascript:history.go(-1)\" class=\"button\"></th></tr>"; } else{ require "connect.php"; require "common.php"; $status = quote_smart($_POST['status']); $website = quote_smart($_POST['website']); $type = quote_smart($_POST['type']); $title = quote_smart($_POST['title']); $name = quote_smart($_POST['name']); $os = quote_smart($_POST['os']); $browser = quote_smart($_POST['browser']); $version = quote_smart($_POST['version']); $report = quote_smart($_POST['report']); $id = quote_smart($_POST['id']); $date2 = date("Y-m-d H:i:s"); $addbug = "INSERT INTO bugreports (bugreport_id, date, status, website, type, title, author, os, browser, version, report) VALUES ('$id', '$date2', '$status', '$website', '$type', '$title', '$name', '$os', '$browser', '$version', '$report');"; mysql_query($addbug) or die(mysql_error()); echo "<div class=\"text\" align=\"center\">The bug reported has been successfully added to the database.</div></td></tr>"; echo "<tr><th class=\"row3\"><input type=\"button\" value=\"Add another bug\" onClick=\"window.location='addbug.php'\"></th></tr>"; } echo "</table>"; ?>
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 12:26 PM   #6 (permalink)
Inactive
 
TeKBuzz's Avatar
 
Join Date: 11-12-03
Location: Ohio
Posts: 558
iTrader: 0 / 0%
Latest Blog:
None

TeKBuzz is liked by somebodyTeKBuzz is liked by somebodyTeKBuzz is liked by somebodyTeKBuzz is liked by somebody
Send a message via ICQ to TeKBuzz Send a message via AIM to TeKBuzz Send a message via MSN to TeKBuzz Send a message via Yahoo to TeKBuzz
just put the values in the query as $_POST[] values, forget setting the post values to a whole nother variable.
TeKBuzz is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 01:42 PM   #7 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
Make sure that register_globals is off in the php.ini file, otherwise, it will automatically convert the $_GET variables and/or $_POST variables to $variablename. This is done by default in later versions of PHP, but... you might want to check on that.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 02:03 PM   #8 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
Quote:
Originally Posted by TeKBuzz
just put the values in the query as $_POST[] values, forget setting the post values to a whole nother variable.
k but would i still be able to use my quote_smart($_POST['']) as this function is what uses mysql_real_escape_string to prevent ' etc and sql injection.

Also how can i turn register_globals off can i do it in htaccess.

Last edited by Limit : 04-04-2005 at 02:09 PM.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 05:04 PM   #9 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
magic quotes will take care of code injection hacks.

register_globals and magic_quotes are handled in the php.ini file in the server. To check if these are set, you can put the following code into a separate php file.

Code:
<?php phpinfo(); ?>
if they aren't set, you can do so either by modifying the php.ini file, or by using ini_set as follows:

Code:
<?php ini_set("register_globals", 0); ini_set("magic_quotes_gpc", 0); ini_set("magic_quotes_runtime", 0); ?>
Put the above on the top of a common file (one used on all pages). You can also put it on all of the files if you do not have a common file.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 05:07 PM   #10 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
it is possible that register_globals won't be set at runtime, so if it doesn't, or you must use .htaccess to control it, add the following entry into your htaccess.

Code:
php_flag register_globals off
sorry for the double post.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-04-2005, 11:24 PM   #11 (permalink)
Inactive
 
TeKBuzz's Avatar
 
Join Date: 11-12-03
Location: Ohio
Posts: 558
iTrader: 0 / 0%
Latest Blog:
None

TeKBuzz is liked by somebodyTeKBuzz is liked by somebodyTeKBuzz is liked by somebodyTeKBuzz is liked by somebody
Send a message via ICQ to TeKBuzz Send a message via AIM to TeKBuzz Send a message via MSN to TeKBuzz Send a message via Yahoo to TeKBuzz
thanx insitedev I've been wondering how to change the ini settings, its messed with me a few times ^_^
TeKBuzz is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 12:20 PM   #12 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
Quote:
TeKBuzz: thanx insitedev I've been wondering how to change the ini settings, its messed with me a few times ^_^
no problem. You can learn more about ini_set by going to http://www.php.net/ini_set. You can find a list of all of the possible settings here.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 12:38 PM   #13 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
i tried doing .htaccess one with
Code:
php_flag register_globals off
and my website produced error 500 for all pages.

is there any other way.

And i'd rather not user magic_quotes as what i'm doing now i have more control. So how would i insert my query with quote_smart($_POST['']) still on it.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 03:44 PM   #14 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
Hmm... first things first, does your host have register_globals enabled? No sense in trying to solve a problem that doesn't exist.

Your current way of assigning your modified $_POST data to a separate variable would work. Personally, I would just do it with addslashes / stripslashes. This is normally done automatically as a security precaution, but...

Of course, if your host does have magic quotes enabled to begin with, and you try adding slashes (whether by quote_smart or add slashes), you are going to end up adding slashes where you don't want. You should refer to your php.ini file (read it using the phpinfo(); function).
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 03:48 PM   #15 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
I now have register_globals disabled and magic_quote disabled as i wish to use my way of adding slashes by my function.

thanks for the help
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 03:52 PM   #16 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
BTW... you can add directly to the query line by putting them in the following format

Code:
$query = "INSERT INTO bugreports ... values ('" . quote_magic($_POST['bugreportid']) . "', '" . quote_magic($_POST['variablegoeshere']) . "')";
but.. make sure you check and see if magic_quotes_gpc is set in the php.ini file first. If it is and you use quote_magic (assuming you are using the one off of php.net) you will end up adding slashes to your query string that you don't want (\' would become \\\').
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 03:56 PM   #17 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
thanks thats shortened my code alot (and yes magic_quote is off don't like them lol).

is there a way a can shorten my check to see if the fields have text in.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-05-2005, 11:40 PM   #18 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
yeah, try this out.

Code:
$errors = array(); $req_fields = array("field1", "field2", "field3", "field4"); // Add fields here foreach ($req_fields as $field) { if (empty($_POST[$field])) { $errors[] = $field; } if (sizeof($errors) > 0) { echo "Please enter valid data for the following fields:"; foreach ($errors as $error) { echo '<br><font color="#ff0000">' . $field . '</font>'; } } else { // put your processing code here } }
This will allow you to add all of your required fields to the $req_fields array instead of writing code for each one.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-06-2005, 03:39 AM   #19 (permalink)
Inactive
 
Join Date: 10-29-03
Posts: 249
iTrader: 0 / 0%
Latest Blog:
None

Limit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the roughLimit is a jewel in the rough
hi again i'm having problems with the error checking when i have dropdown select boxes on the form. When i don't select any options it looks like this:

Quote:
Please enter valid data for the following fields:
websitePlease enter valid data for the following fields:
type
typePlease enter valid data for the following fields:
title
title
titlePlease enter valid data for the following fields:
name
name
name
namePlease enter valid data for the following fields:
os
os
os
os
osPlease enter valid data for the following fields:
browser
browser
browser
browser
browser
browserPlease enter valid data for the following fields:
version
version
version
version
version
version
versionPlease enter valid data for the following fields:
report
report
report
report
report
report
report

also when i put the quote_smart in the insert statement with the $_POST i get this error
Quote:
Fatal error: Cannot redeclare quote_smart() (previously declared in functions.php:3) in fucntions.php on line 3
. But it still adds it to the database but doesn't add slashes because of this error.

This is in my functions.php
Code:
function quote_smart($varr) { $var = trim($varr); $var = mysql_real_escape_string($var); return $var; }

Last edited by Limit : 04-06-2005 at 04:04 AM.
Limit is offline  
Add Post to del.icio.us
Reply With Quote
Old 04-06-2005, 11:07 AM   #20 (permalink)
Inactive
 
insitedev's Avatar
 
Join Date: 12-14-04
Posts: 108
iTrader: 0 / 0%
Latest Blog:
None

insitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebodyinsitedev is liked by somebody
Sorry, i messed up on the error checking code. Use this instead:

Code:
$errors = array(); $req_fields = array("field1", "field2", "field3", "field4"); // Add fields here foreach ($req_fields as $field) { if (empty($_POST[$field])) { $errors[] = $field; } } if (sizeof($errors) > 0) { echo "Please enter valid data for the following fields:"; foreach ($errors as $error) { echo '<br><font color="#ff0000">' . $field . '</font>'; } } else { // put your processing code here }
The previous one echoed the errors array for every missing field, which is the cause of the redundancy.

As for the redeclaration, it looks like you are including functions.php and fucntions.php in one of your files (probably once in your common, then again in the file that you are currently using). You might find out where you are including fucntions.php (looks like a misspelling).

If this isn't the problem, post up the insert statement and i'll take a look at that. You don't need to put "function" in front of the function call. In fact, this would cause the redeclaration. Without seeing the code, I don't know if this is the problem or not. I'm betting on an overlooked mistake of including that fucntions.php file.
insitedev is offline  
Add Post to del.icio.us
Reply With Quote