Importing MySQL Rows into a table - php

So I was importing some MySQL Rows into a form but there seems to be an issue, the database doesnot connects, it says no database selected, I have my Database connection parameters in constants.php and they are working fine in the other pages of the website, and there is no syntax error in the commands either, Help me please.Thanks!
<?php
require_once 'classes/Membership.php';
require_once 'includes/constants.php';
$membership = New Membership();
$membership->confirm_Member();
$con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('Error connecting Database');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Post Scores | Admin Panel D2C</title>
<style type="text/css">
</style>
</head>
<body>
<div class="main_body">
<table width="1029" border="0" cellpadding="0" class="score_table" >
<td width="131">
<form align="center" action="update_team_database.php" method="post">
<tr>
<td> Team: </td>
<td width="831">
<?php
$result = mysql_query("select DISTINCT TeamName from team") or die(mysql_error());
echo '<select name="teamname1"><OPTION>';
echo "Select a team</OPTION>";
while ($row = mysql_fetch_array($result)){
$team1 = $row["TeamName"];
echo "<OPTION value=\"$team1\">$team1</OPTION>";
}
echo '</SELECT>';
?></td>
</tr>
</form>
</table>
</body>
</html>

I would recommend you make use of Object Oriented way of performing queries over MySQL using MySQLi
You may check the example in here
http://in2.php.net/manual/en/mysqli.query.php
Since MySQL is deprecated as of PHP 5.5

Related

Link URL to image or Title rather than echo link , retriving image,title and link from database in php

I am getting image, title and external URL from database, and display it on my page, code is working well, But i don't want to display URL, I want when I click image or title it should go direct to that URL in new window. My Code is
<?php
include_once("init.php");
$msg='';
$adDir ='./'.EDITORIALNEWS;
$qr = mysql_query("select * from " .enews) or die('Error in connection');
while($rs = mysql_fetch_array($qr))
{
$adv = '';
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}
$image = $adv;
$msg .='<tr>
<td>'.$image.'</td>
<td>'.$rs['title'].'</td>
<td>'.$rs['adv_url'].'</td>
</tr>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editorialt News Lists</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
</head>
<body>
<div class="tabl">
<table width="95%" border="1" align="center" cellpadding="10">
<tr>
<td width="35%"><strong>File</strong></td>
<td width="30%"><strong>Title</strong></td>
<td width="30%"><strong>Link</strong></td>
</tr>
<?php echo $msg;?>
</table>
</body>
</html>
Image, Title, URL are adv, title and adv_url respectively.
I think the line added should be like
<img src="<?=VIDEO.$adv['adv']?>" width="98%" height="90" alt="">
but how and where to use it don't know. Being a student I have keen interest in learning PHP through projects.
You can do it like as follows:
Replace the following line of your code with my code:
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}
//My code
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}

MySQL and PHP table not printing right

This is for a class project in my databases class. I am making an event database and on the index page I want to make a table that joins the 3 tables in my db. right now all the data is on one table but I want to join all the tables. tables(Sports, Concert, and Restaurant)
<?php
include 'database_connector.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$result=mysqli_query($con, "select *from Sports LIMIT 0, 30");
echo "<table>";
echo "<tr>
<th>Event Type</th>
<th>Team 1</th>
<th>Team 2</th>
<th>Place</th>
<th>Price</th></tr>";
while($row=mysqli_fetch_array($result)){
$event = $row['event'];
$team1 = $row['Team 1'];
$team2 = $row['Team 2'];
$place = $row['Place'];
$price = $row['Price'];
echo "<tr><td>".$event."</td>
<td>".$team1."</td>
<td>".$team2."</td>
<td>".$place."</td>
<td>" '$'.$price."</td></tr>";
}
echo "</table>"
?>
</body>
</html>
I would like to put a dollar sign in the last column to tell the people viewing the website that is what it costs

2 recordset in dreamweaver with mysql DB could not be linked

My DB has 2 tables mp_details (unique id id) and pic_gal (unique ID pic_id).
pic_gal has a field mp_name which recieves
the value of mp_details id in the master admin page when the link to
visit is clicked the result is supposed to be like this
http://localhost/win-bengal/test-mp-details-new.php?id=['id']&mp_name=['mp_name']
e.g.
http://localhost/win-bengal/test-mp-details-new.php?id=1&mp_name=1 it
works fine for the first link but then onwards the problem starts
localhost/win-bengal/test-mp-details-new.php?id=2&mp_name=1
how ever
when this 1 is changed to 2 manualy the desired result is achieved. So
in other words 'mp_name' is returning just the first value. Please
help
This is the first Recordset which pull all the user information
mysql_select_db($database_mp_db, $mp_db);
$query_Recordset1 = "SELECT * FROM mp_details";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $mp_db) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
This is the second Recordset which pulls information about picture
mysql_select_db($database_mp_db, $mp_db);
$query_Recordset2 = "SELECT * FROM pic_gal";
$Recordset2 = mysql_query($query_Recordset2, $mp_db) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
This query is supposed to act as a bridge between the 2 tables where id of table mp_details is equal to mp_name of table pic_gal
$query = "SELECT mp_details.*, pic_gal.* ".
"FROM mp_details, pic_gal ".
"WHERE mp_details.id = pic_gal.mp_name";
$result = mysql_query($query) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ADMIN HOME</title>
<link href="../css/css-admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p> Add Record | upload Image</p>
<table width="75%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td bgcolor="#A9C8CB"><strong>id</strong></td>
<td bgcolor="#A9C8CB"><strong>Name</strong></td>
<td bgcolor="#A9C8CB"><strong>District</strong></td>
<td bgcolor="#A9C8CB"><strong>Phone</strong></td>
<td bgcolor="#A9C8CB"><strong>Email</strong></td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
<td bgcolor="#A9C8CB"> </td>
</tr>
<?php do { ?>
<tr>
<td><img src="../images/mp_photos/<?php echo $row_Recordset1['id']; ?>.jpg" alt="<?php echo $row_Recordset1['name']; ?>" width="" height="" border="0" title="<?php echo $row_Recordset1['name']; ?>" /><br /><?php echo $row_Recordset1['name']; ?></td>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
?>
here
< ? php echo $row_Recordset2['mp_name']; ? >
is supposed to echo the same value ad 'id' but it isn't happening so. it only echos the first value

Adding PHP comment box to my site

Hi i've managed to make some sort of a comment box that relies on the use of a mysql database and php coding. I'm able to run the comment box by opening its index.php file on my server but when i try adding it to a html page by using a simple include_once php code
it doesn't seem to work.
please excuse me if I sound stupid but this is my first time using php.
here is the code i've been trying to use.
<?php
include_once("../connect.php");
$commenting_form = '<form action="addcomment.php" method="post">
<table width="310" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><strong>Add Comment:</strong></td>
</tr>
<tr>
<td width="105">Title</td>
<td width="205"><input type="text" name="msg_title" id="msg_title" style="width:200px;" /></td>
</tr>
<tr>
<td colspan="2"><textarea name="msg_message" id="msg_message" style="width:100%;height:200px;font-family:Courier New">Message</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Add Comment" name="msg_submit" id="msg_submit" /></td>
</tr>
</table>
</form>';
$get_comments = mysql_query("SELECT * FROM comments");
$comments_count = mysql_num_rows($get_comments);
if ($comments_count>0)
{
while ($com = mysql_fetch_array($get_comments))
{
$id = $com['id'];
$title = $com['text'];
$message = $com['message'];
$comment .= '<strong>'.$title.'</strong><br />'.$message.'<hr />';
}
$comment .= $commenting_form;
$page_title = $comments_count.' Comments';
}
else
{
$comment = 'There are no comments at the moment.<br />'.$commenting_form;
$page_title = 'No Comments';
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $page_title; ?></title>
</head>
<body>
<?php
echo $comment;
?>
</body>
</html>
Try this:
include "../connect.php";
NOTE: make sure you put the right path of connect.php

connecting php with postgresql

I am a newcomer and have just started building a website.. I wrote the following code but its not working.it is not connecting to the database..If not this is there any other way to connect dreamweaver to postgresql ...please help..thnx in advance
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="span6">
<table class="table table-striped">
<thead>
<tr>
<th>Scheme-ID</th>
<th>Scheme Name</th>
<th>Scheme Type</th>
</tr>
</thead>
<tbody>
<?PHP
$conn = pg_connect("host=localhost port=5432 dbname=egram user=postgres password=password") or die("unable to connect to database");
if ($conn)
{
echo ("Connection attempt succeeded.");
}
else {
echo ("Connection attempt failed.");
}
$sql = "SELECT scheme_id,scheme_name,scheme_type FROM schemes";
$result = pg_query($conn,$sql); //order executes
if($result)
{
echo("query ran successfully");
while($data = pg_fetch_row($result))
{
echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td></tr>");
}
}
else
{
echo("error in running query");
}
?>
</tbody>
</table>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
#
</body>
</html>

Categories