Jump to content

html page with php script & mysql


allensim81

Recommended Posts

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>
<?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>

Link to comment
Share on other sites

1. Are you sure you want to create a new table in this code?  Is this page going to be viewed more than once by the same user(s)?  If so, you should create the table manually, through whatever database management system you have access to (phpMyAdmin?), and only let the PHP script insert/update data.

 

2. Where do $websites and $destination come from?

Link to comment
Share on other sites

What isn't working?

 

I can see one problem.  There is a syntax error:

 

$query="CREATE TABLE websitestable (websites varchar(100) NOT NULL,destination varchar(50) NOT NULL)

 

should be:

 

$query="CREATE TABLE websitestable (websites varchar(100) NOT NULL,destination varchar(50) NOT NULL)";

 

However, that query will fail after the first time the script is run since the table will already be created.

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.