David And Evan Posted November 6, 2008 Share Posted November 6, 2008 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 https://forums.phpfreaks.com/topic/131691-help-creates-new-page-overwrites-previous/ Share on other sites More sharing options...
Psycho Posted November 6, 2008 Share Posted November 6, 2008 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 https://forums.phpfreaks.com/topic/131691-help-creates-new-page-overwrites-previous/#findComment-684038 Share on other sites More sharing options...
flyhoney Posted November 6, 2008 Share Posted November 6, 2008 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 https://forums.phpfreaks.com/topic/131691-help-creates-new-page-overwrites-previous/#findComment-684041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.