Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,673 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,184 people online right now. Registration is fast and FREE... Join Now!




php and MYSQL connectivity

 
Reply to this topicStart new topic

php and MYSQL connectivity

Rating  5
him
post 13 Jul, 2007 - 10:40 PM
Post #1


New D.I.C Head

*
Joined: 13 Jul, 2007
Posts: 6


My Contributions


hi
CODE
  < html >
< body >
< ?php
mysql_connect("localhost", "himvik", "shubhendu");
roll no: <input type="text" name="$x" />

<input type="submit"/>
$result = @mysql_query("SELECT roll_no from student");
while ($row = mysql_fetch_assoc($result)){
$contents = $row['contents'];
}
? >

now i want to give query like roll no as an example and want to fetch whole information of the concerned roll no from th database which i have already created in MYSQL.
But i m not able to do so could u please give the code or some related steps for the same.
smile.gif
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 14 Jul, 2007 - 06:47 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


Can you elaborate a little further - perhaps post an example of what you are trying to get back from the query? Are you getting any errors?
User is offlineProfile CardPM

Go to the top of the page

Styx
post 14 Jul, 2007 - 07:07 AM
Post #3


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


First, you are including your db connection info, which is bad. But you don't include the database you're connecting to.

You need to read more about how to do forms. You don't even have any form tags, unless you left them out on purpose?

You also have php and html mixed right in with each other, which will only give you errors.

Then, you don't say what $x is, not sure if it really matters.

It all should look something like this:
CODE
<?php
$roll = $_POST['roll'];

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database');
$result = mysql_query("SELECT * FROM student WHERE roll_no = $roll");
$row = mysql_fetch_assoc($result);
$contents = $row['contents'];
?>
<form method="post">
Roll No: <input type="text" name="roll" value="<?php echo $roll; ?>">
<input type="submit" name="submit" value="Submit">
</form>


This post has been edited by Styx: 14 Jul, 2007 - 07:10 AM
User is offlineProfile CardPM

Go to the top of the page

him
post 15 Jul, 2007 - 10:36 PM
Post #4


New D.I.C Head

*
Joined: 13 Jul, 2007
Posts: 6


My Contributions


but still its not workin...
neither cn i understand tha error...???



































...
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 16 Jul, 2007 - 05:44 AM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


What is the error? Post the exact error message.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:20AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month