Passing variable via URL and echo data based on it

Hello…Glad there is a beginners forum, because I definitely fit in that category! I have a button on a page with this link on it:

I want to use mfgID to output the data below on my searchbymfg.php page below:

<? $mfg=$_POST['mfgID']; //connect to db/// $dbservertype='mysql'; $servername='host'; // username and password to log onto db server $dbusername='user'; $dbpassword='pass'; // name of database $dbname='db'; //////////////////////////////////////// ////// DONOT EDIT BELOW ///////// /////////////////////////////////////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } //////// End of connecting to database //////// $query = "SELECT * FROM products2 WHERE products2MfgID=$mfg"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo ""; echo ""; echo "
"; echo $row['products2Nane']; echo "
"; } ?>

I keep getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 1

and I wonder where I’ve gone wrong?

Thanks for taking time to help me!


url based variables data can be accessed with $_GET not with $_POST

so, instead of $mfg=$_POST[‘mfgID’]

use $mfg = $_GET[‘mfgID’]

Thank you VERY MUCH! That fixed it!

you are welcome!


You can use $_REQUEST instead of $_GET or $_POST. coz, $_REQUEST works fine with both get and post

Sponsor our Newsletter | Privacy Policy | Terms of Service