Jump to content

Display data from database !Confused!HELP Please


ckerr27

Recommended Posts

Hi I am trying to display data from the table "event" in my database, I use the code below but it will not work and I cannot figure out why. CAn anyone help?

 

CODE:

 

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="test"; // Database name

$tbl_name="event"; // Table name

 

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

 

$result = my_sql_query("SELECT * FROM event WHERE eventid = '1'");

 

while($row = mysql_fetch_array($result))

  {

  $eventname= $row["eventname"];

  $eventdate= $row["eventdate"];

 

  echo "<b><u>Event Name:</b></u>  $eventname"

echo "<b><u>Event Date:</b></u> $eventdate<br>";

  }

?>

 

 

 

DISPLAY:

 

Event Name: $eventname echo "Event Date: $eventdate

"; } ?>

Link to comment
Share on other sites

The only error I see in the code as posted, is a missing semi-colon on the first echo.

 

However, the example display you showed indicates that you used a single-quote to open the first echo, and did not close that string.

 

(by the way, please use [ code] tags or [ php] tags when posting code).

 

The example display looks like your code actually is:

   echo '<b><u>Event Name:</b></u>  $eventname
   echo "<b><u>Event Date:</b></u> $eventdate<br>";
  }
?>'

 

Note that PHP will not interpret variables inside of single-quoted strings. That block should be:

   echo "<b><u>Event Name:</b></u>  $eventname";
   echo "<b><u>Event Date:</b></u> $eventdate<br>";
  }
?>

Link to comment
Share on other sites

Well, we'd like to help more, but I don't know what you are saying.

 

the code looks correct to me

Did you change the code as I suggested?

Or was it already that way?

Is that your actual code, because the code you showed should produce a syntax error, not the output you showed.

 

Can you cut and paste your code, exactly as is, using the code tags (it's the button with the hash-mark -- octothorpe? -- just above the smileys with the blinking eyes)?

 

Can you also cut and paste the HTML (from "View Source") of the browser (again, using code tags) so we can see what is happening?

Link to comment
Share on other sites

I hop i have used the correct code tags! This is the complete file:

 

#<html>

#<head>

#<link rel="stylesheet" type ="text/css" href="anything2.css"

#</head>

 

#<body>

 

 

#<div id="container">

 

#<div id="header"><img src="imagesb.jpg" alt="Cool Image" align="left">

#<img src="images.jpg" alt="Cool Image" align="right"><center><b><font size="6.5"><br><br>Future Events</b></center></font>

 

#</div>

 

 

#<div id="leftnav"><center>

#<br><br>

#<input type= "button" style="width:120px;" value="Home" onClick="window.location= 'adminhome.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="Personal Details" onClick="window.location= 'adpersonaldetails.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="Club Details" onClick="window.location= 'adclubdetails.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="News" onClick="window.location= 'adnews.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="FAQ" onClick="window.location= 'adfaq.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="Wall" onClick="window.location= 'adwall.php' ">

#<br><br>

#<input type= "button" style="width:120px;" value="About Us" onClick="window.location= 'adabout.php' ">

#</div>

 

#<div id="body">

#<?php

#$host="localhost"; // Host name

#$username="root"; // Mysql username

#$password=""; // Mysql password

#$db_name="test"; // Database name

#$tbl_name="event"; // Table name

 

#mysql_connect("$host", "$username", "$password")or die("cannot connect");

#mysql_select_db("$db_name")or die("cannot select DB");

 

 

#$result = my_sql_query("SELECT * FROM event WHERE eventid = '1'");

 

#while($row = mysql_fetch_array($result))

  {

# $eventname= $row["eventname"];

#  $eventdate= $row["eventdate"];

#  echo "<b><u>Event Name:</b></u>  $eventname";

#  echo "<b><u>Event Date:</b></u> $eventdate<br>";

#  }

#?>

#<div id="footer">This is the footer</div>

 

#</body>

#</html>

Link to comment
Share on other sites

"Code tags" in a post are like HTML markup, but with square-brackets. So for bold instead of <B></B> (as you would do in HTML), you type [ b]something[ /b] (I had to put a space after the open brackets there so it would display, take the space out) which comes out like something. For code, you use code tags: [ code]code here[ /code] (again, remove the spaces). I mentioned the "#" because, above the edit box are some buttons for formatting posts; the "#" is the picture on the button that puts code tags into the edit area. Also, there is a Preview button below the edit area (next to the Post button) that will let you see your post before you send it, so you can see if the markup is correct.

 

Anyway, on to the problem

 

I see some HTML markup problems in that code. I'm not sure if these could be causing you problem or not. But you should fix these problems and then see what happens:

 

<head>
<link rel="stylesheet" type ="text/css" href="anything2.css"
</head>

That LINK tag is not closed, so the closing HEAD tag is ignored and it's closing bracket closes the LINK.

 

<div id="container">
...
<div id="body">

There are no closing tags for these two DIVs

 

Other than the fact that the HEAD tag is left open, I don't think these could be causing the problem.

 

Did you look at the HTML source in your browser? That may give us a hint as to what is happening.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.