Jump to content

Any help with this simple query?


twilightnights

Recommended Posts

I'm trying to insert me as author for all the jokes already on the site... what is wrong here?

 

<?
include("dbinfo.inc.php");
include("dbconnect.inc.php");


$query22 ="SELECT * FROM `$table` ORDER BY `jokeID` ASC";
$result33= mysql_query($query22);
$num53=mysql_numrows($result33);
$i=2;

echo"num53";

while($i < $num53)
{
$query ="INSERT INTO `$table` (Author)
values ('TwilightNights') WHERE `jokeID` = '$i'";
mysql_query($query);
$i++;
}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/36550-any-help-with-this-simple-query/
Share on other sites

What about this?

 

I think there is something wrong with this line, here is the whole code

$query ="SELECT * FROM `$table` ORDER BY jokeID ASC WHERE jokeID ="$i"";

 

<?php


include("dbinfo.inc.php");
include("celllayout.php");
$i= $_GET['i'];
IF ($i == null || $i < 0)
{
srand(time());
$random = (rand()%$num);
$i=$random;
}
Else if($i>0)
{
$i=$i-1;
}

include("dbconnect.inc.php");

$query ="SELECT * FROM `$table` ORDER BY jokeID ASC WHERE jokeID ="$i"";
$result= mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i1=0;

$jokeID=mysql_result($result,$i1,"jokeID");
$jokename=mysql_result($result,$i1,"jokename");
$jokebody=mysql_result($result,$i1,"jokebody");
$answer=mysql_result($result,$i1,"answer");
$cat1=mysql_result($result,$i1,"cat1");
$rating=mysql_result($result,$i1,"rating");
$votes=mysql_result($result,$i1,"votes");
$datetime=mysql_result($result,$i1,"datetime");
$author=mysql_result($result,$i1,"author");

?>

If you use double quotes inside of a double quoted string you have to escape them (\"). It's easier to use single quotes in this instance.

<?php
$query ="SELECT * FROM `$table` ORDER BY jokeID ASC WHERE jokeID ='$i'  ";
$result= mysql_query($query) or die($query."<br />\n".mysql_error());
?>

 

Note also the addition of "or die...". This will display the query and the error message associated with an erroneous query, making debugging easier while you test your script. You should remove it and use other error catching techniques when you go live.

Note also the addition of "or die...". This will display the query and the error message associated with an erroneous query, making debugging easier while you test your script. You should remove it and use other error catching techniques when you go live.

Better yet, call you own die() function that respects a global "debug" flag.

Note also the addition of "or die...". This will display the query and the error message associated with an erroneous query, making debugging easier while you test your script. You should remove it and use other error catching techniques when you go live.

Better yet, call you own die() function that respects a global "debug" flag.

 

Good suggestion.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.