Jump to content

Confusing problem


Yuki

Recommended Posts

To see the site I'll be referring to,To see the site I'll be referring to, please goto http://shahinrostami.com/webdevass2/login.php

 

SOURCE:

http://shahinrostami.com/webdevass2/admin.phps

http://shahinrostami.com/webdevass2/question.phps

 

 

Username: admin

Passsword: istrator

 

 

Basically, navigate to a Question within a module, you'll see a form at the bottom for adding questions.

 

when you click that, I need to be able to echo out either the MySQL error or "New Question Added"

 

so I have:

 

mysql_query($query) or die('Error, insert query failed');

 

echo = "New question added";

 

 

 

 

admin.php contains the div I want to be using to print out notifications like that, it's the

 

<?php

    echo "<div class=\"notification\">";

    echo $notification;

    echo "</div>";

    ?>

 

problem is it's above the case switches that include the body.

 

I don't understand how to get round this purely using PHP, help please!

 

 

Link to comment
Share on other sites

Most my code is procedural, the only thing that I've made my own function for is when I have to re-use the EXACT same code twice.

 

 

The part that needs to print out the message is the parent, I consider the include the child (conceptually in this scenario)

 

 

 

$notification;

echo $notification;

 

 

// question.php has a form in it that inserts questions into the db

include "question.php";

 

 

 

 

now, I want $notification to print out the mysql error message. Problem is, it's echo'd before the include, if it was after, all would be fine, I could do it like the previous poster stated, cast it into a variable, and print it out.

 

Link to comment
Share on other sites

It's going to have to be AJAX/Javascript. Was trying to avoid learning any of that until this project is over, I understand the concepts though, anyone have any links to tutorials/manuals with simple explenations of something as simple as I'm trying to do?

 

ONE div on the page that needs to have something echo'd out to it AFTER it's displayed

Link to comment
Share on other sites

If you have the id of the div you could use this in your php script.

 

Javascript Example:

 

<?php
// the code you want to echo
$echo = "this is the html code";
// script to display it
echo "<script type='text/javascript'>document.getElementById('id_of_div').innerHTML = '".$echo."';</script>";
?>

Link to comment
Share on other sites

Makes sense but I can't seem to get my head round it. The Stylesheet is included, .css file

 

.notification{

background-color: #DB4105;

color: #FFF8E3;

width: 60%;

display: none;

}

 

 

 

I've added display: none;

 

what would I pass through using javascript

Link to comment
Share on other sites

Don't add display none to the css stylesheet, hard-code it into the div.  Here's how it should work.

 

<!-- FOR THE DIV -->
<div id="div_id" style="display: none;"></div>
<?php
// the code you want to echo
$echo = "this is the html code";
// script to display it
echo "<script type='text/javascript'>
var divid = document.getElementById('div_id');
divid.style.display = 'block';
divid.innerHTML = '".$echo."';
</script>";
?>

 

I believe that should work.  I didn't test it.

Link to comment
Share on other sites

Hmm try this instead:

 

<!-- FOR THE DIV -->
<div id="div_id" style="display: hidden;"></div>
<?php
// the code you want to echo
$echo = "this is the html code";
// script to display it
echo "<script type='text/javascript'>
var divid = document.getElementById('div_id');
divid.style.visibility = 'visible';
divid.innerHTML = '".$echo."';
</script>";
?>

 

See if that works.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.