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

Recommended Answers

All 6 Replies

Member Avatar for diafol

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.

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

@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

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?

Member Avatar for diafol

@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. :)

@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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.