Jump to content


Help with a tutorial system im working on.


9 replies to this topic

#1 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 04 February 2007 - 10:57 PM

Hello
I have been doing a tutorial system and hopig someone might be able to help resolve this problem.
When i go to create a catagory, it submits, yet when i go to submit a tutorial, there are no catagories listed.
I get no error msgs or anything.
The following are the two pages of coding if it helps.

"functions.php":
<?php 

function list_categories() { 
$query = mysql_query("SELECT * FROM tutorials_categories"); 
while($row = mysql_fetch_array($query)) { 
$query2 = mysql_query("SELECT * FROM tutorials WHERE cat_id = '$row[id]'"); 
if(mysql_num_rows($query2) == 0) { 
echo" $row[catname] |"; 
} 
else { 
echo" <a href='$self?action=cat&id=$row[id]'>$row[catname]</a> |"; 
} 
} 
} 

function list_unval_tutorials() { 
echo"<strong>Un-Validated tutorials</strong>"; 
$query = mysql_query("SELECT * FROM tutorials WHERE valid = '0' ORDER BY id DESC"); 
while($row = mysql_fetch_array($query)) { 
echo" 
<table width='100%'> 
  <tr> 
	<td width='60%'> 
	$row[tutname] 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=mod&id=$row[id]'>Modify</a> 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=delete&id=$row[id]'>Delete</a> 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=view&id=$row[id]'>View</a> 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=validate&id=$row[id]'>Validate?</a> 
	</td> 
  </tr> 
</table> 
"; 
} 
} 

function list_val_tutorials() { 
echo"<strong>Validated tutorials</strong>"; 
$query = mysql_query("SELECT * FROM tutorials WHERE valid = '1' ORDER BY id DESC"); 
while($row = mysql_fetch_array($query)) { 
echo" 
<table width='100%'> 
  <tr> 
	<td width='60%'> 
	$row[tutname] 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=mod&id=$row[id]'>Modify</a> 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=delete&id=$row[id]'>Delete</a> 
	</td> 
	<td width='10%'> 
	  <a href='$self?action=view&id=$row[id]'>View</a> 
	</td> 
  </tr> 
</table> 
"; 
} 
echo""; 
} 

function del_tutorial() { 
if(!isset($_POST['delete'])) { 
if($_GET['id']) { 
$id = (int)$_GET['id']; 
$query = "DELETE FROM tutorials WHERE id = '$id' LIMIT 1"; 
mysql_query($query); 
echo"Tutorial Deleted"; 

} 
} 
} 

function val_tutorial() { 
if(!isset($_POST['validate'])) { 
if($_GET['id']) { 
$id = (int)$_GET['id']; 
$query = "UPDATE tutorials SET valid = '1' WHERE id = '$id' LIMIT 1"; 
mysql_query($query); 
echo"Tutorial Validated"; 

} 
} 
} 

function view_tutorial() { 
if(!isset($_POST['view'])) { 
if($_GET['id']) { 
$id = (int)$_GET['id']; 
$query = mysql_query("SELECT * FROM tutorials WHERE id = '$id' LIMIT 1"); 
while($row = mysql_fetch_array($query)) { 
echo"You are viewing: <b>$row[tutname]</b>  
	 $row[tuttext]  
	 Some other info:  
	 Author: $row[authname] | Date posted: $row[date] | 
	 "; 
} 
} 
} 
} 

function add_tut() { 
if(!isset($_POST['add_tut'])) { 
echo" 
<form action='$self?action=add_tut' name='addtutorials' method='post'> 
<table> 
	<tr> 
		<td> 
		Tutorial name: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='tutname'> 
		</td> 
	</tr> 
		<td> 
		Author name: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='authname'> 
		</td> 
	</tr> 
	<tr> 
		<td> 
		Categories: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<select name='category'>"; 
		$query = mysql_query("SELECT * FROM tutorials_categories ORDER  

BY id ASC"); 
		while($row = mysql_fetch_array($query)) { 
		echo"<option value='$row[id]'>$row[catname]"; 
		} 
		echo" 
		</select> 
		</td> 
	</tr> 
	<tr> 
		<td>	 
		Image: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='image'> (40x40px) 
		</td> 
	</tr> 
	<tr> 
		<td> 
		Email: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='email'> 
		</td> 
	</tr> 
	<tr> 
		<td> 
		Tutorial Text: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<textarea cols='50' rows='20' name='tuttext'></textarea><br  

/> 
		</td> 
	</tr> 
	<tr> 
		<td> 
		Short description: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<textarea cols='50' rows='5' name='shortdes'></textarea><br  

/> 
		 

		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='submit' name='add_tutorials' value='submit  

tutorial'> 
		</td> 
	</tr> 
</table> 
</form>";	
} 
elseif(isset($_POST['add_tutorials']))  
{ 

$tutname = mysql_real_escape_string(strip_tags($_POST['tutname'])); 
$authname = mysql_real_escape_string(strip_tags($_POST['authname'])); 
$image = mysql_real_escape_string(strip_tags($_POST['image'])); 
$email = mysql_real_escape_string(strip_tags($_POST['email'])); 
$category = mysql_real_escape_string(strip_tags($_POST['category'])); 
$tuttext = $_POST['tuttext']; 
$shortdes = $_POST['shortdes']; 
$date = date("d.m.y"); 

$error = array(); 

if(empty($tutname)) { 
$error[] = "Please enter your tutorial name."; 
} 
if(empty($authname)) { 
$error[] = "Please enter your (the author's) name."; 
} 
if(empty($image)) { 
$error[] = "Please enter an image."; 
} 
if(empty($tuttext)) { 
$error[] = "Hello. You seem to have entered nothing into the tutorial text  

area."; 
} 
if(empty($shortdes)) { 
$error[] = "Enter a short description.";  
} 

if(count($error)>0) { 
echo"<font size='3' color='#CC0000'>ERROR:</font>"; 
foreach($error as $error2) 
echo"$error2"; 
} 

else { 
$mysql = "INSERT INTO tutorials(tutname, email, authname, image, tuttext, shortdes, valid, cat_id, date, views) VALUES('$tutname', '$email', '$authname', '$image', '$tuttext', '$shortdes', '0', '$category', '$date', '0')"; 

mysql_query($mysql); 

echo"Your tutorial has successfully been submitted for valadation."; 

} 
} 
} 

function mod_tut() { 
if(!isset($_POST['modify'])) { 
if($_GET['id']) { 
$id = (int)$_GET['id']; 
$query = mysql_query("SELECT * FROM tutorials WHERE id = '$id' LIMIT 1"); 
while($row = mysql_fetch_array($query)) { 
echo" 
<form name='modify' action='$self?action=mod&id=$row[id]' method='post'> 
<table> 
	<tr> 
		<td> 
		Tutorial name: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='modtutname' value='$row[tutname]'> 
		</td> 
	</tr> 
		<td> 
		Author name: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='modauthname' value='$row[authname]'> 
		</td> 
	</tr> 
	<tr> 
		<td>	 
		Image: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='modimage' value='$row[image]'>(40x40px)  
		</td> 
	</tr> 
	<tr> 
		<td> 
		Email: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='modemail' value='$row[email]'> 
		</td> 
	</tr> 

	<tr> 
		<td> 
		Tutorial Text: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<textarea cols='50' rows='20' name='modtuttext'>$row[tuttext]</textarea> 
		</td> 
	</tr> 
	<tr> 
		<td> 
		Short description: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<textarea cols='50' rows='5' name='modshortdes'>$row[shortdes]</textarea> 
		 

		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='submit' name='modify' value='modify'> 
		</td> 
	</tr> 
</table> 
</form>";	 
} 
} 
} 

elseif(isset($_POST['modify']))  
{ 

$modtutname = mysql_real_escape_string(strip_tags($_POST['modtutname'])); 
$modauthname = mysql_real_escape_string(strip_tags($_POST['modauthname'])); 
$modimage = mysql_real_escape_string(strip_tags($_POST['modimage'])); 
$modemail = mysql_real_escape_string(strip_tags($_POST['modemail'])); 
$modcategory = mysql_real_escape_string(strip_tags($_POST['modcategory'])); 
$modtuttext = $_POST['modtuttext']; 
$modshortdes = $_POST['modshortdes']; 

$err3 = array(); 

if(empty($modtutname)) { 
$error[] = "Please enter your tutorial name."; 
} 
if(empty($modauthname)) { 
$error[] = "Please enter your (the author's) name."; 
} 
if(empty($modimage)) { 
$error[] = "Please enter an image."; 
} 
if(empty($modtuttext)) { 
$error[] = "Hello. You seem to have entered nothing into the tutorial text  

area."; 
} 
if(empty($modshortdes)) { 
$error[] = "Enter a short description.";  
} 


if(count($err3)>0) { 
echo"ERROR:"; 
foreach($err3 as $err5)  
echo"$err5"; 
} 

else { 
if($_GET['id']) { 
$id = (int)$_GET['id']; 
$sql1 = "UPDATE tutorials SET tutname = '$modtutname' WHERE id = '$id'"; 
$sql2 = "UPDATE tutorials SET authname = '$modauthname' WHERE id = '$id'"; 
$sql3 = "UPDATE tutorials SET image = '$modimage ' WHERE id = '$id'"; 
$sql4 = "UPDATE tutorials SET email = '$modemail ' WHERE id = '$id'"; 
$sql5 = "UPDATE tutorials SET category = '$modcategory' WHERE id = '$id'"; 
$sql6 = "UPDATE tutorials SET tuttext = '$modtuttext' WHERE id = '$id'"; 
$sql7 = "UPDATE tutorials SET shortdes = '$modshortdes ' WHERE id = '$id'"; 

mysql_query($sql1); 
mysql_query($sql2); 
mysql_query($sql3); 
mysql_query($sql4); 
mysql_query($sql5); 
mysql_query($sql6); 
mysql_query($sql7); 

echo"Tutorial successfully updated."; 
} 
} 
} 
} 

function add_cat() { 
if(!isset($_POST['add_cat'])) { 
echo" 
<form action='$self?action=add_cat' name='addcategories' method='post'> 
<table> 
	<tr> 
		<td> 
		Tutorial name: 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='text' name='catname'> 
		</td> 
	</tr> 
	<tr> 
		<td> 
		<input type='submit' name='add_categories' value='submit category'> 
		</td> 
	</tr> 
</table> 
</form>";	
} 
elseif(isset($_POST['add_categories']))  
{ 

$catname = mysql_real_escape_string(strip_tags($_POST['catname'])); 

$error = array(); 

if(empty($catname)) { 
$error[] = "Please enter your tutorial name."; 
} 

if(count($error)>0) { 
echo"<font size='3' color='#CC0000'>ERROR:</font>"; 
foreach($error as $error2) 
echo"$error2"; 
} 

else { 
$mysql = "INSERT INTO tutorials_categories(catname) VALUES('$catname')"; 

mysql_query($mysql); 

echo"Your category has successfully been submitted."; 

} 
} 
} 

?>


And the "admin.php":
<?php 

include"connect.php"; 
include"functions.php"; 
echo"<a href='$self?action=add_tut'>Add Tutorial</a> | <a href='$self?action=add_cat'>Add Category</a> "; 
list_unval_tutorials(); 
echo""; 
list_val_tutorials(); 


switch($_GET['action']) { 
case"mod"; 
mod_tut(); 
break; 
case"add_tut"; 
add_tut(); 
break; 
case"add_cat"; 
add_cat(); 
break; 
case"validate"; 
val_tutorial(); 
break; 
case"delete"; 
del_tutorial(); 
break; 
case"view"; 
view_tutorial(); 
break; 
} 
?>


#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 05 February 2007 - 06:50 AM

I've cleaned up and made a few changes to your add_cat() function:

function add_cat() {

   if( !isset( $_POST['add_cat'] ) ) {

		  global $self;

	  echo"
	  <form action='$self?action=add_cat' name='addcategories' method='post'>
	  <table>
		  <tr>
			  <td>
			  Tutorial name:
			  </td>
		  </tr>
		  <tr>
			  <td>
			  <input type='text' name='catname'>
			  </td>
		  </tr>
		  <tr>
			  <td>
			  <input type='submit' name='add_categories' value='submit category'>
			  </td>
		  </tr>
	  </table>
	  </form>";	

   } elseif ( isset( $_POST['add_categories'] ) ) {

   $catname = mysql_real_escape_string(strip_tags($_POST['catname']));
   
   #Error checking - uncomment to see what is being set to $catname
   #echo $catname;

   $error = array();

   if( empty( $catname ) ) {
	  $error[] = "Please enter your tutorial name.";
   }

   if( count( $error ) > 0 ) {
	  echo"<font size='3' color='#CC0000'>ERROR:</font>";
	  foreach($error as $error2) {
		 echo"$error2";
	  }	  
   } else {
   $mysql = "INSERT INTO `tutorials_categories` SET `catname` = '".$catname."' ";
	  if( mysql_query( $mysql ) ) {
		 echo"Your category has successfully been submitted.";
	  } else {
		 echo mysql_error();
	  }
   }

}

Also I have not seen $self being set anywhere, if you have set $self in functions.php, you will have to global the variable to use it within all the functions, that also may be your problem:

I have updated my code with the:

global $self;

If that is the problem you will have to do that in every single function.

Matt

Edited by Mr. Matt, 05 February 2007 - 06:54 AM.


#3 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 05 February 2007 - 07:12 AM

Thank you matt for the responce.
But now after the updating i get this error:
Parse error: parse error, unexpected $ in /homepages/7/d94330934/htdocs/tutorials/functions.php on line 459

Line 459 being ?>

#4 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 05 February 2007 - 08:24 AM

Ah my mistake:

function add_cat() {

   if( !isset( $_POST['add_cat'] ) ) {

		  global $self;

	  echo"
	  <form action='$self?action=add_cat' name='addcategories' method='post'>
	  <table>
		  <tr>
			  <td>
			  Tutorial name:
			  </td>
		  </tr>
		  <tr>
			  <td>
			  <input type='text' name='catname'>
			  </td>
		  </tr>
		  <tr>
			  <td>
			  <input type='submit' name='add_categories' value='submit category'>
			  </td>
		  </tr>
	  </table>
	  </form>";	

   } elseif ( isset( $_POST['add_categories'] ) ) {

   $catname = mysql_real_escape_string(strip_tags($_POST['catname']));
  
   #Error checking - uncomment to see what is being set to $catname
   #echo $catname;

   $error = array();

   if( empty( $catname ) ) {
	  $error[] = "Please enter your tutorial name.";
   }

   if( count( $error ) > 0 ) {
	  echo"<font size='3' color='#CC0000'>ERROR:</font>";
	  foreach($error as $error2) {
		 echo"$error2";
	  }	  
   } else {
	  $mysql = "INSERT INTO `tutorials_categories` SET `catname` = '".$catname."' ";
	  if( mysql_query( $mysql ) ) {
		 echo"Your category has successfully been submitted.";
	  } else {
		 echo mysql_error();
	  }
   }

   }
}

Matt

#5 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 05 February 2007 - 06:33 PM

Ok for some odd reason, i am back to square one having the same issue.
Once i submit a catagory and then go into and create a tutorial.
In the drop down option for topics, there are none what so ever.

Should i post the entire script?

#6 blacky

    Young Padawan

  • Members
  • Pip
  • 34 posts
  • Gender:Male

Posted 05 February 2007 - 08:14 PM

ok, i think i found something... but after so long of being "semantically correct", i don't know if it's just semantics, or if your html is actually fine...

anyway, you have this in in your add_tut function.

while($row = mysql_fetch_array($query)) { 
		echo"<option value='$row[id]'>$row[catname]"; 
		}

so i think you forgot to add </option> :) or... it could be semantics... but it would explain why no error message is showing, what you should do is post the output html of the "add tutorial" page

Edited by blacky, 05 February 2007 - 08:15 PM.


#7 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 05 February 2007 - 09:55 PM

Well having modified using your suggestion, had no results.
As for any html, it is all there in the functions file.
As well as in the admin.php file.
So this suggestion had no results.
Using:
while($row = mysql_fetch_array($query)) { 
		echo"<option value='$row[id]'>$row[catname]</option>"; 
		}

Nice try and thanks, but still no luck.

#8 blacky

    Young Padawan

  • Members
  • Pip
  • 34 posts
  • Gender:Male

Posted 05 February 2007 - 10:26 PM

i mean the actual ouput html of the php...

while($row = mysql_fetch_array($query)) {
echo"<option value='$row[id]'>$row[catname]</option>";
}

should prodcue

<option value='1'>category name</option>
<option value='2'>category name</option>
etc....

but i dont know what it IS actually doing.. maybe its just producting all the options, but not echoing a cat. name... or maybe it completely didn't echo out any options.

#9 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 05 February 2007 - 11:02 PM

Yes by rights it should.
But for reasons i do not know, it wont.

#10 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 06 February 2007 - 07:09 PM

so any other ideas that might resolve this?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users