Jump to content

[SOLVED] having a problem updating my database


gevo12321

Recommended Posts

ok

Im very new tp php

and i have a code that updates my database but i can find anything wrong with it. can someone plz tell me why it isnt working?

 

here is my code:

 

<?php
require_once('../connect.php');
$articleID=$_GET['newsnumber'];
$query = mysql_query("SELECT * FROM news WHERE newsnumber = '".$articleID."'") or die(mysql_error());
$row=mysql_fetch_object($query);
$date1=$row->date;
$titlea=$row->title;
$newsa=$row->news;
echo "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Edit News</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>

<body>
<form action=\"esubmiteditnews.php\" method=\"post\">
<table width=\"100%\" border=\"0\">
  <tr>
    <td width=\"10%\">Title (Max 300):</td>
    <td><input type=\"text\" name=\"title\" size=\"50\" value=\"";
echo $titlea;
echo"
\"/></td>
  </tr>
  <tr>
    <td width=\"10%\">Date (yyyy-mm-dd):</td>
    <td><input type=\"text\" name=\"date1\" value=\"";
echo $date1;
echo "
\"/></td>
  </tr>
  <tr>
    <td width=\"10%\" valign=\"top\">News:</td>
    <td><textarea cols=\"100\" rows=\"25\" name=\"news\"/>";
echo $newsa;
echo "
</textarea></td>
  </tr>
  <tr>
    <td width=\"10%\">News Number:</td>
<td><input type=\"text\" name=\"newsnumber\" size=\"10\" disabled value=\"
";
echo $articleID;
echo "
\"/>
</table>
<input type=\"submit\" value=\"Edit\">
</form>
</body>
</html>
";
mysql_close($link)
?>

 

the above code is the form

 

<?php
require_once('../connect.php');
$newsnumber = $_POST[newsnumber];
$date1 = $_POST[date1];
$title = $_POST[title];
$news = $_POST[news];
mysql_query("UPDATE news SET date = '$date1', title = '$title', news = '$news'
WHERE newsnumber = '$newsnumber'") or die(mysql_error());
echo "News Archive has been edited";
mysql_close($link)
?>

 

the above code is what the "edit" button should do

 

plz

someone help me

 

i have no idea what im doing wrong

 

ur help is greatly appreciated

thank you

Link to comment
Share on other sites

tips to debug!!

 

1. echo the query for update then check the data

2. if you use the phpmyadmin update certain file there and get the query result then compare the no step or if you cant still fixed

 

show me the echoed first step

Link to comment
Share on other sites

ok

 

so when i echo the query i used this code:

<?php
require_once('../connect.php');
$newsnumber = $_POST[newsnumber];
$date1 = $_POST[date1];
$title = $_POST[title];
$news = $_POST[news];
$query=mysql_query("UPDATE news SET date = $date1, title = '".$title."', news = '".$news."'
WHERE newsnumber = '".$newsnumber."'") or die(mysql_error());
echo $query;
echo "<br>News Archive has been edited";
mysql_close($link)
?>

 

and the result tat it gives me is:

 

1

News Archive has been edited

Link to comment
Share on other sites

no do this

echo UPDATE news SET date = $date1, title = '".$title."', news = '".$news."'

WHERE newsnumber = '".$newsnumber."'";

 

then if u r using phpmyadmin edit some file there and compare the output you have from above and if still you cant have it fixed show me the echoed result

Link to comment
Share on other sites

change your code to this...

<?php
require_once('../connect.php');
$newsnumber = $_POST[newsnumber];
$date1 = $_POST[date1];
$title = $_POST[title];
$news = $_POST[news];
$query="UPDATE `news` SET `date` = '". $date1 . "', `title` = '".$title."', `news` = '".$news."'
WHERE newsnumber = '" . `$newsnumber` . "'";
echo $query;
$query = mysql_query($query) or die(mysql_error());
if (
  mysql_affected_rows() > 0
  )
{
echo "<br>News Archive has been edited";
}
mysql_close($link)
?>

 

run teh page - check you db table if teh update still do not work then copy the query string (that is now eching out) and run teh direct in phpmyadmin (or what ever app you sue to administer your database) and see what it throws out.

Link to comment
Share on other sites

when i use toonmariner's code

 

i get the same thing as i did with tango84

 

so i guess the problem is that it is blank where its supposed to put the newsnumber

 

so maybe its not linked correctly or something

 

can someone plz check to see that i linked it properly?

 

thank you very much

Link to comment
Share on other sites

ok so the reason i guess that this doesn't work is because i used $_get to get the newsnumber for the form in the first place and than when i try to use the newsnumber form the form and it becomes blank

 

does anyone have an idea on how i could make this work?

Link to comment
Share on other sites

give as the result of what you echo remember the query and i check it out for you

 

"UPDATE `news` SET `date` = '". $date1 . "', `title` = '".$title."', `news` = '".$news."'

WHERE newsnumber = '" . `$newsnumber` . "'";

 

echo that and ill chek it out

 

Link to comment
Share on other sites

the result of that echo is:

 

UPDATE `news` SET `date` = '2007-06-22', `title` = 'Created a News Archive for the Website', `news` = 'All the news about this website is stored in the archive from the start of the project to this point. the Archive can be accessed by clicking the Archive button on the right. ' WHERE newsnumber = ''

Link to comment
Share on other sites

date` = '2007-06-22', ==== this maybe the prob i gues it should be

date` = 2007-06-22, if you declare it to your db as date

newsnumber = and where do you expect to have that value for where

 

$newsnumber = $_POST[newsnumber]; // check the form where you get that post and practice doing this for string $_POST['newsnumber']

Link to comment
Share on other sites

omg thank you sooooooooooooooooooooooooooooooooooooooooooooooooooooooo sooooooooooooooooooooooooooooooooooooooooooooooo soooooooooooooooooooooooooooooooooooooo much u rock

 

oh wow

 

im soooooooooooooooooo happy

 

lol

 

thank you

thank you

 

it works!!!!

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.