| View previous topic :: View next topic |
| Author |
Message |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Thu Nov 20, 2008 2:16 pm Post subject: more php problems |
|
|
i am making a forum in php. (dont ask me why its just something to pass the time.)
but i'm having a little trouble with this one line of code that wont let me view the page. could andyone here make it work for me?
ill give the link of code that doesnt work and the source code.
all code
| Code: | <?php
session_start();
include'../global.php';
?>
<html>
<head>
<title>Nostrich's Forum</title>
<link rel="stylesheet" href="../style3.css" type="text/css" />
<script language="javascript" type="text/javascript">
function confirmLogout(){
var agree = confirm("Are you sure you wish to log out?");
if(agree){
return true ;
else{
return false ;
}
}
</script>
</head>
<body>
<center>
<div id="holder">
<div id="userInfo">
<?php
if($_SESSION['uid']){
$sql = "SELECT * FROM users WHERE id = '" . $_SESSION['uid'] . "'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
session_destroy();
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}else{
$row = mysql_fetch_assoc($res);
echo "Welcome back,<a href=\"./forum-index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" onClick='confirmLogout()'>Logout</a>\n";
echo "<br>\n";
if($row['admin'] == '1'){
echo "<a href=\"./admin.php\">Adminastrators section</a>\n";
}
}
}else{
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}
?>
</div>
<div id="content">
<?php
if($_SESSION['uid']){
$sql3 = "SELECT admin FROM users WHERE id='".$_SESSION['uid']."'";
$res3 = mysql_query($sql3) or die(mysql_error());
if(mysql_num_rows($res3) == 0){
echo "Please login to your account!\n";
}else{
$row2 = mysql_fetch_assoc($res3);
if($row2['admin'] != '1'){
echo "You are not allowed to view this page!\n";
}else{
$act = $_GET['act'];
$acts = array('create_cat','create_subcat');
$actions = array('create_cat' => 'Create Forum Category','create_subcat' => 'Create Forum Sub Category!');
$x= 1;
$c = count($actions);
foreach($actions AS $url => $link){
$bull = ($x == $c) ? "" : " • ";
echo "<a href=\"./index.php?act=" . $url . "\">" . $link . "</a>" . $bull . "\n";
$x++;
}
echo "<br><br>\n";
if(!$act || !in_array($act,$acts)){
echo "Please choose an option from above to contine!\n";
}else{
if($act == 'create_cat'){
if(!$_POST['submit']){
echo "<table border='0' cellspacing ='3' cellpadding='3'>\n";
echo "<form method='post' action='index.php?act=create_cat'>\n";
echo "<tr><td>Category Name:</td><td><input tpye='text' name='name'><td></tr>\n";
echo "<tr><td>Admin Only?</td><td><input type='checkbox' name='admin' value='1'></td></tr>\n";
echo "<tr><td colspan='2' align='right'><input type='submit' name='submit' value='Create Forum Category'></td></tr>\n";
echo "</form></table>\n";
}else{
$name = $_POST['name'];
$admin = $_POST['admin'];
if($name){
if(strlen($name) < 3 || strlen($name) > 32){
echo "The forum category name cannot exceed 32 characters but must be more than 3 chracters!\n";
}else{
$sql4 = "SELECT * FROM forum_cats WHERE name='".$name."'";
$res4 = mysql_query($sql4) or die(mysql_error());
if(mysql_num_rows($res4) > 0){
echo "The category name has already been used, please supply another one!\n";
}else{
$admin_check = ($admin == '1') ? "1" : "0";
$sql5 = "INSERT INTO forum_cats (name,admin) VALUES ('".$name."','".$admin_check."')";
$res5 = mysql_query($sql5) or die(mysql_error());
echo "The forum category <b>" . $name . "</b>has succsessfully been created!\n";
}
}
}else{
echo "You must supply a category name!\n";
}
}
}
if($act == 'create_subcat'){
if(!$_POST['submit']){
echo "<table border='0' cellspacing='3' cellpadding='3'>\n";
echo "<form method='post' action='index.php?act=create_subcat'>\n";
echo "<tr><td>Forum Category</td><td><select name='cat'><option value='0'>Please Choose...</option>\n";
$sql6 = "SELECT * FROM forum_cats ORDER BY id ASC";
$res6 = mysql_query($sql6) or die(mysql_error());
if(mysql_num_rows($res6) == 0){
echo "</select><br>No categories exist!\n";
}else{
while($row3 = mysql_fetch_assoc($res6)){
echo "<option value=\"".$row3['id']."\">".$row3['name']."</option>\n";
}
}
echo "</select></td></tr>\n";
echo "<tr><td>Sub Cat. Name</td><td><input type='text' name='name'></td></tr>\n";
echo "<tr><td>Description</td><td><textarea name='desc'></textarea></td></tr>\n";
echo "<tr><td colspan='2' align='right'><input type='submit' name='submit' value='Create Sub Cat.'></td></tr>\n";
echo "</form></table>\n";
}else{
$cat = $_POST['cat'];
$name = $_POST['name'];
$desc = $_POST['desc'];
if($cat && $name && $desc){
$sql7 = "SELECT * FROM forum_cats WHERE id='".$cat."'";
$res7 = mysql_query($sql7) or die(mysql_error());
if(mysql_num_rows($res7) == 0){
echo "The forum category you supplied does not exist!\n";
}else{
$sql8 = "SELECT * FROM forum_sub_cats WHERE name='".$name."' AND cid='".$cat."'";
$res8 = mysql_query($sql8) or die(mysql_error());
if(mysql_num_rows($res8) > 0){
echo "The forum sub category already exists within the main category!\n";
}else{
if(strlen($desc) > 255){
echo "The description must be under 255 characters.\n";
}else{
$row4 = mysql_fetch_assoc($res7);
$sql9 = "INSERT INTO `forum_sub_cats` (`cid`,`name`,`desc`,`admin`) VALUES ('".$cat."' && '".$name."' && '".$desc."' && '".$row4['admin']."')";
$res9 = mysql_query($sql9) or die(mysql_error());
}
}
}
}
}
}
}
}
}
?>
</div>
</div>
</center>
</body>
</html> |
line that doesn't work
| Code: | | $sql9 = "INSERT INTO `forum_sub_cats` (`cid`,`name`,`desc`,`admin`) VALUES ('".$cat."' && '".$name."' && '".$desc."' && '".$row4['admin']."')"; |
help please. +rep to anyone who helps. |
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Thu Nov 20, 2008 3:11 pm Post subject: |
|
|
| Code: |
$sql9 = "INSERT INTO `forum_sub_cats` (`cid`,`name`,`desc`,`admin`) VALUES ('".$cat."', '".$name."', '".$desc."', '".$row4['admin']."')";
|
You might want to read some MySQL tutorials... |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Thu Nov 20, 2008 3:17 pm Post subject: |
|
|
| thats what i did before, that didnt work either. |
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Thu Nov 20, 2008 5:46 pm Post subject: |
|
|
| Is there any error? |
|
| Back to top |
|
 |
SXGuy I post too much
Reputation: 0
Joined: 19 Sep 2006 Posts: 3551
|
Posted: Thu Nov 20, 2008 6:00 pm Post subject: |
|
|
| question, why didnt u host your forum on a host that has free php and mysql wizards? would have saved so much time. |
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Thu Nov 20, 2008 8:40 pm Post subject: Re: more php problems |
|
|
| ghostrider1337 wrote: | line that doesn't work
| Code: | | $sql9 = "INSERT INTO `forum_sub_cats` (`cid`,`name`,`desc`,`admin`) VALUES ('".$cat."' && '".$name."' && '".$desc."' && '".$row4['admin']."')"; |
|
1) Only use ' ' in your sql statements to encapsulate a string value. The table & column names, integer values, etc.. all have no use for them.
2) Your values are seperated by && instead of a comma.
| Code: | | $sql9 = "INSERT INTO forum_sub_cats (cid, name, desc, admin) VALUES ('$cat', '$name', '$desc', '" . $row4['admin'] . "')"; |
3) Assuming your are inserting the values from left to right as they are defined in the table, you can simplify this by not specifying the columns.
| Code: | | $sql9 = "INSERT INTO forum_sub_cats VALUES ('$cat', '$name', '$desc', '" . $row4['admin'] . "')"; |
4) Don't forget to post the error message.
-edit-
@jackyyll Oops, didn't notice you already cleaned that up. ^^
If you still have problems, check your database, make sure the table / columns you are trying to insert data into exist, and the data you insert is in the correct format for that column. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Fri Nov 21, 2008 2:00 am Post subject: |
|
|
| still doesn't work. i don't get what the problem is. maybe its the whole script? |
|
| Back to top |
|
 |
LolSalad Grandmaster Cheater
Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
Posted: Fri Nov 21, 2008 4:12 am Post subject: |
|
|
| ghostrider1337 wrote: | | still doesn't work. i don't get what the problem is. maybe its the whole script? |
You still haven't posted the error. Error reporting in PHP is usually able to tell you exactly what the problem is, and it's usually easy to fix once you know what the problem is. _________________
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Fri Nov 21, 2008 10:05 am Post subject: |
|
|
| the problem is that the whole page doesn't show up. maybe find a different host? |
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Fri Nov 21, 2008 10:38 am Post subject: |
|
|
It's not uncommon for web hosts to disable php error reporting for security reasons. Temporarily add this to the top of your page,
| Code: | <?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?> |
Refresh and you should hopefully see some error messages now. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Fri Nov 21, 2008 10:50 am Post subject: |
|
|
still nothing apprears. should i check the curly brackets? sorry man but ur idea didnt work. ill try to find a different host that is localhost enabled.
EDIT:Yet again i needed another curly bracket. its appearing fine now, but when i get an error saying
| Code: | | Column count doesn't match value count at row 1 |
|
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Fri Nov 21, 2008 11:40 am Post subject: |
|
|
| If nothing appears it's most likely that you've forgotten a ; ... go through your code and make sure they're all there.. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Fri Nov 21, 2008 11:46 am Post subject: |
|
|
i have done that. it appears but the error is now | Code: | | Column count doesn't match value count at row 1 |
|
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Fri Nov 21, 2008 1:47 pm Post subject: |
|
|
Don't code tags preserve tabs?
Yep. So... USE FUCKING TABS. Holy god, you will never complete your project when it looks like a heap of random characters with no structure. Honestly...
| Code: | <?php
session_start();
include'../global.php';
?>
<html>
<head>
<title>Nostrich's Forum</title>
<link rel="stylesheet" href="../style3.css" type="text/css" />
<script language="javascript" type="text/javascript">
function confirmLogout(){
var agree = confirm("Are you sure you wish to log out?");
if(agree){
return true ;
else{
return false ;
}
}
</script>
</head>
<body>
<center>
<div id="holder">
<div id="userInfo">
<?php
if($_SESSION['uid']){
$sql = "SELECT * FROM users WHERE id = '" . $_SESSION['uid'] . "'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
session_destroy();
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}else{
$row = mysql_fetch_assoc($res);
echo "Welcome back,<a href=\"./forum-index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" uuups='confirmLogout()'>Logout</a>\n";
echo "<br>\n";
if($row['admin'] == '1'){
echo "<a href=\"./admin.php\">Adminastrators section</a>\n";
}
}
}else{
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}
?>
</div>
<div id="content">
<?php
if($_SESSION['uid']){
$sql3 = "SELECT admin FROM users WHERE id='".$_SESSION['uid']."'";
$res3 = mysql_query($sql3) or die(mysql_error());
if(mysql_num_rows($res3) == 0){
echo "Please login to your account!\n";
}else{
$row2 = mysql_fetch_assoc($res3);
if($row2['admin'] != '1'){
echo "You are not allowed to view this page!\n";
}else{
$act = $_GET['act'];
$acts = array('create_cat','create_subcat');
$actions = array('create_cat' => 'Create Forum Category','create_subcat' => 'Create Forum Sub Category!');
$x= 1;
$c = count($actions);
foreach($actions AS $url => $link){
$bull = ($x == $c) ? "" : " • ";
echo "<a href=\"./index.php?act=" . $url . "\">" . $link . "</a>" . $bull . "\n";
$x++;
}
echo "<br><br>\n";
if(!$act || !in_array($act,$acts)){
echo "Please choose an option from above to contine!\n";
}else{
if($act == 'create_cat'){
if(!$_POST['submit']){
echo "<table border='0' cellspacing ='3' cellpadding='3'>\n";
echo "<form method='post' action='index.php?act=create_cat'>\n";
echo "<tr><td>Category Name:</td><td><input tpye='text' name='name'><td></tr>\n";
echo "<tr><td>Admin Only?</td><td><input type='checkbox' name='admin' value='1'></td></tr>\n";
echo "<tr><td colspan='2' align='right'><input type='submit' name='submit' value='Create Forum Category'></td></tr>\n";
echo "</form></table>\n";
}else{
$name = $_POST['name'];
$admin = $_POST['admin'];
if($name){
if(strlen($name) < 3 || strlen($name) > 32){
echo "The forum category name cannot exceed 32 characters but must be more than 3 chracters!\n";
}else{
$sql4 = "SELECT * FROM forum_cats WHERE name='".$name."'";
$res4 = mysql_query($sql4) or die(mysql_error());
if(mysql_num_rows($res4) > 0){
echo "The category name has already been used, please supply another one!\n";
}else{
$admin_check = ($admin == '1') ? "1" : "0";
$sql5 = "INSERT INTO forum_cats (name,admin) VALUES ('".$name."','".$admin_check."')";
$res5 = mysql_query($sql5) or die(mysql_error());
echo "The forum category <b>" . $name . "</b>has succsessfully been created!\n";
}
}
}else{
echo "You must supply a category name!\n";
}
}
}
if($act == 'create_subcat'){
if(!$_POST['submit']){
echo "<table border='0' cellspacing='3' cellpadding='3'>\n";
echo "<form method='post' action='index.php?act=create_subcat'>\n";
echo "<tr><td>Forum Category</td><td><select name='cat'><option value='0'>Please Choose...</option>\n";
$sql6 = "SELECT * FROM forum_cats ORDER BY id ASC";
$res6 = mysql_query($sql6) or die(mysql_error());
if(mysql_num_rows($res6) == 0){
echo "</select><br>No categories exist!\n";
}else{
while($row3 = mysql_fetch_assoc($res6)){
echo "<option value=\"".$row3['id']."\">".$row3['name']."</option>\n";
}
}
echo "</select></td></tr>\n";
echo "<tr><td>Sub Cat. Name</td><td><input type='text' name='name'></td></tr>\n";
echo "<tr><td>Description</td><td><textarea name='desc'></textarea></td></tr>\n";
echo "<tr><td colspan='2' align='right'><input type='submit' name='submit' value='Create Sub Cat.'></td></tr>\n";
echo "</form></table>\n";
}else{
$cat = $_POST['cat'];
$name = $_POST['name'];
$desc = $_POST['desc'];
if($cat && $name && $desc){
$sql7 = "SELECT * FROM forum_cats WHERE id='".$cat."'";
$res7 = mysql_query($sql7) or die(mysql_error());
if(mysql_num_rows($res7) == 0){
echo "The forum category you supplied does not exist!\n";
}else{
$sql8 = "SELECT * FROM forum_sub_cats WHERE name='".$name."' AND cid='".$cat."'";
$res8 = mysql_query($sql8) or die(mysql_error());
if(mysql_num_rows($res8) > 0){
echo "The forum sub category already exists within the main category!\n";
}else{
if(strlen($desc) > 255){
echo "The description must be under 255 characters.\n";
}else{
$row4 = mysql_fetch_assoc($res7);
$sql9 = "INSERT INTO `forum_sub_cats` (`cid`,`name`,`desc`,`admin`) VALUES ('".$cat."' && '".$name."' && '".$desc."' && '".$row4['admin']."')";
$res9 = mysql_query($sql9) or die(mysql_error());
}
}
}
}
}
}
}
}
}
?>
</div>
</div>
</center>
</body>
</html> |
Thats close using automated tools _________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Last edited by nog_lorp on Fri Nov 21, 2008 2:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Fri Nov 21, 2008 1:50 pm Post subject: |
|
|
| not in dreamweaver. |
|
| Back to top |
|
 |
|