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
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");

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.