Forum Moderators: coopster

Message Too Old, No Replies

How to display mysql rows using Selected value as a condition

         

pokka

6:54 am on Jun 20, 2012 (gmt 0)

10+ Year Member



Hi guys ,i'm trying to retrieve my table details using the <select> value such that the rows that have the value"NTUC" would display all its other column value out . but i'm having some problem with it !

This is my php page -viewfeedback.php

<head>
<h1>View feedback results</h1>
</head>
<body>
<form method="post" action="insert_Test.php">
<label for="select"><select name="store" value="Select" size="1">
<?php

include_once('config2.php');
//construct SQL
$sql="SELECT * FROM provision";
//send to mysql using mysqli object
$result=$mysqli->query($sql);
//iterate

while(list ($provisionid,$provisionstore)=$result->fetch_row())
echo "<option data-provisionid='".$provisionid."'>".$provisionstore."</option>";
$result->free();
$mysqli->close();
?>
</SELECT>

<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

This is the code of insert_test.php
<?

$host="127.0.0.1";
$user="root";
$password="password";
$database="feedback_survey_db";
$db_Table="feedback";

mysql_connect("$host","$user","$password") or die ("cannot connect");
mysql_select_db("$database") or die("cannot select DB");

$store=$_POST['store'];

$sql="SELECT idfeedback,name,email,feedback FROM feedback WHERE provisionstore = '$store'";
$result=$mysqli->query($sql);
while(list ($idfeedback,$name,$email,$feedback)=$result->fetch_row())
{
echo"<p>".$idfeedback."."."Name:".$name."<br/>"."Email address:".$email."<br/></p>"."Feedback:".$feedback."<br/></p>";;
}
$result->free();
$mysql->close();

?>

This is the error i received
[20-Jun-2012 14:54:19] PHP Notice: Undefined variable: mysqli in C:\www\Project\09\insert_Test.php on line 15
[20-Jun-2012 14:54:19] PHP Fatal error: Call to a member function query() on a non-object in C:\www\Project\09\insert_Test.php on line 15

Some help please guy :( sorry for being a newbie in this !

rocknbil

4:52 pm on Jun 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard pokka, this

$result=$mysqli->query($sql);

indicates there is a class method somewhere, have you included the file containing the class? The raw equivalent (with a proper error trap!) would be

$result=mysqli_query($sql) or die(cannot execute query: " . mysqli_error());