0

i'm new learn php and mysql and i got stuck can't get better logic for my brain i want to get message from page if i type url like index.php?user=user1 and page will show with data table and if username doesn't exist and page show no username found so this example when i type index.php?user=22222 and page show message no username found here my query

<?php
.....
if(isset($_GET['user'])) {
        $result = mysql_query("select * from content where username = '" . $_GET['user'] . "' limit 3;");

        $get_jml = mysql_query("select count(*) as jml from content");
        $jml = 0;
        while($h_jml = mysql_fetch_array($get_jml)){
        $jml_artcles = $h_jml['total'];         
            }   
        }else {}
        $jml_page = ceil($jml_articles); 
?>

        <?php while($data = mysql_fetch_array($result)){ ?>
/*some code here */

        <?php } ?>  

what can i add or change my query above sorry my english bad
thanks

Edited by zein1212: wrong type

3
Contributors
6
Replies
30
Views
3 Years
Discussion Span
Last Post by zein1212
0

Don't use mysql_* functions - they are deprecated - use mysqli or PDO instead,

Don't place input vaiables directly into SQL as you may be open to SQL injection - use prepared statements and bind parameters.

What is this trying to do? The two queries don't seem to make much sense.

0

i was wrong for this .. I've resolve this problem
how can i delete this post ?

0

@diafol I have not learned about PDO or MSYQLI ..if you can help .. can you type example from my query above from mysql to PDO ?
Thanks

0

Posts are never deleted. You can always click solved.

Can you at least tell us what was wrong and what you did to fix it?

0

@diafol I have not learned about PDO or MSYQLI ..if you can help .. can you type example from my query above from mysql to PDO ?
Thanks

No sorry. You can learn PDO or mysqli from the php.net manual or from hundreds of online tutorials - or check out pritaeas' php snippets on Daniweb - you just need to search. You can then test your own examples. :)

0

@blackmiau my problem is if url type index.php?user=user1 is on table so the data will show else if index.php?user=user2 doesn't exist on table the page will show message about what i want example "the url doesn't exist" i fix it base on query above with add this

<?php
.....
if(isset($_GET['user'])) {
$result = mysql_query("select * from content where username = '" . $_GET['user'] . "' limit 3;");
if(mysql_num_rows($result) != 1){
        echo"<h2 style='color:#EA6213;text-align:center;'>Username is invalid or you don't have any post here..</h2>";
        echo "<br/>";
        }

@diafol : Ok thanks for your suggest

Edited by zein1212: wrong text

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.