twilightnights Posted January 31, 2007 Share Posted January 31, 2007 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(); ?> Quote Link to comment Share on other sites More sharing options...
shoz Posted January 31, 2007 Share Posted January 31, 2007 What you're looking for is an "UPDATE" statement. The following alone will do what you ask. UPDATE tablename SET Author = "TwilightNights" Quote Link to comment Share on other sites More sharing options...
twilightnights Posted January 31, 2007 Author Share Posted January 31, 2007 Nice, ty Quote Link to comment Share on other sites More sharing options...
twilightnights Posted February 1, 2007 Author Share Posted February 1, 2007 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"); ?> Quote Link to comment Share on other sites More sharing options...
shoz Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
shoz Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.