View Full Version : don't get it...its not working!
raptori
12-24-2002, 07:10 AM
when i try to run the code below i get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
$query = "SELECT * FROM translator where word_id = '$id'";
$result = mysql_query($query) or die("Error: " . mysql_error());
$values = mysql_fetch_array($reslut);
i don't see the problem, can you please tell me what im doing wrong?
thanks for help
If that's not a typo, you've mis-spelt $result in the mysql_fetch_array command.
Other than that, it looks fine, to me.
raptori
12-24-2002, 03:35 PM
thx Kiwi,
im trying to display the values from the db to the form but i get a blank screen.
<? $query = "SELECT * FROM translator where word_id = '$id'";
$result = mysql_query($query) or die("Error: " . mysql_error());
$values = mysql_fetch_row($result);
?>
<form name="form2" method="post" action="admin.php?cmd=edit">
<table width="372" border="0" cellspacing="2" cellpadding="1">
<tr>
<td width="103"><img src="spacer.gif" width="103" height="1"></td>
<td width="259"><img src="spacer.gif" width="193" height="1"></td>
</tr>
<tr>
<td><div align="right">ID: </div></td>
<td> <input name="id" type="text" disabled id="id" value="<? echo $values['word_id']; ?>" size="8"></td>
</tr>
<tr>
<td><div align="right">Word1: </div></td>
<td> <input name="ang_word" type="text" id="ang_word" value="<? echo $values['one_word']; ?>" size="35"></td>
</tr>
<tr>
<td><div align="right">Word2: </div></td>
<td> <input name="alb_word" type="text" id="alb_word" value="<? echo $values['two_word']; ?>" size="35"></td>
</tr>
<tr>
<td><div align="right">Example: </div></td>
<td> <textarea name="alb_shembull" cols="40" id="alb_shembull"><? echo stripslashes($values['two_meaning']); ?></textarea></td>
</tr>
<tr>
<td><div align="right">Meaning: </div></td>
<td> <textarea name="alb_meaning" cols="40" id="alb_meaning"><? echo stripslashes($values['two_example']); ?></textarea></td>
</tr>
<tr>
<td height="24"><div align="right">Approved: </div></td>
<td> <p>
<label>
<input name="aprovimi" type="radio" value="Yes" <? if ($values['word_apr']=="Yes")echo "Checked"; ?>>
Yes</label>
<br>
<label>
<input type="radio" name="aprovimi" value="No" <? if ($values['word_apr']=="No")echo "Checked"; ?>>
No</label>
</p></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" name="Submit2" value="Edit"></td>
</tr>
</table>
</form>
can someone help please,
thanks
This is the code I use for a similar purpose:function type_select_list($lvl) {
$sql_stmt="SELECT * FROM doc_types WHERE TypeLevel='$lvl' AND TypeActive='Y'";
if(!mysql_query($sql_stmt)) { // error handling
}
else {
$result=mysql_query($sql_stmt);
while($row=mysql_fetch_object($result)) {
echo("<option value='$row->TypeID'>$row->TypeShortDesc</option>\n");
}//while
} // if(!mysql_fetch_object($result))
}
And the html looks like this:<body onload="javascript: document.forms.mainform.date.value=date_today();">
<h1>Add Content Form</h1>
<form action="formproc.php?pg=00001" method="post" enctype="multipart/form-data" name="mainform">
<table>
<tr><td>Short Description</td>
<td><input type="text" name="sdesc"/></td></tr>
<tr><td>
Date (dd/mm/YYYY)</td>
<td><input type="text" name="date"/><input class="button" type="button" onclick="javascript: document.forms.mainform.date.value=date_today();" value="Today"></td></tr>
<tr><td>Type</td>
<td><select name="type" value='0001'><?php type_select_list(0); ?></select></td></tr>
</table>
</form>
</body>
Spookster
12-24-2002, 05:10 PM
When you get that error it typically means no records were returned.
I see two possible issues causing it besides what kiwi already pointed out.
1. You are treating 'id' as a string. Is it a string datatype in your table? If not then don't treat it as a string
SELECT * FROM translator where word_id = $id
2. You are not passing a value to $id. Try hardcoding a value in there:
if string datatype-
SELECT * FROM translator where word_id = '10'
if integer datatype
SELECT * FROM translator where word_id = 10
raptori
12-25-2002, 12:34 AM
i did that but the info still dosen't show up.
i wanted to make sure that if im getting any results so i did a row check and i got 1 row affected by that query.
I don't know what's wrong, that should be working....
any other options that would help to solove this problem?
thanks in advance
Two things I can suggest. Firstly, make sure that you're fetching associative arrays (by default you do with mysql_fetch_array, but not with mysql_fetch_row). To test this, start returning $value[0] and seeing if that gives you any data. This may well be your problem.
Secondly, put in some debugging routines. I would dump most of the html for now, until you get the functions to start returning the values you want. Once you rip the code out, you can then start echoing the array values. A loop like this can help:
$query = "SELECT * FROM translator where word_id = '$id'";
$result = mysql_query($query) or die("Error: " . mysql_error());
while($values = mysql_fetch_row($result)) {
echo("<p>");
foreach($values as $key=>$value){
echo($key.": ".$value."<br/>");
}
echo("</p>");
} // while
This will dump the entire result set to the page in a readible form.
raptori
12-25-2002, 04:18 PM
here is another strange thing...
i have a query to update a filed that looks like this:
<?
//more lines above
$update_query = "update translator set word_apr = '$apr' WHERE word_id = $id";
//more lines below?>
and when i run it, it says : You have an error in your SQL syntax near '' at line 1
i know that the query is fine and to make sure its correct i go into phpmyadmin to see if it works and BAMM it works.
now that made me so :mad:, how come it works with phpmyadmin but it doesn't work with my script?
is the server playing tricks on me or im doing something wrong?
mordred
12-25-2002, 10:07 PM
Try to print your SQL query to see what's really in your query. Your example leaves the content of $apr and $id open, and if there are any single quotes in these variables your query will most likely fail. It looks to as if addslashes($apr) could help. PhpMyAdmin does that automagically to your queries, AFAIR.
Do you echo the query string to the screen -- this usually helps, as you get to see the exact string that's being sent to mySql.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.