Jump to content

Recommended Posts

some how i cant update i dont know y

 

<div id="ahome">
<?php
include "scripts/connect.php";

if(isset($_GET[edit])){

$newid = $_GET['edit'];

$query = mysql_query("SELECT * FROM news WHERE id='$newid' LIMIT 1");
$rows = mysql_fetch_array($query);

$newstitle = stripslashes($rows['title']);
$newsby = stripslashes($rows['by']);
$newsbody = stripslashes($rows['body']);

}

?>
<?php


if ($_POST['saveedit']){

$newid = mysql_real_escape_string($_POST['saveedit']);
$newstitle = mysql_real_escape_string($_POST['title']);
$newsby  = mysql_real_escape_string($_POST['by']);
$newsbody = mysql_real_escape_string($_POST['body']);

if ($newstitle && $newsby && $newsbody){

$query = mysql_query("UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'");

echo "UPDATE SUCCESFULLY!";

}else
   $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>";

}

?>
<form action='enews.php' method='POST'>
<table>
<tr>
<td></td>
<td><?php echo $msg; ?></td>
</tr>
<tr>
<td>Article Title</td>
<td><input type='text' name='title' size='45' value='<?php echo $newstitle; ?>'/></td>
</tr>
<tr>
<td>By:</td>
<td><input type='text' name='by' size='30' value='<?php echo $newsby; ?>' /></td>
</tr>
<tr>
<td>Article Body</td>
<td><textarea cols='45' rows='25' name='body'><?php echo   stripslashes($newsbody); ?></textarea></td>
</tr>
<tr>
<td><input type='hidden' name='saveedit' value='$newid'/></td>
<td><input type='submit' name='updatebtn' value='Update' /></td>
</tr>
</table>
</form>
</div>

Link to comment
https://forums.phpfreaks.com/topic/253558-update/
Share on other sites

I don't do it like you, I always gave the query two parameters,

 

$query = mysql_query(dbc, "UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'");

 

actually, the second parameter is the link_identifier, the first parameter is the query.

 

OP, have you tried to debug this at all yet? I would start there.

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299812
Share on other sites

i get this Notice: Undefined variable: msg in /home/website/public_html/enews.php on line 63 but i dont think thats the problem and melloorr i go to the page to edit and i when im done editing and press update it looks like everything i edit stays there but when i click to another link and come back its still there

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299824
Share on other sites

Copy and paste this. If it doesn't work then I have no clue what could be the problem

 

<div id="ahome">
<?php
include "scripts/connect.php";

if(isset($_GET[edit])){

$newid = $_GET['edit'];

$query = mysql_query("SELECT * FROM news WHERE id='$newid' LIMIT 1");
$rows = mysql_fetch_array($query);

$newstitle = stripslashes($rows['title']);
$newsby = stripslashes($rows['by']);
$newsbody = stripslashes($rows['body']);

}


if(isset($_POST['updatebtn'])){

$newid = $_POST['saveedit'];
$newstitle = $_POST['title'];
$newsby  = $_POST['by'];
$newsbody = $_POST['body'];

if ($newstitle != '' && $newsby != '' && $newsbody != ''){

$query = mysql_query("UPDATE news SET title='$newstitle', by='$newsby', body='$newsbody' WHERE id='$newid'");

echo "UPDATE SUCCESFULLY!";

}else
   $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>";

}

?>
<form action='enews.php' method='POST'>
<table>
<tr>
<td></td>
<td><?php echo $msg; ?></td>
</tr>
<tr>
<td>Article Title</td>
<td><input type='text' name='title' size='45' value='<?php echo $newstitle; ?>'/></td>
</tr>
<tr>
<td>By:</td>
<td><input type='text' name='by' size='30' value='<?php echo $newsby; ?>' /></td>
</tr>
<tr>
<td>Article Body</td>
<td><textarea cols='45' rows='25' name='body'><?php echo   stripslashes($newsbody); ?></textarea></td>
</tr>
<tr>
<td><input type='hidden' name='saveedit' value='$newid'/></td>
<td><input type='submit' name='updatebtn' value='Update' /></td>
</tr>
</table>
</form>
</div>

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299825
Share on other sites

i get this

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by='Edward Jobs', body='While the PlayStation 3 is just now hitting its stride, ' at line 1

 

what does it mean

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299830
Share on other sites

i get this

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by='Edward Jobs', body='While the PlayStation 3 is just now hitting its stride, ' at line 1

 

what does it mean

 

"by" is a mysql reserved words, which means that you have to wrap the column name in backticks when using in a query, or rename the column.

 

$query = mysql_query("UPDATE news SET title='$newstitle', `by`='$newsby', body='$newsbody' WHERE id='$newid'") or die(mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299832
Share on other sites

floridaflatlander has a point.

 

i get this Notice: Undefined variable: msg in /home/website/public_html/enews.php on line 63

 

is this line 63?

 

$msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>";

 

That will not display it to the screen, it should be:

 

$msg ='<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>';
echo $msg;

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299836
Share on other sites

The error is due to the fact that the variable is only initialized in the event that one of the fields is left empty. It should be initialized as empty if there is no error, or it should be checked for a value before the echo, but that isn't related to the failure to update problem.

Link to comment
https://forums.phpfreaks.com/topic/253558-update/#findComment-1299840
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.