hi guys, i have done the records selection from mysql db but now i want to view the details for each record. this is my php code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <?php $userid = $_GET["userid"]; ?> </head> <body> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM dealers WHERE userid='$userid;'"); while($row = mysql_fetch_array($result)) { ?> <?php echo $row['company']; ?><br /><?php echo $row['vat']; ?> <?php } ?> </body> </html> PHP: when i type manualy a "userid" in this section: the record details are appearing correct. what i can do to play dynamically? thanks in advance.
You need a form with an input field for the userid. Then in your PHP script you use $_POST['userid'] or $_GET['userid'] (depends on the form method) to retrieve the value inserted by the user.
your sql statement is wrong so i am making it right.. just paste it place of $result. $result = mysql_query("SELECT * FROM dealers WHERE userid=' ".$userid." ' "); Sure this will work.. Thanks Sam
what happens if you do not specify userid ( I mean userid="") , also do not use root as userid to connect to mysql server.
As said, you need a form: <?php if( $_POST ) { $con = mysql_connect( "localhost", "root", "" ); if ( !$con ) { die( "Could not connect: ". mysql_error( ) ); } mysql_select_db( "storedb", $con ); $userid= $_POST["userid"]; $fetch = mysql_query( "SELECT * FROM dealers WHERE userid='".$userid."'" ); while( $array = mysql_fetch_array( $fetch ) ) { echo "".$row["company"]."<br />".$row["vat"].""; } } ?> <form method="post" action=""> User ID: <input type="text" name="userid" /> <input type="submit" value="Submit" /> </form> PHP:
the form was created before this page my friend. how i can change the username and password of mysql database? can you tell me?