-
Posts
289 -
Joined
-
Last visited
Everything posted by Noskiw
-
I'm having trouble with my code which is supposed to define the <title> of the page. This is my class code in which the $row variable is defined. <?php class page{ var $host; var $user; var $pass; var $db; function connect(){ $con = mysql_connect($this->host, $this->user, $this->pass) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function check_page($id){ $sql = "SELECT * FROM page WHERE id='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $id = $row['id']; $page = $row['page']; $title = $row['title']; } } } ?> And my index page <?php include './class/class.php'; $obj = new page(); $obj->host = 'localhost'; $obj->user = 'root'; $obj->pass = ''; $obj->db = 'p_web'; $obj->connect(); ?> <html> <head> <title><?php $obj->check_page(1); ?></title> <link href="./css/style.css" rel="stylesheet" /> </head> <body> <center> <div id="mainC" style="text-align: left;"> <div id="header"> header here </div> <div id="mainC"> <div id="navbar"> <div class="button"> <a href="#">Home</a> </div> <div class="button"> <a href="#">About</a> </div> <div class="button"> <a href="#">Portfolio</a> </div> <div class="button"> <a href="#">Tutorials</a> </div> <div class="button"> <a href="#">Contact</a> </div> </div> </div> </div> </center> </body> </html> This is getting increasingly frustrating. If anyone could help me, I would be very appreciative.
-
of course it's possible, but I don't read minds. instead of ?id, what is it you're looking to do. I'm looking for something like ?p= What's with the function? I want it so it goes into the check_page function because it's in a class which I have related to my index page and all of my other pages. I want to be able to define the page by a function that will thereby define the title from the database. I'll show you my index page. <?php include './class/class.php'; $obj = new page(); $obj->host = 'localhost'; $obj->user = 'root'; $obj->pass = ''; $obj->db = 'p_web'; $obj->connect(); ?> <html> <head> <title><?php $obj->check_page($row['title']); ?></title> <link href="./css/style.css" rel="stylesheet" /> </head> <body> <center> <div id="mainC" style="text-align: left;"> <div id="header"> header here </div> <div id="mainC"> <div id="navbar"> <div class="button"> <a href="#">Home</a> </div> <div class="button"> <a href="#">About</a> </div> <div class="button"> <a href="#">Portfolio</a> </div> <div class="button"> <a href="#">Tutorials</a> </div> <div class="button"> <a href="#">Contact</a> </div> </div> </div> </div> </center> </body> </html> And my class file <?php class page{ var $host; var $user; var $pass; var $db; function connect(){ $con = mysql_connect($this->host, $this->user, $this->pass) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function check_page($id){ $page = $_GET['page']; $sql = "SELECT * FROM page WHERE id='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $page = $row['page']; $title = $row['title']; } } } ?> This makes it a lot easier than writing all the code on one page and having it look messy. This keeps it organised. (From my perspective at least)
-
Can you possibly make it so it isn't like "?id". Sorry And so it goes in my function...
-
<title><?php $obj->check_page($row['title']); ?></title> Quick Edit: This is what I used ^ This I have no idea whether it will work or not... The function is also different now... function check_page(){ $sql = "SELECT * FROM page"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $title = $row['title']; $page = $row['page']; } }
-
OK.... This is my code now... <?php function check_page($page){ $sql = "SELECT * FROM page"; $res = mysql_query($sql) or die(mysql_error()); } ?> I DO have the connection variable in there but it isn't relevant. I'm not sure where to go from here... And I do have some rows inserted
-
I would like to know how to create a function in which I can check what page it is on so I can change the "<title>" tag according to the page. It would be complicated and padantic yes... But I have no clue in where to start. This is my code so far <?php class page{ function check_page($page){ } } ?> I'm completely stuck. And yes, I have purposely done this function in a class. Putting it in a class makes it a whole lot simpler for me.
-
You've just solved 2 problems with 1 solution. Thankyou :')
-
I did that, it made no difference, and I have no idea how to define the $id.
-
function update_content($p){ $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); $id = mysql_real_escape_string($id); if (!$title || !$body) { if (!$title) { echo "<p>The Title is needed</p>"; } if (!$body) { echo "<p>The Body is needed</p>"; } echo "<p><a href='update-content.php?id=" . $id . "'>Try again!</a></p>"; } else { $sql = "UPDATE cms_content SET title='".$title."', body='".$body."' WHERE id='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); echo "Row updated successfully"; } } This is the new function. And this is there error. Warning: Missing argument 1 for modernCMS::update_content(), called in C:\xampp\htdocs\cms\admin\index.php on line 33 and defined in C:\xampp\htdocs\cms\class\cms_class.php on line 114 The Title is needed The Body is needed Try again! EDIT: I've managed to fix the errors, but this time, it says that the row has been updated successfully, but yet, it hasn't updated... Any thoughts? EDIT No2: It seems that when it says 'try again' The id wont show up, so the web address shows http://localhost/cms/admin/update-content?id=Which is annoying. I'm guessing that it has to do with this line echo "<p><a href='update-content.php?id=" . $id . "'>Try again!</a></p>";
-
Please help. It's getting frustrating
-
<?php if($_POST['add']): $obj->add_content($_POST); elseif($_POST['update']): $obj->update_content($_POST); endif; ?> The error is Fatal error: Call to undefined method modernCMS::update_content() in C:\xampp\htdocs\cms\admin\index.php on line 31 The line is $obj->update_content($_POST); The function is... function update_content() { $title = mysql_real_escape_string($title); $body = mysql_real_escape_string($body); $id = mysql_real_escape_string($id); if (!$title || !$body) { if (!$title) { echo "<p>The Title is needed</p>"; } if (!$body) { echo "<p>The Body is needed</p>"; } echo "<p><a href='update-content.php?id=".$id."'>Try again!</a></p>"; } else { $sql = "UPDATE cms_content SET title = '$title', body='$body' WHERE id='$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Row updated successfully"; } } This function is also needed... function update_content_form($id) { $id = mysql_real_escape_string($id); $res = mysql_query("SELECT * FROM cms_content WHERE id='$id'") or die(mysql_error ()); $row = mysql_fetch_assoc($res); echo '<form method="POST" action="index.php"> <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="' . $row['id'] . '" /> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="' . $row['title'] . '" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40">' . $row['body'] . '</textarea> </div> <input type="submit" name="submit" value="Edit" /> </form>'; } } This is buggging me. Thanfully after this is sorted, the website will be finished :')
-
<?php function update_content_form($id){ $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id='" . $id . "'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); ?> <form method="POST" action="index.php"> <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="<?php $row['id'] ?>" /> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="<?php $row['title'] ?>" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40"><?php $row['body'] ?></textarea> </div> <input type="submit" name="submit" value="Edit" /> </form> <?php } } ?> What I'm trying to do is edit a post. Yet when I go to the update-content section, there's nothing there. I'm guessing my SQL query sucks.
-
Are there any other methods that I could use? And the class file is basically the foundation of a specific page. I'll post one of my main pages. <?php include 'class/cms_class.php'; $obj = new modernCMS(); //Setup Our Connection Vars $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = ''; $obj->db = 'modernCMS'; //Connect To Our DB $obj->connect(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UFT-8" /> <title>My Modern CMS</title> <link href="./style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="page-wrap"> <?php include'nav.php'; ?> <?php if(isset($_GET['id'])): $obj->get_content($_GET['id']); else: $obj->get_content(); endif; ?> </div> </body> </html> That basically sets up the page and posts what is on there by using $obj->get_content(); This makes it easier than typing in the whole page on one document and makes it look a lot cleaner.
-
<?php class modernCMS { var $host; var $username; var $password; var $db; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = ''){ $id = mysql_real_escape_string($id); if($id != ''){ $sql = "SELECT * FROM cms_content WHERE id='" . $id . "'"; $return = "<a href='index.php'>Go back to content</a>"; }else{ $sql = "SELECT * FROM cms_content ORDER BY id DESC"; } $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0){ while($row = mysql_fetch_assoc($res)){ echo "<h1><a href='index.php?id=" . $row['id'] . "'>" . $row['title'] . "</a></h1>"; echo "<p>" . $row['body'] . "</p>"; echo $return; } }else{ echo "<p>ID for post does not exist!</p>"; } } function manage_content(){ echo '<div id="manage">'; $sql = "SELECT * FROM cms_content"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res)==0){ echo "There are no posts. <a href='add-content.php'>Add one now!</a>"; } while($row = mysql_fetch_assoc($res)){ echo" <div> <h2 class='title'>" . $row['title'] . "</h2> <span class='actions'><a href='update-content.php?id='" . $row['id'] . "'>Edit</a> | <a href='?delete=" . $row['id'] . "'>Delete</a></span> </div>"; } echo "</div>"; } function delete_content($id){ if(!$id){ return false; }else{ $id = mysql_real_escape_string($id); $sql = "DELETE FROM cms_content WHERE id = '" . $id . "'"; $res = mysql_query($sql) or die(mysql_error()); echo "Content Deleted Succesffuly"; } } function add_content(){ if(!$_POST['submit']){ echo "<form action='add-content.php' method='POST'>"; echo "<tr><td><input type='text' name='title' /></td></tr><br /><br />"; echo "<tr><td><textarea name='body' width='140' height='40'></textarea></td></tr><br />"; echo "<tr><td colspan='2'><input type='submit' name='submit' value='Post' /></td></tr>"; echo "</form>"; }else{ $id = $_POST['id']; $title = mysql_real_escape_string($_POST['title']); $body = mysql_real_escape_string($_POST['body']); $sql = "INSERT INTO cms_content (id, title, body) VALUES('".$id."','".$title."','".$body."')"; $res = mysql_query($sql) or die(mysql_error()); echo "Row successfully entered"; } } } ?> I would like to add some javascript to make you enter a password to view a page. But I have a method in javascript. Unfortunately, when I try to add it, if you click cancel, you can get on the page anyway. Here is my code. <script type="text/javascript"> var password = "nomnom"; function prtyo(){ var p = prompt("Enter password"); if(p != password){ var cancel = confirm("Wrong password, do you want to try again?"); if (cancel){ prtyo(); } }else{ window.location = "add-content.php"; } } prtyo(); </script> I would add it here so it looks like <?php function add_content(){ ?> <script type="text/javascript"> var password = "nomnom"; function prtyo(){ var p = prompt("Enter password"); if(p != password){ var cancel = confirm("Wrong password, do you want to try again?"); if (cancel){ prtyo(); } }else{ window.location = "add-content.php"; } } prtyo(); </script> <?php if(!$_POST['submit']){ echo "<form action='add-content.php' method='POST'>"; echo "<tr><td><input type='text' name='title' /></td></tr><br /><br />"; echo "<tr><td><textarea name='body' width='140' height='40'></textarea></td></tr><br />"; echo "<tr><td colspan='2'><input type='submit' name='submit' value='Post' /></td></tr>"; echo "</form>"; }else{ $id = $_POST['id']; $title = mysql_real_escape_string($_POST['title']); $body = mysql_real_escape_string($_POST['body']); $sql = "INSERT INTO cms_content (id, title, body) VALUES('".$id."','".$title."','".$body."')"; $res = mysql_query($sql) or die(mysql_error()); echo "Row successfully entered"; } } } ?> Unfortunately, it makes you re-enter the password over and over and over again. Which gets increasingly annoying each time. Any help would be apreciated
-
Thank you. That worked. All I have now is a javascript error so I shall post that in the javascript help section
-
Thanks, that worked But I seem to be having another error I want to be able to put 'smiley faces' on my post's title(s). But yet, I always get an error. is there a way of fixing this? <?php class modernCMS { var $host; var $username; var $password; var $db; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = ''){ $id = mysql_real_escape_string($id); if($id != ''){ $sql = "SELECT * FROM cms_content WHERE id='" . $id . "'"; $return = "<a href='index.php'>Go back to content</a>"; }else{ $sql = "SELECT * FROM cms_content ORDER BY id DESC"; } $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0){ while($row = mysql_fetch_assoc($res)){ echo "<h1><a href='index.php?id=" . $row['id'] . "'>" . $row['title'] . "</a></h1>"; echo "<p>" . $row['body'] . "</p>"; echo $return; } }else{ echo "<p>ID for post does not exist!</p>"; } } function manage_content(){ echo '<div id="manage">'; $sql = "SELECT * FROM cms_content"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res)==0){ echo "There are no posts. <a href='add-content.php'>Add one now!</a>"; } while($row = mysql_fetch_assoc($res)){ echo" <div> <h2 class='title'>" . $row['title'] . "</h2> <span class='actions'><a href='update-content.php?id='" . $row['id'] . "'>Edit</a> | <a href='?delete=" . $row['id'] . "'>Delete</a></span> </div>"; } echo "</div>"; } function delete_content($id){ if(!$id){ return false; }else{ $id = mysql_real_escape_string($id); $sql = "DELETE FROM cms_content WHERE id = '" . $id . "'"; $res = mysql_query($sql) or die(mysql_error()); echo "Content Deleted Succesffuly"; } } function add_content(){ if(!$_POST['submit']){ echo "<form action='add-content.php' method='POST'>"; echo "<tr><td><input type='text' name='title' /></td></tr><br />"; echo "<textarea name='body' width='140' height='40'></textarea><br />"; echo "<tr><td colspan='2'><input type='submit' name='submit' value='Post' /></td></tr>"; echo "</form>"; }else{ $id = $_POST['id']; $title = htmlspecialchars($_POST['title']); $body = htmlspecialchars($_POST['body']); $sql = "INSERT INTO cms_content (id, title, body) VALUES('".$id."','".$title."','".$body."')"; $res = mysql_query($sql) or die(mysql_error()); echo "Row successfully entered"; } } } ?> Look at this bit in particular function add_content(){ if(!$_POST['submit']){ echo "<form action='add-content.php' method='POST'>"; echo "<tr><td><input type='text' name='title' /></td></tr><br />"; echo "<textarea name='body' width='140' height='40'></textarea><br />"; echo "<tr><td colspan='2'><input type='submit' name='submit' value='Post' /></td></tr>"; echo "</form>"; }else{ $id = $_POST['id']; $title = htmlspecialchars($_POST['title']); $body = htmlspecialchars($_POST['body']); $sql = "INSERT INTO cms_content (id, title, body) VALUES('".$id."','".$title."','".$body."')"; $res = mysql_query($sql) or die(mysql_error()); echo "Row successfully entered"; } } I want to be able to add 'smiley faces' such as ":')" and ":'(" and "" But it won't let me because of the punctuation and it affects the sql query I'm assuming. Which really sucks
-
<?php class modernCMS { var $host; var $username; var $password; var $db; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = ''){ $id = mysql_real_escape_string($id); if($id != ''){ $sql = "SELECT * FROM cms_content WHERE id='" . $id . "'"; $return = "<a href='index.php'>Go back to content</a>"; }else{ $sql = "SELECT * FROM cms_content ORDER BY id DESC"; } $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0){ while($row = mysql_fetch_assoc($res)){ echo "<h1><a href='index.php?id=" . $row['id'] . "'>" . $row['title'] . "</a></h1>"; echo "<p>" . $row['body'] . "</p>"; echo $return; } }else{ echo "<p>ID for post does not exist!</p>"; } } function manage_content(){ echo '<div id="manage">'; $sql = "SELECT * FROM cms_content"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo" <div> <h2 class='title'>" . $row['title'] . "</h2> <span class='actions'><a href='#'>Edit</a> | <a href='?delete=" . $row['id'] . "'>Delete</a></span> </div>"; } echo "</div>"; } function delete_content($id){ if(!$id){ return false; }else{ $id = mysql_real_escape_string($id); $sql = "DELETE FROM cms_content WHERE id'" . $id . "'"; $res = mysql_query($sql) or die(mysql_error()); echo "Content Deleted Succesffuly"; } } } ?> My error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM cms_content WHERE id'1'' at line 1 I'm assuming that it's an error with this line $sql = "DELETE FROM cms_content WHERE id'" . $id . "'";
-
Yes it was. Although, I did forget to include my $obj->connect(); The first time round I put the "<?php" tags instead of "<?=". Thank you anyway
-
I'm using windows vista and XAMPP
-
cms_class.php <?php class modernCMS { var $host; var $username; var $password; var $db; function connect(){ $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content(){ $sql = "SELECT * FROM cms_content"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo "<h1>" . $row['title'] . "</h1>"; echo "<p>" . $row['body'] . "</p>"; } } } ?> index.php <?php include 'class/cms_class.php'; $obj = new modernCMS(); //Setup Our Connection Vars $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = ''; $obj->db = 'modernCMS'; //Connect To Our DB $obj->connect(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UFT-8" /> <title>My Modern CMS</title> <link href="./style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="page-wrap"> <?=$obj->get_content()?> </div> </body> </html> The problem that I seem to be having is when I load my page on "localhost", all at shows me is 'getcontent()?>' which is the function that I used in the divider. I know it probably seems like a really simple question to answer. But it's starting to get fairly annoying.
-
That works great thank you I know this is a little silly of me to ask... But I don't fully understand it, could you maybe explain? If it's a bother to explain, then you don't have to, I know you've helped me a lot, but explaining it would help me to become a better coder. EDIT: Nevermind. I took a 14TH!... look at the code, and finally understood it. It took a while, but I finally got there But what I don't understand is where you got the "el" from. EDIT NO. 2: "el" is just the name of the variable of the textbox I assume. I must seem like a complete dumbass to you now
-
Ok, that works, i've also added an "onblur" function to it, but is there anyway to check if there is text in the box, and if so, it won't do the onblur. It would have to be in a function wouldn't it? <script> var text = document.getElementById(text); function check(text){ if(document.text.value){ } } </script> <input type="text" name="text" value="Default Stuff" onfocus="this.value='';" onblur="this.value='Default Stuff';" /> OK, I got stuck at the value part.... this does take a lot of thinking about... And unfortunately, I'm fairly new to javascript.
-
Just like on facebook, I would like to be able to have a random bit of text in my textbox before the user has even though about clicking on it, then when they have clicked on it, the text disappears. Yet this proves impossible to me... -.- I imagine that it uses "document.getElementById()" but again, I'm lost. Javascript is fairly new to me, I know where to use "getElementById()", but I can't make it work.
-
That's exactly what i'm looking for. Thankyou