FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » problem with many buttons
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
problem with many buttons [message #182805] Mon, 16 September 2013 02:25 Go to next message
Avnesh Shakya is currently offline  Avnesh Shakya
Messages: 2
Registered: September 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
hi,
I have a problem, I have created lot of blogs in my site, and i put those as button, so when i click on button(e.i. blog name), then it should be redirect on other page like. Now I am on page like localhost/blog/blogName.php, here I have all blog buttons, after clicking on a particular button, it should go on localhost/blog/commentShow.php?id=blogName, here blogName is a name of blog that button contains.

I am doing in page localhost/blog/blogName.php
<?php
$blogIds = 0;
$sql = "SELECT * FROM user_blogs";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result))
{
echo "<ul class='ulBullet horLine'>";
echo "<li>".$row['description']."</li>";
$bgname = 'bgname'.$blogIds;
echo "<li><button id=$bgname onclick = return(blogId($this))>".$row['blogs_name']."</button></li>";
$next = "SELECT * FROM users WHERE user_id=$row[user_id]";
$result12 = mysqli_query($con, $next);
$row12 = mysqli_fetch_array($result12);
echo "<li style=''><button class=''>".$row12['usename']."</button></li>";
echo '</ul>';
$blogIds++;
}
?>
in last, i added
<?php
echo "<script type='text/javascript'>function blogId($bgid) { top..location.href = './blogComment.php?id=$bgid'; };</script>";
?>

it is going on that page but not contaid this value...

please help me, what's wrong with me...

thanks and regards,
Avnesh Shakya
Re: problem with many buttons [message #182808 is a reply to message #182805] Mon, 16 September 2013 06:57 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Avnesh Shakya wrote:

> I have a problem, I have created lot of blogs in my site, and i put
> those as button, so when i click on button(e.i. blog name), then it
> should be redirect on other page like. Now I am on page like
> localhost/blog/blogName.php, here I have all blog buttons, after
> clicking on a particular button, it should go on
> localhost/blog/commentShow.php?id=blogName, here blogName is a name of
> blog that button contains.
>
> I am doing in page localhost/blog/blogName.php
> <?php
> $blogIds = 0;
> $sql = "SELECT * FROM user_blogs";
> $result = mysqli_query($con, $sql);
> while($row = mysqli_fetch_array($result))
> {
> echo "<ul class='ulBullet horLine'>";
> echo "<li>".$row['description']."</li>";
> $bgname = 'bgname'.$blogIds;
> echo "<li><button id=$bgname onclick =
> return(blogId($this))>".
$row['blogs_name']."</button></li>";
> $next = "SELECT * FROM users WHERE
> user_id=$row[user_id]"; $result12 =
> mysqli_query($con, $next); $row12 =
> mysqli_fetch_array($result12); echo "<li
> style=''><button
> class=''>".$row12['usename']."</button></li>";
> echo '</ul>'; $blogIds++;
> }
> ?>
> in last, i added
> <?php
> echo "<script type='text/javascript'>function blogId($bgid) {
> top.location.href = './blogComment.php?id=$bgid'; };</script>"; ?>
>
> it is going on that page but not contaid this value...
>
> please help me, what's wrong with me...

You are not thinking clearly, and you have not done your homework.

Steps you have before you, probably best in that order:

- Learn how to ask questions the smart way:

<http://www.catb.org/~esr/faqs/smart-questions.html>

- Do not use Google Groups for posting to Usenet, it is broken
and filled with spam. Use instead, for example, one of the following:

<https://en.wikipedia.org/wiki/SeaMonkey>
<https://en.wikipedia.org/wiki/Mozilla_Thunderbird>
<https://en.wikipedia.org/wiki/Kontact#Usenet_News_Client>

- Learn HTML [1] and learn how to write *Valid* HTML:

<http://validator.w3.org/>
<news:comp.infosystems.www.authoring.html>

- Learn *at least* the *basics* of PHP:

<http://php.net/manual/>

- Get used to a consistent, easily readable and maintainable code style
for each markup/programming language that you are using. For example,
with regard to PHP, you can use

<http://pear.php.net/manual/en/standards.php> pp.

as basis for your code style.

- Get a decent integrated development environment that makes all
of this a lot easier:

<http://projects.eclipse.org/projects/tools.pdt>

- Learn the difference between server-side and client-side code,
and between static and generated content. [1]

- Only use “echo” for *generated* content:

<http://php.net/manual/en/tutorial.firstpage.php>

- Learn to structure your code. Use functions in order to DRY;
templates to separate business logic, like database queries,
from output:

<https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>
<http://php.net/manual/en/language.functions.php>
<http://php.net/include>
<http://php.net/require>
<http://php.net/require_once>
<http://www.smarty.net/>

- Escape input to prevent invalid input and (SQL) code injection:

<https://en.wikipedia.org/wiki/Code_injection>
<http://php.net/mysqli_real_escape_string>
<http://php.net/manual/en/mysqli.quickstart.prepared-statements.php>
<http://php.net/manual/en/pdo.prepare.php>

- Escape output to prevent invalid output and cross-site scripting (XSS):

<http://php.net/addslashes>
<http://php.net/htmlspecialchars>
<http://php.net/rawurlencode>
<http://php.net/manual/en/security.php>
<https://en.wikipedia.org/wiki/XSS>

- Learn object-oriented programming:

<http://en.wikipedia.org/wiki/Object-oriented_programming>

With regard to PHP:

<http://php.net/manual/en/language.oop5.php>

- Learn J(ava)Script/ECMAScript and how to use the DOM APIs. [1]
See also <news:comp.lang.javascript>

- Learn (My)SQL and how to process (My)SQL query results with PHP
(in an efficient way):

<https://en.wikipedia.org/wiki/SQL>
<http://dev.mysql.com/manual/>
<news:comp.databases.mysql>
<http://php.net/manual/en/mysqli.quickstart.php>
<http://php.net/manual/en/pdostatement.fetchall.php>

[1] <https://developer.mozilla.org/> pp.

YMMV. HTH.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
Re: problem with many buttons [message #182810 is a reply to message #182805] Mon, 16 September 2013 07:32 Go to previous messageGo to next message
Fiver is currently offline  Fiver
Messages: 35
Registered: July 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On 2013-09-16 08:25, Avnesh Shakya wrote:
> <?php
> echo "<script type='text/javascript'>function blogId($bgid) {
> top.location.href = './blogComment.php?id=$bgid'; };</script>";
> ?>
>
> it is going on that page but not contaid this value...

echo "... $bgid ..." will try to interpolate the PHP variable "$bgid"
into the string. Depending on your settings and whether $bgid actually
exists, this will result in an error or something you didn't want.
JavaScript variables and function arguments are not usually prefixed
with a "$" sign. Try this instead (without the <?php ... ?> around it):

<script type="text/javascript">
function blogId(bgid) {
top.location.href = './blogComment.php?id=' + bgid;
}
</script>


regards,
5er
Re: problem with many buttons [message #182812 is a reply to message #182810] Mon, 16 September 2013 09:41 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Fiver wrote:

> On 2013-09-16 08:25, Avnesh Shakya wrote:
>> <?php
>> echo "<script type='text/javascript'>function blogId($bgid) {
>> top.location.href = './blogComment.php?id=$bgid'; };</script>";
>> ?>
>>
>> it is going on that page but not contaid this value...
>
> echo "... $bgid ..." will try to interpolate the PHP variable "$bgid"
> into the string. Depending on your settings and whether $bgid actually
> exists, this will result in an error or something you didn't want.
> JavaScript variables and function arguments are not usually prefixed
> with a "$" sign. Try this instead (without the <?php ... ?> around it):
>
> <script type="text/javascript">
> function blogId(bgid) {
> top.location.href = './blogComment.php?id=' + bgid;
> }
> </script>

I am afraid that this code is not going to work until someone with a minimum
clue will be rewriting it. For example,

| echo "<li><button id=$bgname onclick = return(blogId($this))>".
| $row['blogs_name']."</button></li>";

is not going to work already because “$this” will be expanded to "" while
generating the notice “Undefined variable: this”. It must be “this”
instead, and the “onclick“ attribute value must be quoted; but to know that
you have to have at least a basic understanding of HTML, and you have to
know the difference between server-side and client-side code, and between
PHP (used here server-side) and ECMAScript/JavaScript (used here client-
side).


PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Confirm PG-related segfault in current PHP version
Next Topic: syntax error or notepad++ error?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Oct 17 02:08:15 EDT 2017

Total time taken to generate the page: 0.00667 seconds