scotthammersley Posted November 14, 2006 Share Posted November 14, 2006 Im relatively new to php and mysql, i have read several books on php but i cant seem to get a straight answer.When passing form information to a php script i can get it to work with a simple script but not when i try to do more. I have a couple of questions.1) do i use $_GET[''] or @$_GET[''] or even $HTTP_GET_VARS[''] to assign variable info.2) Have the following code to execute an Sql query, the query needs to use variables. I get either a T_ECHO error or Unexpected '>'. Now this may be because of the first question, i dont know.?php//sortinclude 'pattern_search.php';$m = $_GET['order'];$h = $_GET['how'];$pattern = $_GET['pattern'];$piece = $_GET['piece']; $host = ;$user = ;$pass = ;$database =; mysql_connect($host, $user, $pass); @mysql_select_db($database) or die( "Unable to select database");//select from ds_carts $query = ("SELECT * FROM ds_carts WHERE pNum LIKE $pattern OR pName LIKE $piece ORDER BY $m OR $h"); $result = mysql_db_query(gpittman1, $query); if ($result) { echo "<font><align=center><b>Current Collectors - Sorted By $m in $h order.</b><br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>Product Name</td> <td align=center bgcolor=#00FFFF>Sku</td> <td align=center bgcolor=#00FFFF>Qty</td> <td align=center bgcolor=#00FFFF>Price</td> <td align=center bgcolor=#00FFFF>Total</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $name = $r["pName"]; $sku = $r["pNum"]; $qty = $r["pQty"]; $price = $r["pPrice"]; $total = $r[$price * $qty]; echo "<tr> <td>$name</td> <td>$sku</td> <td>$qty</td> <td>$price</td> <td>$total</td> </tr>"; } // end while echo "</table>"; } else { echo "problems...."; } ?> This may seem trivial but im stumped.Thanks Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/ Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 can you post your code in code tags? Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124612 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 What exactly do you mean? Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124616 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 [ code] [/ code]without spaces[code]<?php//sortinclude 'pattern_search.php';$m = $_GET['order'];$h = $_GET['how'];$pattern = $_GET['pattern'];$piece = $_GET['piece']; $host = ;$user = ;$pass = ;$database =; mysql_connect($host, $user, $pass); @mysql_select_db($database) or die( "Unable to select database");//select from ds_carts $query = ("SELECT * FROM ds_carts WHERE pNum LIKE $pattern OR pName LIKE $piece ORDER BY $m OR $h"); $result = mysql_db_query(gpittman1, $query); if ($result) { echo "<font><align=center>Current Collectors - Sorted By $m in $h order."; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>Product Name</td> <td align=center bgcolor=#00FFFF>Sku</td> <td align=center bgcolor=#00FFFF>Qty</td> <td align=center bgcolor=#00FFFF>Price</td> <td align=center bgcolor=#00FFFF>Total</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $name = $r["pName"]; $sku = $r["pNum"]; $qty = $r["pQty"]; $price = $r["pPrice"]; $total = $r[$price * $qty]; echo "<tr> <td>$name</td> <td>$sku</td> <td>$qty</td> <td>$price</td> <td>$total</td> </tr>"; } // end while echo "</table>"; } else { echo "problems...."; } ?> [/code] Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124617 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 <?php//sortinclude 'pattern_search.php';$submit = $_GET['submit'];$m = $_GET['order'];$h = $_GET['how'];$pattern = $_GET['pattern'];$piece = $_GET['piece'];$host = ;$user = ;$pass = ;$database = 'gpittman1';mysql_connect($host, $user, $pass); @mysql_select_db($database) or die( "Unable to select database");//select from ds_customers $query = ("SELECT * FROM ds_carts WHERE pNum LIKE $pattern OR pName LIKE $piece ORDER BY $m OR $h"); $result = mysql_db_query(gpittman1, $query); if ($result) { echo "<font><align=center><b>Current Collectors - Sorted By $m in $h order.</b><br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>Product Name</td> <td align=center bgcolor=#00FFFF>Sku</td> <td align=center bgcolor=#00FFFF>Qty</td> <td align=center bgcolor=#00FFFF>Price</td> <td align=center bgcolor=#00FFFF>Total</td> </tr>"while ($r = mysql_fetch_array($result)) { // Begin while $name = $r["pName"]; $sku = $r["pNum"]; $qty = $r["pQty"]; $price = $r["pPrice"]; $total = $r[$price * $qty]; echo "<tr> <td>$name</td> <td>$sku</td> <td>$qty</td> <td>$price</td> <td>$total</td> </tr>"; } // end while echo "</table>"; } else { echo "problems...."; } ?> Is this what you mean, you have to excuse me, this is first time trying to get help using forums. Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124621 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 try:[code]<?php//sortinclude("pattern_search.php");$m = $_GET[order];$h = $_GET[how];$pattern = $_GET[pattern];$piece = $_GET[piece]; $host = "";$user = "";$pass = "";$database = "";$connect = mysql_connect($host,$user,$pass);$db = mysql_select_db($database,$connect) or die(mysql_error());//select from ds_carts $query = "SELECT * FROM ds_carts WHERE pNum LIKE $pattern OR pName LIKE $piece ORDER BY $m"; $result = mysql_query($query); if ($result) { echo "<font><align=center>Current Collectors - Sorted By $m in $h order."; echo " <table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>Product Name</td> <td align=center bgcolor=#00FFFF>Sku</td> <td align=center bgcolor=#00FFFF>Qty</td> <td align=center bgcolor=#00FFFF>Price</td> <td align=center bgcolor=#00FFFF>Total</td> </tr>"; while ($r = mysql_fetch_assoc($result)) { // Begin while $name = $r["pName"]; $sku = $r["pNum"]; $qty = $r["pQty"]; $price = $r["pPrice"]; $total = $r[$price * $qty]; echo "<tr> <td>$name</td> <td>$sku</td> <td>$qty</td> <td>$price</td> <td>$total</td> </tr>"; } // end while mysql_free_result($result); echo "</table>"; } else { die("ERROR"); };?>[/code] Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124626 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 still getting the error? I have no idea. Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124631 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 could you post the full error? Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124634 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 Its just the 'else' error, not an sql or php error. Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124646 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 why cant you post it then? Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124648 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 // end while mysql_free_result($result); echo "</table>"; } else { die("ERROR"); };The die ERROR, i dont know what to tell you after that. Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124651 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 just change die("ERROR");to likeecho "error";i meant for you to post the error you're recieving Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124655 Share on other sites More sharing options...
scotthammersley Posted November 14, 2006 Author Share Posted November 14, 2006 thats what i was saying earlier, i dont get an error from the script except on the 'if' statement, i dont think the form is passing the info over, or its that the script isnt processing the info because if i try to echo even the username, it doesnt display, it just displays $user. Like this.$connect = mysql_connect($host,$user,$pass);$db = mysql_select_db($database,$connect) or die(mysql_error());//select from ds_carts $query = "SELECT * FROM ds_carts WHERE pNum LIKE $pattern OR pName LIKE $piece ORDER BY $m"; $result = mysql_query($query);echo '$user'; Link to comment https://forums.phpfreaks.com/topic/27248-understanding-variables-used-with-mysql-query-statements/#findComment-124656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.