Jump to content
Larry Ullman's Book Forums

Angus Pearson

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by Angus Pearson

  1. ".......'Title' = '2011-07-06', 'Date' = 'Hello World - Post 1', at line 1

     

    Hope you can spot your error. Strings don't work inside datetime datatypes, you know ;)

    Yea, but I don't know why it is trying to insert the variables into the wrong column. All of the inputs in the HTML have the correct names, and the only thing I could think of is whether the order of the variables in the function statement effect this??? Should these produce different results?

    e.g.:

    function getPosts($id, $Title, $Date)
    
    //and
    
    function getPosts($Date, $Title, $id)
    

  2. Sorry for the second post... Just discovered what tab does...

     

    //From edit.php
    <form action="doedit.php" method="post">
    <table>
    <tr>
    <td class="descriptor"><label for="Div_Class">Class: (tpost / ipost / cpost)</label></td> 
    <td><input type="text" name="Div_Class"  class="inputother" value="<?php echo $post['Div_Class']; ?>" /></td>
    </tr>
    //And so on... All of the variables have this layout, and $id is in a hidden input
    
    //From doedit.php
    <?php
    include('includes/cms_functions.php');
    
    if(isset($_POST['submit'])) {
    if(isset($_POST['Div_Class'])) {
    	if(isset($_POST['Date'])) {
    		if(isset($_POST['Title'])) {
    			if(isset($_POST['Author'])) {
    				editPost($_POST['Div_Class'], $_POST['Date'], $_POST['Title'], $_POST['Author'], $_POST['Content'], $_POST['id']);
    				header ("Location: posts.php");
    			} else { echo "Add the Author.."; include ("create.php"); }
    		} else { echo "Add the Title..."; include ("create.php"); }
    	} else { echo "Add the Date..."; include ("create.php"); }
    } else { echo "Add the Div Class..."; include ("create.php"); }
    } else {
    header("Location: create.php");
    }
    

     

    When I changed the action to addPost, it worked fine, and added a new post. I am kinda stuck for what to do.

     

    function addPost($Div_Class, $Title, $Date, $Author, $Content) {
    $query = mysql_query("INSERT INTO posts VALUES(null, 0, '$Div_Class', '$Title', '$Date', '$Author', '$Content')") or die(mysql_error());
    }
    

  3. Thanks for the help and support - However, as those errors were cleared up, everything worked, but now I am trying to put an edit feature in my simple CMS, but I am hitting a lot of walls: Firstly, I have to escape EVERY apostrophe and other special character otherwise I get a MySQL error, and now no matter what I do in the code, I get this error:

     

    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 'Div_Class' = 'tpost', 'Title' = '2011-07-06', 'Date' = 'Hello World - Post 1',  at line 1

     

    Basically, this is how it's supposed to work:

     

    Function gets current data ----------> The User can Edit that data, ----------> A simple PHP file puts it

    from MySQL, and puts it in then submits it through a function that inserts

    the input boxes. the new data into MySQL

     

    But this hasn't worked. Here is the code: (I won't include HTML and the form)

     

    //From cms_functions.php
    
    function editPost($Div_Class, $Title, $Date, $Author, $Content, $id) {
    $id = (int) $id;
    $query = mysql_query("UPDATE posts SET 'Div_Class' = '$Div_Class', 'Title' = '$Title', 'Date' = '$Date', 'Author' = '$Author', 'Content' = '$Content' WHERE ID ='$id'") or die(mysql_error());
    header("Location: posts.php");
    }
    
    --------------------------------------------------------
    
    //From edit.php
    <tr>
    <td class="descriptor"><label for="Div_Class">Class: (tpost / ipost / cpost)</label></td> 
    			<td><input type="text" name="Div_Class"  class="inputother" value="<?php echo $post['Div_Class']; ?>" /></td>
    		</tr>
    
    

  4. Hi, I couldn't find a topic that was relevant, so here goes:

     

    Pretymuch the first major PHP script i am atempting to write has kinda died: It's only a few lines long, and the small bit of MySQL connection code doesn't work for some reason that I can't work out. This is the code:

     

    index.php:
    <?php
    include('includes/functions.php');
    
    getPosts();
    ?>
    
    connect.php:
    <?php
    
    define('DB_HOST','localhost');
    define('DB_USER','root');
    define('DB_PASS','');
    define('DB_NAME','cmsdb');
    
    $connection = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die(mysql_error());
    mysql_select_db(DB_NAME) or die(mysql_error());
    ?>
    
    functions.php:
    <?php
    
    include('includes/connect.php');
    
    function getPosts() {
    $query = mysql_query("SELECT * FROM posts") or die(mysql_error());
    while($post = msql_fetch_assoc($query)) {
    	echo "<h2>" . $post['Title'] . " by" . $post['Author'] . "</h2>";
    	echo $post['Content'];
    }
    }
    ?>
    

     

    errors:

     

    Fatal error: Call to undefined function msql_fetch_assoc() in C:\xampp\htdocs\cms\includes\functions.php on line 7

×
×
  • Create New...