You are not logged in.

#1 07 Mar 2007 12:46 pm

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Advanced PHP Includes

Hello again, this time I am wondering how I can use PHP Includes to take the content from a single cell within a HTML document, and have the include paste it in another document. As far as I've managed to use it, I have only included entire files to another file. If you look here, you can see my current small system, that will post every ID in it's own cell (using a submit system I made with MySQL).

Is there a way I can include the content of a single cell? Or alternately, have the content of a cell be processed to another file? Need to be able to select a single ID from one of the cell's, to automatically have it pasted into another file. So that whenever the database updates, and dynamically adds a new ID to those fields, it will re-add it to the other file, where I can have the newest ID at the top and going downwards the the 5th newest.

Any suggestions or solutions are welcomed ;)


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#2 07 Mar 2007 2:33 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

includes don't work that way.  they are used to attach and run an existing php script.  require works the same way, except it will stop the script execution if the file you're trying to include doesn't exist.  include will continue running if it doesn't exist.

I believe the route that you're trying to get down is to store some values in a file, and retrieve those values.  at its heart, this is what the database is for.  html pages should only be used to present some data that you have stored (often called the "presentation layer" in programming).  the html page should pull that data from the same place that your php file is including it.

now if you're talking about doing whats called screen scraping, then you have to parse the file to obtain the details you're looking for.  I personally don't like the XML support in PHP (or at least the support in v4).  PHP 5 is better, but still, parsing an html file is cumbersome (because most HTML elements are not named, that makes it hard to know what TD in what TR in what TABLE  your in). 

if you're just wanting to include some random html in your page like an iframe would do you simply:

Code:

echo file_get_contents($someUri);

where someUri can be a local file or an http url.

Offline

 

#3 08 Mar 2007 5:26 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Yes, I see your point. I might have explained the problem a bit poorly, it's like this: I have a page with several tables, where each runs by a ID given out from the database. But instead of having them display the same data over and over, I need the top one to always have the newest ID (that's a easy one, just using LIMIT 1 in the MySQL query), but for the other ones, I need to be able to get the second newest ID, the third newest ID etc.

I figured that a easy way of doing this was for example being able to use an include for each of the cells in that document, since it posts out all ID's, with 1 in each cell. I don't know any XML, or what it's used for really.

Is there any other way to only put out the second, third, fourth or fifth newest ID from the database?


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#4 08 Mar 2007 7:09 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

your query to get the latest just needs to be formatted differently.  assuming you are using an auto-increment id, each new entry will have a larger id than its predecessor.  you can submit a query "select * from table order by `id_field_name` desc"  this way you'll get them in order that they were inserted.  if you only want one at time you can add the limit statement to this to get the last record inserted, then using its id, get the next and repeat this process to get subsequent ones. "select * from `table` where id < $last_id order by `id_field_name` desc"

Offline

 

#5 08 Mar 2007 8:57 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Ahh, so SELECT FROM "table" WHERE id < $last_id order by "id" DESC will give me the next id, instead of the newest one? But don't I need a SQL statement for $last_id that gives a condition (that made little sense to me, lol), or will the above SQL Query give the next id in line?

And yeh, my id field is auto_increment and primary.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#6 08 Mar 2007 1:54 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

there are 2 ways of doing it.  first, you get all the records in the database, and write them all out one at a time as you cycle over the returned results.  the second is to get them one at a time.  to get them all at once:

Code:

select * from `table_name` order by `id` desc

this will give you all of the records in your database starting w/ the newest record, ending w/ the oldest inserted record.  you can then cycle over these to do whatever you want with them.

the second way is to get them one at a time:

Code:

select * from `table_name` order by `id` desc limit 1

with this query, you'll get the id of the newest inserted record.  store that value in $newest_id in php, and the next time you need to pull second record:

Code:

select * from `table_name` where id < '$newest_id' order by `id` desc limit 1

this will give you your second newest inserted row.  store its id to $newest_id, and repeat.  you will get each record, starting from the newest to oldest.

Offline

 

#7 09 Mar 2007 4:48 pm

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Hmm, displays empty, usng this:

To query:

Code:

<?php
$con = mysql_connect("...","...","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("danwew_news", $con);

$result = mysql_query("SELECT * FROM news WHERE id < '$newest_id' ORDER BY id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
  {
  echo $row['id'];
  }
mysql_close($con);
?>

To save the $newest_id:

Code:

<?php
$con = mysql_connect("...","...","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("danwew_news", $con);
$newest_id = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 1");

mysql_close($con);
?>

Do they have to be in the same connection perhaps?

Last edited by Butcher (09 Mar 2007 8:56 pm)


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#8 09 Mar 2007 7:41 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

the first part:

Code:

<?php
$con = mysql_connect("...","...","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("danwew_news", $con);

$result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 1");
$newest_id = 0;
$row = mysql_fetch_array($result);
$newest_id = $row['id'];
echo $newest_id;
mysql_close($con);
?>

then, $newest_id will have the newest id, which you can then use in subsequent queries to get the next rows:

Code:

<?php
$result = mysql_query("SELECT * FROM news where id < $newest_id ORDER BY id DESC LIMIT 1");

$row = mysql_fetch_array($result);
$newest_id = $row['id'];
echo $newest_id;
mysql_close($con);
?>

Offline

 

#9 09 Mar 2007 8:55 pm

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Hmm, I probably should have cencored the connection, lol.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#10 09 Mar 2007 8:57 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

lol, you're a moderator... you can (although I did it for you big_smile)

Offline

 

#11 14 Mar 2007 7:46 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Decided to do an alternate method, that only puts out a result if there are multiple ones available. But something does something weird with the table build up, it splits at a completely unforseen end. Result of it can be seen at the bottom of this page.

I am using this code:

Code:

<?php $dbh=mysql_connect ("host","user","password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("database");
?>
<?php
        $result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
            while($myrow = mysql_fetch_assoc($result))
            {
                echo '<table width="650px" border="0" cellspacing="0" cellpadding="0">';
                echo '<tr background="images/news_top_grad.gif">';
                                        echo '<td colspan="3" align="left" class="style2">&nbsp;</td>';
                                         echo '</tr>';
                echo '<tr background="images/news_id_grad.gif">';
                echo '<td width="150px" align="left" class="style2">ID: ' . $myrow['id'] . '</td>';
                echo '<td width="250px" align="left" class="style2">Author: ' . $myrow['author'] . '</td>';
                echo '<td width="250px" align="left" class="style2">Date: ' . $myrow['date'] . '</td>';
                echo '</tr>';
                echo '<tr background="images/news_category_grad.gif">';
                echo '<td width="650px" class="style2">Category: ' . $myrow['category'] . '</td>';
                echo '</tr>';
                echo '<tr align="left" valign="top" bgcolor="272727">';
                echo '<td width="650px" class="style2">' . $myrow['content1'] . '</td>';
                echo '</tr>';
                echo '<tr background="images/news_sub_grad.gif">';
                echo '<th>&nbsp;</th>';
                echo '</tr>';
                echo '</table>';
                echo '<br />';
                echo '<br />';
            }
?>

For some weird reason, it splits it at the cell for Author, any idea why?


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#12 14 Mar 2007 12:40 pm

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Ahh, damned typos, it happened because I tried to force it to use width="650" instead of colspan="4".


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#13 14 Mar 2007 2:07 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

looks good!. you may want to wrap that text in a <span> w/ a style that allows the text to overflow but doesnt stretch the entire window like:

Code:

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

its something like <span style="overflow:auto;">text here</span>

Offline

 

#14 15 Mar 2007 7:21 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

I actually want it to be able to stretch the window, it will allow it to have all news on there, and if it is too much, I can just use the limit. If thats what you mean.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#15 18 Mar 2007 8:28 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Hmmm, there is something that eludes me when making a edit form. It wont actually update the database table, though it is set to do so. I made it like this:

1. I click a link thats sends me to the edit page and brings with me a certain ID, for a database table, code looks like this:

Code:

$result = mysql_query("SELECT * FROM news ORDER BY ID DESC");

while($row = mysql_fetch_array($result))
  {
$row['id'];
echo " ";
echo "<a href=\"news_edit.php?ID=$row[id]\">$row[title]</a>";
echo "<br />";
  }

Which posts a ID to the next page.

2. In the edit news page, it puts that ID in all the input fields php functions, to query the database to recieve all the correct info related to that ID, and everything in the table with the ID is shown, with this code:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WBeatzH - News Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
    color: #FFFFFF;
    font-weight: bold;
}
-->
</style>
</head>

<body bgcolor="#131313" alink="#FFFFFF" vlink="#FFFFFF" link="#FFFFFF">
<table width="800" border="0" cellspacing="1" cellpadding="0" align="center">
  <tr>
    <td height="150" colspan="3"><a href="http://danwew.freehostia.com/index.php"><img src="http://danwew.freehostia.com/logo.jpg" alt="Logo" width="800" height="150" border="0"></a></td>
  </tr>
  <tr>
    <td height="20" colspan="3"><?php include("http://danwew.freehostia.com/includes/navigation.php"); ?></td>
  </tr>
  <tr>
    <td width="150" height="200"><?php include("http://danwew.freehostia.com/includes/menu.php"); ?></td>
    <td width="650" rowspan="2">
    <form action="process_edit_news.php" method="post">
    <table width="650" border="0">
  <tr>
    <td align="right"><span class="style1">ID:&nbsp;</span></td>
    <td align="left">&nbsp;<input type="text" name="id" cols="30" maxlength="20" value="<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['id'];
  }
mysql_close($con);
?>" READONLY></td>
  </tr>
  <tr>
    <td width="350" align="right"><span class="style1">Title:&nbsp;</span></td>
    <td width="350">&nbsp;<input type="text" cols="30" maxlength="20" value="<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['title'];
  }
mysql_close($con);
?>">
  </tr>
  <tr>
    <td align="right"><span class="style1">Old Category:&nbsp;</span></td>
    <td>&nbsp;<input type="text" cols="30" maxlength="20" value="<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['category'];
  }
mysql_close($con);
?>" READONLY></td>
  </tr>
  <tr>
    <td align="right"><span class="style1">New Category:&nbsp;</span></td>
    <td>&nbsp;<select name="category">
                  <option value="WBeatzH News" selected="selected">
                  <label for="wn">WBeatzH News</label>
                  </option>
                  <option value="Site News">
                  <label for="sn">Site News</label>
                  </option>
                  <option value="Other News">
                  <label for="on">Other News</label>
                  </option>
                </select>
                <br>
                <?php
if(isset($_POST['category'])) {
    switch($_POST['category']) {
    case "wn":
    case "sn":
    case "on":
        echo "Category Input";
        }  
        }    
?></td>
  </tr>
  <tr>
    <td width="350" align="right"><span class="style1">Text:&nbsp;</span></td>
    <td width="350" height="160">&nbsp;<textarea name="content1" rows="8" cols="35" WRAP=SOFT><?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['content1'];
  }
mysql_close($con);
?></textarea></td>
  </tr>
  <tr>
    <td align="right"><span class="style1">Your Name :&nbsp;</span></td>
    <td>&nbsp;<input type="text" name="author" cols="30" maxlength="20" value="<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['author'];
  }
mysql_close($con);
?>"></td>
  </tr>
  <tr>
    <td align="right"><span class="style1">Old Date:&nbsp;</span></td>
    <td>&nbsp;<input type="text" cols="30" maxlength="50" value="<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['date'];
  }
mysql_close($con);
?>" READONLY></td>
  </tr>
  <tr>
    <td width="350" align="right"><span class="style1">Todays Date:&nbsp;</span></td>
    <td width="350">&nbsp;<input type="text" name="date" cols="30" maxlength="50" value="<?php
echo date("d");
?>
th of 
<?php
echo date("F");
?>
, 
<?php
echo date("Y");
?>" READONLY></td>
  </tr>
  <tr>
    <td width="350" align="right"><span class="style1">Your IP :&nbsp;</span></td>
    <td width="350">&nbsp;<input type="text" name="ip" cols="30" maxlength="20" value="<?php $ip = $_SERVER['REMOTE_ADDR']; 
    echo "$ip"; ?>" READONLY></td>
  </tr>
  <tr>
    <td align="right"><input name="Submit" type="submit" id="Submit" value="Submit"></td>
    <td><input name="Reset" type="reset" id="Reset2" value="Reset"></td>
  </tr>
</table>
    </form>
    </td>
  </tr>
  <tr>
    <td width="150" height="200"><?php include("http://danwew.freehostia.com/includes/menu.php"); ?></td>
  </tr>
  <tr>
    <td colspan="3"><?php include("http://danwew.freehostia.com/includes/copyright.php"); ?></td>
  </tr>
</table>
</body>
</html>

3. With the information from that page updated or changed, I press submit, and it sends me to my process page, where it should update the database entry, and this is where I am unsure of what to do. At the moment I am using the code from a regular INPUT command for the database, where it would have put it into a new table, but changed it to UPDATE instead. Using this code:

Code:

<html>
<head>
<title>Processed Information</title>
<meta http-equiv="Refresh" content="5;url=http://danwew.freehostia.com/admin/news_submit.php" />
</head>
<body>

<? 
mysql_connect("host","user","password") or die(mysql_error()); 
$id= mysql_real_escape_string($_POST['id']); 
$title = mysql_real_escape_string($_POST['title']); 
$category = mysql_real_escape_string($_POST['category']); 
$content1 = mysql_real_escape_string($_POST['content1']); 
$author = mysql_real_escape_string($_POST['author']); 
$date = mysql_real_escape_string($_POST['date']); 
$ip = mysql_real_escape_string($_POST['ip']); 
mysql_select_db("danwew_news") or die(mysql_error()); 
mysql_query ("UPDATE news SET $title='$title', $category='$category', $content1='$content1', $author='$author', $date='$date', $ip='$ip', WHERE ID='$ID'");
Print "Your information has been successfully added to the database, this site will close in 5 seconds."; 
?>

</body>
</html>

This then takes the results from the previous page, and inputs it here. As far as I can see, this should update the table for the ID I chose, though it doesn't. Any suggestion to what I am doing wrong?


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#16 18 Mar 2007 10:07 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

wrap it in a <form>...</form> element, and set the action to the processing page.  unless you do this, nothing gets posted to the processing page and $_POST will be empty.

Offline

 

#17 18 Mar 2007 10:39 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

I did, it has <form action="process_edit_news.php" method="post"> before the table, and </form> after it.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#18 18 Mar 2007 6:45 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

ah, notepad search failed me.  can you point out the code that does the sql update?  I dont see anywhere in your processing form that does an:

Code:

UPDATE `table` SET `column_x` = value, `column_y` = value WHERE `id` = value;

you're gonna need to do this in order to update the database.

Offline

 

#19 19 Mar 2007 11:37 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

I am using this:

Code:

mysql_query ("UPDATE news SET $title='$title', $category='$category', $content1='$content1', $author='$author', $date='$date', $ip='$ip', WHERE ID='$ID'");

Which I am assuming will update it based on the ID.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#20 19 Mar 2007 12:53 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

yep, that should do it.  check to see if its getting to there, or breaking before it gets there.  i'd create a string: $query = "UPDATE news SET $title='$title', $category='$category', $content1='$content1', $author='$author', $date='$date', $ip='$ip', WHERE ID='$ID'"; and echo that, just before you call mysql_query($query);

one thing you may also want to check, if ID is numeric, and you reference it like '8', the db will assume it's a string, and 8 doesn't equal '8' so you may want to drop the quotes.

Offline

 

#21 19 Mar 2007 2:13 pm

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Ok, ran this:

Code:

$query = "UPDATE news SET $title='$title', $category='$category', $content1='$content1', $author='$author', $date='$date', $ip='$ip', WHERE ID='$ID'";
echo $query;

Which gave the result:
UPDATE news SET ='', WBeatzH News='WBeatzH News', Testing SQL 3, 2222222='Testing SQL 3, 2222222', Butcher='Butcher', 19th of March, 2007='19th of March, 2007', 83.109.235.176='83.109.235.176', WHERE ID=''

It did not update the table though. And the 'id' field is set to "int", which I am pretty sure is numbers, or integers.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#22 19 Mar 2007 5:15 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

I think you missed my point about the data type, placing things in quotes usually makes them a string.  anyway, the problem is $ID is not set, and therefore is not updating the database (notice the WHERE ID='').

Offline

 

#23 20 Mar 2007 4:39 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

I recieved a new echo after changing some stuff, like this:

Code:

UPDATE news SET (WHERE ID=4, , WBeatzH News, Omg, cookies and milk in the morning!33, bitch, 20th of March, 2007, 83.109.235.176)

and, I changed the code to this:

This inserts the ID into the form:

Code:

<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("danwew_news", $con);

$sql = "SELECT * FROM news WHERE ID = '".mysql_escape_string($_GET['ID'])."'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
  {
  echo $row['id'];
  }
mysql_close($con);
?>

Which I tested several times, and work great.

Then, this code take the ID into the process form:

Code:

$id= mysql_real_escape_string($_POST['id']);

Figuring from the echo I recieve now, that one works too.

I am now using a slightly different query, which looks like this:

Code:

$query = "UPDATE news SET (WHERE ID=$id, $title, $category, $content1, $author, $date, $ip)";

As far as I can tell, this then follows this order:
1. Takes the ID from the link I pressed
2. Inserts it into the submit form
3. Takes it from the submit form, and puts it in the query, with the rest of the information

Though it seems to be all fine, and the echo seems fine, it does not actually update the database.

Last edited by Butcher (20 Mar 2007 4:41 am)


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 

#24 20 Mar 2007 7:35 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: Advanced PHP Includes

your old update statement is correct, this one is not.

the syntax for update is:

Code:

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

so the way you have it, isn't going to work.

Offline

 

#25 20 Mar 2007 7:51 am

Butcher
Moderator
From: Norway
Registered: Jul 2006
Posts: 308

Re: Advanced PHP Includes

Aha, so it has to have those double row references? Like this:

Used this now:

Code:

$query = "UPDATE news SET $title=$title, $category=$category, $content1=$content1, $author=$author, $date=$date, $ip=$ip, WHERE ID=$id";

What confuses me about this syntax though, is that the echo reflects itself:

Code:

UPDATE news SET =, WBeatzH News=WBeatzH News, Testing SQL 4, 2222=Testing SQL 4, 2222, Butcher=Butcher, 20th of March, 2007=20th of March, 2007, 83.109.235.176=83.109.235.176, WHERE ID=3

Is it supposed to do so? Cause the database has not updated. The query looks right according to the examples at that MySQL homepage, and the ones I usually follow at W3Schools.


http://bamboocommandos.com/butcher_img/butchersig7.jpg

Offline

 



© 2003 - 2024 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License