Hello,
This I am sure is a rookie question but here goes.
I have a varuable $btn
I want to take what ever data that is currently in the field "news" in table "scrape_btn" and replace it with $btn
I am using php and MYSQL
how do I do it?
Many Many Thanks!
Chris W.
Replace Field Data
Moderator: General Moderators
-
chriswheat
- Forum Newbie
- Posts: 8
- Joined: Fri Oct 03, 2003 12:11 pm
Thank you for the response, I could not make it work.Paddy wrote:mysql_query("update scrape_btn set news='".$btn."'") or exit();
Here is all of the code... I used or die() statements at the end of my mysql statements then used a print mysql success to determine were the problem is. It appears to connect to the db and the table however it seams to die at the update command.
Code: Select all
<html>
<head>
<title>test</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
function New(window) {
OpenWin = this.open(window, "independent", "width=600,height=400,toolbar=1,menubar=0,location=1,scrollbars=1,resizable=1,screenX=1,screenY=1,status=0,titlebar=0");
}
</SCRIPT>
</head>
<body>
<?php
mysql_connect ('localhost', 'myuser', 'mypassword')or die();
print "connect success";
mysql_select_db ('mydatabase')or die();
print "<br>select db success";
$open = fopen("http://www.someserver.com/headlines/index.jsp", "r");
// the above statement opens up the page using the socket libraries and reads it,
// fopen takes the pages as the 1st arguement and type of opening (r in this case) as the 2nd
$read = fread($open, 45000);
// fread scours to the 15000th byte and captures all the encountered bytes into $read
fclose($open);
$search = eregi("<IMG SRC="/images/tab_headlines.gif" WIDTH="147" HEIGHT="17" BORDER="0"><BR>(.*)<TD valign="top" ALIGN="center">", $read, $printing);
// Case insensitive search on the data
$printingї1] = str_replace("<TABLE cellspacing="2" cellpadding="2" border="0" width="100%">", "", $printingї1]);
$printingї1] = str_replace("<TR>", "", $printingї1]);
$printingї1] = str_replace("<TD>", "", $printingї1]);
$printingї1] = str_replace("<IMG BORDER="0" HEIGHT="12" WIDTH="10" SRC="/images/arrow.gif"><font size="1" face="arial, helvetica, sans-serif">", "", $printingї1]);
$printingї1] = str_replace("</font>", "", $printingї1]);
$printingї1] = str_replace("</TD>", "", $printingї1]);
$printingї1] = str_replace("</TR>", "", $printingї1]);
$printingї1] = str_replace("</TABLE>", "", $printingї1]);
$printingї1] = str_replace("<BR CLEAR="none">", "", $printingї1]);
$printingї1] = str_replace("HREF="", "href="javascript:New('http://www.someserver.com", $printingї1]);
$printingї1] = str_replace("">", "');">", $printingї1]);
$printingї1] = str_replace("</A>", "</A><br><br>", $printingї1]);
// Striping and replacing data
$content = $printingї1];
$content = explode("·", $content);
// well this is also a common cancellation or rather the place where the shifting headlines into
// elements actually takes place with the help of "?" and explode();
$headlines = sizeof($content);
// counting the array elements
for ($i = 0; $i < $headlines; $i++) {
$btn = $contentї$i];
// If I use print "$btn"; instead of the below two statements it prints.
mysql_query("UPDATE scrape_btn SET news='".$btn."'")or die();
print "<br>Databes Update Success";
}
?>Chris W.
-
chriswheat
- Forum Newbie
- Posts: 8
- Joined: Fri Oct 03, 2003 12:11 pm
-
chriswheat
- Forum Newbie
- Posts: 8
- Joined: Fri Oct 03, 2003 12:11 pm