Scabby Posted May 7, 2007 Share Posted May 7, 2007 Hey folks, Ok so I programmed when I was young and now I would like to brush up on php but I'm having problems kick starting. I have set myself the task of a simple database query and I cannot get moving with this. <?php //Open a connection to the mysql server $link=mysql_connect("localhost","scabby","scooby"); if(!$link) { print("Failed to establish connection to mysql server!"); exit(); } //Select the database $status=mysql_select_db("scabby"); //Get town from User *************to do***************** //Temporary Measure, Town inserted here! $rq="Dudley" //Run query $query="SELECT Town,Address_time FROM customers WHERE Town=$rq"; $rs=mysql_query($query); if(!$rs) { print("Query Error: ".mysql_error()); } $numrows=mysql_num_rows($rs); print("Number of rows returned: $numrows <br /> "); $customer=mysql_fetch_assoc($rs); print($customer['Town']); print($customer['Address_time']); ?> This is where I have got to but I think where I'm getting stuck here is the relation between the variables. take the line $query="SELECT Town,Address_time FROM customers WHERE Town=$rq"; It will not accept this and I don't know why. What I'm trying to achieve is to retrieve the records whos town is contained in the query variable. I think I'm missing something in the fundamentals as I dragged myself through Basic and Opcode programming, this seems to handle variables differently. Anyone some help here, or some nifty little reading that will iron over the foundations of what you need to know to get your head around this.!! cheers Guys Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/ Share on other sites More sharing options...
papaface Posted May 7, 2007 Share Posted May 7, 2007 Do you get any errors? Try: $query= "SELECT Town,Address_time FROM customers WHERE Town='{$rq}'"; Also this: //Temporary Measure, Town inserted here! $rq="Dudley" //Run query Should be: //Temporary Measure, Town inserted here! $rq = "Dudley"; //Run query Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-247599 Share on other sites More sharing options...
Scabby Posted May 8, 2007 Author Share Posted May 8, 2007 Thanks for the reply papface. So what is returned exactly from the line $query= "SELECT Town,Address_time FROM customers WHERE Town='{$rq}'"; what does $query contain Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-247712 Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 Thanks for the reply papface. So what is returned exactly from the line $query= "SELECT Town,Address_time FROM customers WHERE Town='{$rq}'"; what does $query contain $query is a variable that contains the entire line of code ""SELECT Town,Address_time FROM customers WHERE Town='{$rq}'";" That is a basic must know for PHP, check out some books or online tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-247754 Share on other sites More sharing options...
mmarif4u Posted May 8, 2007 Share Posted May 8, 2007 In your code th problem was with these: WHERE Town='{$rq}'"; U forgot to use quotes in where clause for ur variable. Other u forgot to terminate the line with ; $rq="dudely" must be $rq="dudely"; Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-247782 Share on other sites More sharing options...
Scabby Posted May 10, 2007 Author Share Posted May 10, 2007 Yes a stupid request $query= states itself doesn't it. I move slowly but I always get there. Thanks for the replies, they are very much appreciated. I got my head around Joomla a while back and when I started to teach myself that I was held up for quite a while on simple things. Things that you could get answered in a few mins over a coffee with someone. Thats why I say thanks for what may seem to some a stupid question. Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-250175 Share on other sites More sharing options...
Scabby Posted May 10, 2007 Author Share Posted May 10, 2007 [PS] I have looked extensively for beginners tutorials that do not assume some degree of knowledge, When I start reading I know I'm missing something ??? Quote Link to comment https://forums.phpfreaks.com/topic/50410-total-noob-needs-some-directions-i-think/#findComment-250183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.