HELP??? update mysql data using php?
Posted: Tue Jan 27, 2004 5:33 pm
I'm trying to make a simple little content managment page. i have a little problem with the update function - it wont update the original it males a new entry and only puts oooo-oo-oo in the date... and does not write anything in the other tables.
here is how it looks:
http://www.networkvancouver.com/try/news.php
anyone able to help me? thanks...
here is how it looks:
http://www.networkvancouver.com/try/news.php
anyone able to help me? thanks...
Code: Select all
<?
@$db=mysql_connect("***","****","****");
mysql_select_db("*******");
if($submit=="submit"){
$query="insert into news values('','".$title."','".$date."','".$text1."','".$text2."')";
mysql_query($query);
header('Location: news.php');
}
///////////////////finished inserting
/////////////////////////start delete - update
if ($action=="update"){
$query="Update news set id, title, date, text1, text2 from news where id=".$id;
echo($query);
$result=mysql_query($query);
$output2=mysql_fetch_array($result);
mysql_query($query);
}
if ($action=="delete"){
$query="delete from news where id=".$id;
echo($query);
mysql_query($query);
}
/////////////////////////end delete - update
// set the select statement
$query="select id, title, date, text1, text2 from news";
$result_quiz=mysql_query($query);
// execute the query on the database and put it in the variable $result
$result=mysql_query($query);
// find out how many rows will be returned
$rows=mysql_num_rows($result);
// new table
echo("<table border='1'>");
echo ("<tr>
<td>Id</td>
<td>Title</td>
<td>Date</td>
<td>Text 1</td>
<td>Text 2</td>
</tr>");
// loop throught the results
for ($i=0;$i<$rows;$i++){
$output=mysql_fetch_array($result);
echo ("<tr>");
echo ("<td>".$outputї'id']."</td>");
echo ("<td>".$outputї'title']."</td>");
echo ("<td>".$outputї'date']."</td>");
echo ("<td>".$outputї'text1']."</td>");
echo ("<td>".$outputї'text2']."</td>");
echo ("<td><a href='news.php?id=".$outputї'id']."&action=update'>Update</a></td>");
echo ("<td><a href='news.php?id=".$outputї'id']."&action=delete'>Delete</a></td>");
echo ("</tr>");
}
echo("</table>");
?>
<!-- this is the form for the update -->
<br>
<form>
<b>Please upate:</b><br>
Title: <input type="text" name="question" size="80" value="<? echo($output2ї'title']);?>"><br>
Date: <input type="text" name="correct" size="30" value="<? echo($output2ї'date']); ?>"><br>
Text 1: <input type="text" name="wrong1" size="30" value="<? echo($output2ї'text1']); ?>"><br>
Text 2: <input type="text" name="wrong2" size="30" value="<? echo($output2ї'text2']); ?>"><br>
<input type='submit' name='submit' value='submit'>
</form>