Jump to content

[Help] Creates new page overwrites previous.


David And Evan

Recommended Posts

Hello me and my mate wrote a script which creates a new page and enters data on it. It gives the page an ID but unfortunitly it overwrites and put the data on all pages.

 

 

<?php
header("Location: refresh.html");
echo "<html>
<head>
<title></title>
<link href=\"Header.css\" rel=\"stylesheet\" type=\"text/css\" />
<link href=\"Banner.css\" rel=\"stylesheet\" type=\"text/css\" />
<link href=\"Blue.css\" rel=\"stylesheet\" type=\"text/css\" />
<link href=\"Suckerfish.css\" rel=\"stylesheet\" type=\"text/css\" />
<!--[if lte IE 6]>
<link href=\"Ie6.css\" rel=\"stylesheet\" type=\"text/css\" />
<![endif]-->
<link rel=\"shortcut icon\" href=\"favicon.ico\" />
</head>
<body>";
header("Location: refresh.html");
mysql_connect ("REMOVED", "REMOVED", "REMOVED") or die ('Error: ' . mysql_error());
mysql_select_db ("PageSubmission");
$busid = intVal($_POST['ID']);
$busname = mysql_real_escape_string(strip_tags(trim($_POST['busname'])));
$buscat = mysql_real_escape_string(strip_tags(trim($_POST['buscat'])));
$busloc = mysql_real_escape_string(strip_tags(trim($_POST['busloc'])));
$businfo = mysql_real_escape_string(strip_tags(trim($_POST['info'])));

$query="INSERT INTO business (ID, busname, buscat, busloc, info) VALUES ('NULL','".$busname."', '".$buscat."','".$busloc."', '".$businfo."')";
mysql_query($query) or die ('Error saving Data');
$data = mysql_query("SELECT * FROM business");
while($info = mysql_fetch_array( $data )) {
$body_content="<html>
<title>Kilkenny Business Directory - $busname</title>
<center><body>
<p>$busname</p><br>
<p>$buscat</p><br>
<p>$busloc</p><br>
<p>$businfo</p><br>
<script type=\"text/javascript\"><!--
google_ad_client = \"pub-1016814804288932\";
/* 468x60, created 11/3/08 */
google_ad_slot = \"6808829774\";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script> 
</center>";
echo $body_content;
// Store some text to enter inside the file
$file_name = "ads/".$info['ID'].".php";
$fp = fopen ($file_name, "w"); 
fwrite ($fp,$body_content);   
fclose ($fp);                                // closing the file pointer
chmod($file_name,0777);           // changing the file permission.
}

echo "</body></html>";
?>

 

So just to refresh it will create the new page but it will put the given info ie,

 

HTML Code:

 

<p>$busname</p><br>
<p>$buscat</p><br>
<p>$busloc</p><br>
<p>$businfo</p><br>

 

On all the previous pages created Ie, the newest page /ads/5.php will make all of the pages 1.php 2.php ect have the same content as 5.php

Link to comment
Share on other sites

Well, your query grabs every record from the business table and creates a file for each. I see nothin in the script that would restrict it to updating only 1 ID.

 

here is your script with some logical spacing and comments added with some lines left out for clarity.

//Select every record from the business table
$data = mysql_query("SELECT * FROM business");

//Go through each record in the result set.
while($info = mysql_fetch_array( $data )) {

    //Create body content and write to new file--FOR EACH RECORD ID
    $body_content="<html>";
    echo $body_content;
    // Store some text to enter inside the file
    $file_name = "ads/".$info['ID'].".php";
    $fp = fopen ($file_name, "w"); 
    fwrite ($fp,$body_content);   
    fclose ($fp);                                // closing the file pointer
    chmod($file_name,0777);           // changing the file permission.
}

 

If you only want it to update the file for record ID 5 you need to have some logic to handle that.

Link to comment
Share on other sites

Make sure your database table is set up to have a PRIMARY KEY 'ID' that is set to auto_increment.  Then, in your INSERT statement, just leave the ID out entirely and the database will do the work of creating a new row in the database with a new auto incremented ID.

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.