/    Sign up×
Community /Pin to ProfileBookmark

Mysql error in script

I am busy with an news script that is working with an log-in.
I was busy with an edit script to edit the posted news but now I get an Mysql error and I can’t correct it, so I hope someone here can help me.
Owyeah and you can go to the first page to edit then fill in everything but wen you push the submit button you get the error.

error:
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 ‘( id ) = ”’ at line 1

Page editnews.php (is included)

[code=php]<?php
include(“config.php”);
include(“flood.php”);
if ($MySession->Loggedin == 1)
{
//===========================================================//
$Query2 = mysql_query(“SELECT * FROM `news` WHERE id=’$newsid'”);
$news2 = mysql_fetch_object($Query2);
$Result = mysql_num_rows($Query2);
$Query9 = mysql_query(“SELECT * FROM `members` WHERE USERNAME=’$MySession->Username'”);
$Member9 = mysql_fetch_object($Query9);
$Query13 = mysql_query(“SELECT * FROM `profiles` WHERE id=’$Member9->id'”);
$Profile13 = mysql_fetch_object($Query13);
$Query9 = mysql_query(“SELECT * FROM `members` WHERE USERNAME=’$news->AUTHOR'”);
$Member9 = mysql_fetch_object($Query9);
//===========================================================//
if ($Profile13->RANK == “Administrator” OR $Profile13->RANK == “Moderator” OR $news2->AUTHOR == “$MySession->Username”)
{
$author=”$news2->AUTHOR”;
$idnews=”$news2->id”;
$category2=”news2->CATEGORY”;
//===========================================================//
if ($_POST[‘Submit’])
{ //als er op submit is gedrukt gaan we checken of alle velden wel zijn ingevuld …
if ($_POST[‘message’] == “”)
$error = “You have to fill in a message!<br><br>”;
if ($_POST[‘subject’] == “”)
$error = “You have to fill in a titel for you message!<br><br>”;
if (!$error)
{ //als er geen error is
if(!floodfilter(1)) {
echo “You have just posted an message, you must wait 20 seconds before you can post again.<br>
<a href=”javascript:history.go(-1)”>go back.</a>n”;
} else { //als het geen spammen is

//$query =”UPDATE news (AUTHOR, POSTDATE, MAINTEXT,
//SUBJECT, IPADRESS, CATEGORY) VALUES (‘$author’, NOW(), ‘$message’,
//’$subject’, ‘$REMOTE_ADDR’, ‘$category’)”;
$query = “UPDATE news SET AUTHOR=’$author’, SUBJECT=’$subject’, MAINTECT=’$message’, CATEGORY=’$category’ WHERE CONCAT ( id ) = ‘$news2->id'”;
mysql_query($query) or die (mysql_error());
echo “The news item has been updated!!<br>
Look for all the news (and your item) <a href=”index.php”>Here</a><br><br>”;
//als je de comment hebt gepost stuur je de bezoeker terug naar het nieuwsbericht

floodfilter(2); // poster toevoegen aan de floodfilter table
}
}
elseif ($error)
{ //als er een error is
echo ”
<div align=”center”><table width=”50%” border=”1″
cellspacing=”0″ cellpadding=”2″>
<tr bordercolor=”#000000″>
<td bordercolor=”#000000″ bgcolor=”#e2e2e2″ height=”36″>
$error<br>
<form method=”post” action=”javascript:history.go(-1)”>
<input type=”submit” name=”Terug” value=”Terug”>
</form>
</td></tr></table></div>”;
}
}
else
{
?>
<form name=”form” method=”post” action=”index.php”>
<input name=”id” type=”hidden” value=”editnews”>
<table width=”100%” border=”0″><tr>
<td height=”38″>
<strong>Edit news item</strong><br> <td></td></tr>
<td width=”20%”><strong>Author:</strong></td>
<td><? echo $author ; ?></td>
</tr>
<tr>
<td><strong>Category:</strong></td>
<td><select size=”1″ name=”category”>
<option value=”1″<? if ($category2==”1″) { echo” selected”; } ?>>General news</option>
<option value=”2″<? if ($category2==”2″) { echo” selected”; } ?>>Network news</option>
<option value=”3″<? if ($category2==”3″) { echo” selected”; } ?>>Call of Duty news</option>
<option value=”4″<? if ($category2==”4″) { echo” selected”; } ?>>Medal of Honor news</option>
<option value=”5″<? if ($category2==”5″) { echo” selected”; } ?>>Pacific Assault news</option>
</select></td>
</tr>
<tr>
<td><strong>Titel:</strong></td>
<td><input name=”subject” type=”text” size=”50″ maxlength=”30″ value=”<? echo $news2->SUBJECT ; ?>”></td>
</tr>
<tr>
<td valign=”top”><strong>BB codes:</strong></td>
<td>
<? echo “<input type=”button” value=”B” style=”font-weight:bold; width: 30px” onClick=”javascript:addtext(‘message’,'[b]text[/b]’)”>
<input type=”button” value=”i” style=”font-style:italic; width: 30px” onClick=”javascript:addtext(‘message’,'[i]text[/i]’)”>
<input type=”button” value=”u” style=”text-decoration: underline; width: 30px” onClick=”javascript:addtext(‘message’,'[u]text[/u]’)”>
<input type=”button” value=”Lijst” style=”width: 40px” onClick=”javascript:addtext(‘message’,'[list]text[/list]’)”>
<input type=”button” value=”Quote” style=”width: 50px” onClick=”javascript:addtext(‘message’,'[quote]text[/quote]’)”>
<input type=”button” value=”Link” onClick=”javascript:addtext(‘message’,'[url=www.mywebpage.com]My Web Page[/url]’)”>
<input type=”button” value=”Figuur” onClick=”javascript:addtext(‘message’,'[img]www.image.jpg[/img]’)”>
<input type=”button” value=”Code” style=”width: 40px” onClick=”javascript:addtext(‘message’,'[code]text[/code]

‘)”><br>”; ?>
</td>
</tr>
<tr>
<td valign=”top”><strong>Smilies:</strong></td>
<td>
<a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/smile.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/biggrin.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’:blink:’)”><img src=”images/smilies/blink.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’-_-‘)”><img src=”images/smilies/closedeyes.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/cool.gif” border=”0″></a><a href=”javascript:addtext(‘message’,'<_
<‘)”><img src=”images/smilies/dry.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’^_^‘)”><img src=”images/smilies/happy.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’:lol:’)”><img src=”images/smilies/laugh.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’:huh:’)”><img src=”images/smilies/huh.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’>_
<‘)”><img src=”images/smilies/mad.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’:mellow:’)”><img src=”images/smilies/mellow.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’:ninja:’)”><img src=”images/smilies/ninja.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/ohmy.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/sad.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/tongue.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’:unsure:’)”><img src=”images/smilies/unsure.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’?’)”><img src=”images/smilies/wink.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’:wub:’)”><img src=”images/smilies/wub.gif” border=”0″></a>
<a href=”javascript:addtext(‘message’,’:wacko:’)”><img src=”images/smilies/wacko.gif” border=”0″></a><a href=”javascript:addtext(‘message’,’:rolleyes:’)”><img src=”images/smilies/rolleyes.gif” border=”0″></a>
</td>
</tr>
<tr><td>
<strong>Message:</strong>
</td>
<td>
<textarea name=”message” cols=”60″ rows=”8″><? echo $news2->MAINTEXT ; ?></textarea>
</td></tr>
<tr><td>
</td><td><div align=”left”>
<input type=”submit” name=”Submit” value=”Edit news”>
<input type=”reset” name=”Reset” value=”Reset fields”>
<input type=”button” value=”Back to news”
onClick=”window.location=’index.php’ ” name=”button”>
</div></td></td></tr></table>
</form>
<?php
}
}
elseif ($Profile13->RANK != “Administrator” OR $Profile13->RANK != “Moderator” OR $news->AUTHOR != “$MySession->Username”)
{
echo”You are not allowed to edit this News Items! Only admins and the poster of the news can.<br><br>”;
echo”Click <a href=”index.php”>Here</a> to go back to the index of World War Shooter Source.”;
}
}
if ($MySession->Loggedin != 1)
{
$REASON=”to post news”
?><form method=”post” action=”index.php”>
<input type=”hidden” name=”Submit” value=”1″><input type=”hidden” name=”sent” value=”27″><input name=”id” type=”hidden” value=”login”>
You don’t have the permission <? echo $REASON ; ?>. You have to be a member of the <b>World War Shooter Source</b> crew to come in this area.<br>
You aren’t logged in yet, so please log-in down here or register at the register page.
Haven’t got an account yet? <a href=”index.php?id=register”>Register here!</a><br>
<br>
<table width=”34%” border=”0″>
<tr>
<td width=”34%”>Username:</td>
<td width=”66%”><input type=”text” name=”LoginName”></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=”password” name=”LoginPassword”></td>
</tr>
<tr>
<td height=”28″>&nbsp;</td>
<td><input name=”submit” type=”submit” value=”Login”>&nbsp;&nbsp;&nbsp;<a href=”index.php?id=register”>Register</a></td>
</tr>
</table>
</form>
<? } ?>[/code]

Mysql table:
CREATE TABLE `news` (
`id` int(11) NOT NULL auto_increment,
`SUBJECT` varchar(50) NOT NULL default ”,
`AUTHOR` varchar(50) NOT NULL default ”,
`MAINTEXT` longtext NOT NULL,
`POSTDATE` datetime default ‘0000-00-00 00:00:00’,
`IPADRESS` text NOT NULL,
`CATEGORY` varchar(10) NOT NULL default ‘1’,
PRIMARY KEY (`id`),
UNIQUE KEY `SUBJECT` (`SUBJECT`)
) TYPE=MyISAM COMMENT=’All the news items are listed here.’
AUTO_INCREMENT=7 ;

I hope someone can help me
Thank you ?

to post a comment
PHP

18 Comments(s)

Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — Remove the ' in the where clause after id

$Query2 = mysql_query("SELECT * FROM news WHERE id='$newsid'");

/ / / / / / / / / / / /

$Query2 = mysql_query("SELECT * FROM news WHERE id=$newsid");

Your table-definition says that "id" is from type "int" so you can't match it when you put a string as condition.
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — If I change he does the same only after the submit he gives the same error and also an PHP error ? :

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:apache2htdocsnewseditnews.php on line 8 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:apache2htdocsnewseditnews.php on line 9 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 '( id ) =' at line 1
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — ok, then try this:

$Query2 = mysql_query("SELECT * FROM news WHERE id='".$newsid."'");
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — Ok the PHP error is away again but somehow I still have the Mysql 1 ?
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — after you define the Query-Variable print it out, so that you can see the MySQL query-string. Perhaps the error lies in there.

$Query2 = mysql_query("SELECT * FROM news WHERE id='".$newsid."'");

echo $Query2;
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — [COLOR=red]Resource id #11[/COLOR]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 '( id ) =' at line 1

While I was trying to edit id=6

http://localhost/index.php?id=editnews&newsid=6
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — I think the variable doesn't get the value from your adress-line.

try to set the value explicitly.

$newsid = $_REQUEST['newsid'];
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — Still the same, but if I get it right when you go to the page it haves already checked that because I see the information in the fields that I can edit. If there is the error then he must give the error there but he give when you submit...

check it for you self maybe you understand then

http:///index.php?id=editnews&newsid=6

login

Username: TEST

password: lol

then go back to that link
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — Perhaps the error isn't in the first query. print out the mysql_error - message after each query to see which one has the error.

$Query2 = mysql_query("SELECT * FROM news WHERE id='".$newsid."'");

echo "Query2: " . mysql_error();

$Query3 = mysql_query("...");

echo "Query3: " . mysql_error();

...
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — then I get this:

Query2: Query9: Query13: Query9: query: 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 '( id ) =' at line 1

Isn't it

$Query2 = mysql_query("SELECT * FROM news WHERE id='".$newsid."'");

echo "$Query2: " . mysql_error();

But I have done the way you said
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — The error is in this query:

$query = "UPDATE news SET AUTHOR='$author', SUBJECT='$subject', MAINTECT='$message', CATEGORY='$category' WHERE CONCAT ( id ) = '$news2->id'";

is the "concat"-function intented? i think the where clause hast to be:

"... WHERE id = '$news2->id'";

If it is intented, what do you want to do with this function?
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — OK the error is away but he doesn't update the file ?

Really tahnks for already fixing this point but now I really don't know what to do because I don't get an error but he doesn't update the database ?

And the function was an mistake I think I don't know anymore why I had it in there :rolleyes:
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — if i've got your problem right, you have to reload the data after you've done the update. otherwise your variable has still the old values. so you have to do the query2 one more time after the update.
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — That doesn't help.

to let you understand right I will explain again in my best english ?

You can submit now and the page says it is updated, it will send you back to the home with all the news. But unless it said it is updated it isn't changed in the database so on the main and in database you still see the old message.
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — >>MAINTECT='$message'<< should be >>MAINTEXT='$message'<< in $query - right?

please tell me that it was a spelling - mistake and that it works now. otherwise i can't help you much more.
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — I had seen already :o sorry I didn't tell ?
Copy linkTweet thisAlerts:
@PeteIcemanJul 20.2004 — >>MAINTECT='$message'<< should be >>MAINTEXT='$message'<< in $query - right?

please tell me that it was a spelling - mistake and that it works now. otherwise i can't help you much more.
Copy linkTweet thisAlerts:
@BlackBloodauthorJul 20.2004 — no it wasn't ? Thank you for helping and I also really don't get why it goes wrong ? And the irritating is there is no error...

But really thanks for the part you helped me with ?
×

Success!

Help @BlackBlood spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...