Page 1 of 1
html page with php script & mysql
Posted: Wed Jul 15, 2009 4:33 am
by allensim81
hi,i am newbie in php. I created a html page and included a php script and mysql in it.
I tested, somehow it doesn't work....
Can you please guide me step-by-step?
Thanks & appreciate your guidiance & help.
Love
Following is my code:
<html>
<?
$database="websites_database";
mysql_connect(localhost);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE websitestable (websites varchar(100) NOT NULL,destination varchar(50) NOT NULL)
$query = "INSERT INTO websitestable VALUES ('$websites','$destination')";
$query="SELECT*FROM websitestable";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
$i++;
}
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Websites</font></th>
<th><font face="Arial, Helvetica, sans-serif">Destination</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $websites; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $destination; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
<body>
<h1>Goverment Websites</h1>
<form action="insert.php" method="post">
<p>Website address:</p>
http:// <input type="text" name="websites" size="60">
destination: <input type="text" name="destination" size="30">
<input type="submit" value="Submit">
</form>
</html>
Re: html page with php script & mysql
Posted: Wed Jul 15, 2009 4:58 am
by Tiz
mhhh... learn php ?
First we use <?php better than <?
2nd : mysql_connect($server, $username, $password, [ ... ])
3rd : localhost => "localhost"
4th : $query is redefined 3 times, it is a string, so it is totally useless, you don't query your requests.
5th : it is mysql_num_rows()
6th : while ($i < $num) =====> $num ? where it is defined ?
7th : learn XHTML
Re: html page with php script & mysql
Posted: Wed Jul 15, 2009 11:17 am
by allensim81
hi, glad to hear from your reply ....
2nd : mysql_connect($server, $username, $password, [ ... ])
3rd : localhost => "localhost"
4th : $query is redefined 3 times, it is a string, so it is totally useless, you don't query your requests.
5th : it is mysql_num_rows()
6th : while ($i < $num) =====> $num ? where it is defined ?
7th : learn XHTML
mhhh... learn php ?
2nd : mysql_connect($server, $username, $password, [ ... ])
i put like this, correct or not?=>mysql_connect(localhost,$user,$password);
3rd : localhost => "localhost"
u mean like this=>mysql_connect("localhost",$user,$password);
4th : $query is redefined 3 times, it is a string, so it is totally useless, you don't query your requests.
u mean totally delete the 3 queries?
5th : it is mysql_num_rows()
how to put the above code, put it to where?
6th : while ($i < $num) =====> $num ? where it is defined ?
$num=mysql_numrows($result);
7th : learn XHTML
Re: html page with php script & mysql
Posted: Wed Jul 15, 2009 11:43 am
by omniuni
First, please use code tags.
Code: Select all
<html>
<?php
$database="websites_database";
mysql_connect(localhost);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE websitestable (websites varchar(100) NOT NULL,destination varchar(50) NOT NULL)";
$query = "INSERT INTO websitestable VALUES ('$websites','$destination')";
$query="SELECT*FROM websitestable";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
$i++;
}
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Websites</font></th>
<th><font face="Arial, Helvetica, sans-serif">Destination</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $websites; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $destination; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
<body>
<h1>Goverment Websites</h1>
<form action="insert.php" method="post">
<p>Website address:</p>
http:// <input type="text" name="websites" size="60">
destination: <input type="text" name="destination" size="30">
<input type="submit" value="Submit">
</form>
</html>
2nd : mysql_connect($server, $username, $password, [ ... ])
i put like this, correct or not?=>mysql_connect(localhost,$user,$password);
http://us2.php.net/function.mysql-connect
3rd : localhost => "localhost"
u mean like this=>mysql_connect("localhost",$user,$password);
That's better... "localhost" is a string, therefore, it should be in single or double quotes.
4th : $query is redefined 3 times, it is a string, so it is totally useless, you don't query your requests.
u mean totally delete the 3 queries?
No, just delete the three $query's (the variables) since there is nothing useful in them.
5th : it is mysql_num_rows()
how to put the above code, put it to where?
Look for the command in your code, you spelled it wrong. Also, be sure to terminate all lines with a semicolon.
6th : while ($i < $num) =====> $num ? where it is defined ?
$num=mysql_numrows($result);
7th : learn XHTML
Good luck, but please, try learning some basics first. I recommend going to
http://tizag.com and reading their PHP tutorial. It's not too long, very well written and easy to follow, and it'll help you catch the vast majority of the errors in the cod you posted.
Re: html page with php script & mysql
Posted: Wed Jul 15, 2009 11:53 am
by allensim81
hi, i done with the correction
Following is my code
I am really pretty new in php, hope you can guide me step-by-step, links that u shown me is marvelous!
I am so touched wth all of your reply...Appreciate u all!!
Code: Select all
<html>
<?php
$database="websites_database";
mysql_connect("localhost",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE websitestable (websites varchar(100) NOT NULL,destination varchar(50) NOT NULL)
$query = "INSERT INTO websitestable VALUES ('$websites','$destination')";
$query="SELECT*FROM websitestable";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
$i++;
}
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Websites</font></th>
<th><font face="Arial, Helvetica, sans-serif">Destination</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$websites=mysql_result($result,$i,"websites");
$destination=mysql_result($result,$i,"destination");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $websites; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $destination; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
<body>
<h1>Goverment Websites</h1>
<form action="insert.php" method="post">
<p>Website address:</p>
http:// <input type="text" name="websites" size="60">
destination: <input type="text" name="destination" size="30">
<input type="submit" value="Submit">
</form>
</html>
Re: html page with php script & mysql
Posted: Wed Jul 15, 2009 11:58 pm
by allensim81
Hi,i put 3 $query, 1st is to create table, 2nd is to insert the data into the table and the 3rd is to show the data...
It doesn;t work.... can anyone help me on this... Thanks in advance. Love