Jump to content

eminempk

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Posts posted by eminempk

  1. like i said, look at your insert statement, the query doesnt now where to insert the submitted data.

     

    $sql = "INSERT INTO info  VALUES (null, '$title' , '$body')";

     

    should be

     

    $sql = "INSERT INTO info (title,body) VALUES ('$title' , '$body')";

     

    also need to add a " = " to this line

    <label for="title">Title:</label>

    <input type="text" name"title" id="title" />

    labrat, you do not need to specify where to put the values as long as the values match with the fields, if you have an auto-incrementing field that you are not inserting a value into, you will need to put empty quotations for that field in your insert clause...eminempk, where is the script that is calling the functions that you created?

     

    @Fugix this is the code that is calling those functions...

     

     

    <?php
    include "connect.php";
    $obj = new database_connect();
    
    //Setup our Database Variables
    $obj->host = 'localhost';
    $obj->username = 'root';
    $obj->password = '';
    $obj->db = 'school';
    
    //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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>Modern CMS</title>
    </head>
    
    <body>
    <div id="page-wrap">
    <?php
    include 'nav.php';
    ?>
    <?php
    if ($_POST['add']):
    $obj->add_content($_POST);
    endif;
    ?>
    
    
    </div>
    </body>
    </html>

  2. what are you trying to insert?  needs to be in the form of INSERT into info ( ) values('')

     

    Any data whn i try to insert it says tell me "The title Is Required" nd it didnt add the data into the database whn i retrieve the data, here is the code for add_content.php so tht u can see the whole picture.

    <?php
    include "connect.php";
    $obj = new database_connect();
    
    //Setup our Database Variables
    $obj->host = 'localhost';
    $obj->username = 'root';
    $obj->password = '';
    $obj->db = 'school';
    
    //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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>Modern CMS</title>
    </head>
    
    <body>
    <div id="page-wrap">
    <?php
    include 'nav.php';
    
    
    ?>
    <form method="post" action="index.php">
    <input type="hidden" name="add" value="true" />
    <div>
    <label for="title">Title:</label>
    <input type="text" name"title" id="title" />
    </div>
    
    <div>
    <label for = "body">Body:</label>
    <textarea name="body" id="body" rows="8" cols="40">
    </textarea>
    
    </div>
    <input type="submit" name="submit" value="Add Content" />
    </form>
    </div>
    </body>
    </html>
    

  3. i need help in tht the following code, it doesnt add the content in the database, i dnt noe wht went wrong in the code  :-[ need help , i need help in the add content function, i guess something is wrong in the loop bt cnt figure it out wht  :shrug:

    <?php
    
    class database_connect {
    
    var $host;
    var $username;
    var $password;
    var $con;
    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 ='') {
         
    	if($id != ''):
    	$id = mysql_real_escape_string($id);
    	$sql= "SELECT * FROM info WHERE id = '$id'";
    	$ret = '<p><a href="index.php">Go back to content</a></p>';
    	else:
    	$sql= "SELECT * FROM info ORDER BY id DESC";
    	endif;
    
    	$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>';
    
    	}
    	else :
    	echo '<p>doesnt exist</p>';
    	endif;
    	echo $ret;
    
    }
    function add_content($p) {
    	$title = mysql_real_escape_string($p['title']);
    	$body = mysql_real_escape_string($p['body']);
    
    	if(!$title || !$body):
    	if(!$title):
    	echo "<p>The title Is Required</p>";
    	endif;
    	if(!$body):
    	echo "<p>The body Is Required</p>";
    	endif;
    
    
    	echo '<p><a href="add-content.php">Try Again</a></p>';
    	else:	
    
    $sql = "INSERT INTO info  VALUES (null, '$title' , '$body')";
    $res = mysql_query($sql) or die(mysql_error());
    echo "Added Sucessfully";
    endif;
    
    }
    //End of class
    
    }
    ?>

  4. yeah sorry a small typo  ::)

     

    if (isset($_GET['page'])) $page = $_GET['page']

     

    i only closed off one of the )

     

    lol now i m getting an error in line 9

     

    switch($page) {

     

    ( ! ) Parse error: syntax error, unexpected T_SWITCH in C:\wamp server\www\Myweb\index.php on line 9

     

    can u post me the full code  :shrug:

  5. page is undefined as its not a variable passed in the $_GET when you call the page first off.

    wrap the whole if statement in an other if statement that has isset($_GET['page'])

     

    personally I would do it this way:

    $page;

    if (isset($_GET['page']) $page = $_GET['page'];

     

    switch ($page) {

        case "design":

            include ("includes/design.html");

    break;

        case "gallery":

            include ("includes/gallery.html");

            break;

        case "contact":

            include ("includes/contact.html");

            break;

        default:

            include ("includes/home.html");

     

    }

     

    I did wht u asked like this but now i get this error;

    ( ! ) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp server\www\Myweb\index.php on line 7

     

    and line 7 is if (isset($_GET['page']) $page = $_GET['page'];

     

     

     

    <?php

    include("includes/header.html");

    include("includes/navbar1.html");

     

    $page;

    if (isset($_GET['page']) $page = $_GET['page'];

     

    switch ($page) {

        case "design":

            include ("includes/design.html");

    break;

        case "gallery":

            include ("includes/gallery.html");

            break;

        case "contact":

            include ("includes/contact.html");

            break;

        default:

            include ("includes/home.html");

    include("includes/footer.html");

    }

     

    ?>

     

     

     

     

     

     

  6. Hey,

    i m a newbie in php,when i run the wamp server i got this error whn i click on my project. but when i click on Home, Gallery etc, then the error is gone i dont know what seems the problem is, help would be appreciated.

     

    here is the code of index.php

     

     

    <?php

     

    include("includes/header.html");

    include("includes/navbar1.html");

     

    if($_GET["page"] == "design"){

    include ("includes/design.html");

    }

    else if ($_GET["page"] == "gallery"){

    include ("includes/gallery.html");

    }

     

    else if ($_GET["page"] == "contact"){

    include ("contact2.html");

    }

    else if  ($_GET["page"] == "about"){

    include ("includes/About.html");

    }

    else

    {

     

    include("includes/home.html");

    }

    include("includes/footer.html");

     

    ?>

     

    It loads the dynamic content, but first when i load it i got these errors as mentioned in the screenshot. 

     

    [attachment deleted by admin]

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.