Forum Moderators: coopster

Message Too Old, No Replies

Error:Warning: mysql_fetch_array(): supplied argument is not a valid M

         

rus3439

9:46 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Hi,
Here is the code i got from this forum:
<?php
$host = "localhost";
$user = "*******";
$pass = "*******";
$dbname = "data";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$sql = "select * from 'tablename' where id=". $_POST['Name'] . $_POST['Address'] . $_POST['SS#'] . $_POST['Birthday'] . $_POST['Birth_place'] . $_POST['comments'];
echo $sql;

$query = mysql_query($sql);

while($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
echo "<p>",$row['Name'],":",
$row['Address'],
$row['SS#'],
$row['Birthday'],
$row['Birth_Place'],
$row['Comments'] ;
}
?>

Here is my form:

<form action="page5.php" method="post">
<P><STRONG>PLEASE ENTER THE FOLLOWING INFO BELOW::</STRONG></P>
<P><STRONG>Name:</STRONG>
<input type="text" name="Name" size="10"><br>
</P>
<P><STRONG>Address:</STRONG>
<input type="text" name="Address" size="10"><br>
</P>
<P><STRONG>SS#:</STRONG>
<input type="text" name="SS#" size="20"><br>
</P>
<P><STRONG>Birthday:</STRONG>
<input type="text" name="Birthday" size="10"><br>
</P>
<P><STRONG>Place Of Birth:</STRONG>
<input type="text" name="Birth_place" size="10"><br>
</P>
<P><STRONG>Comments:</STRONG>
<TEXTAREA NAME = "comments" ROWS = "4" cols = "20"></TEXTAREA>
</P>
<input type="submit" value="Submit" name="Submit">
<input type="submit" value="Show All Records" name="Show All Records">
</form>

I'm very new to this and can use any advise, thanks a lot

dreamcatcher

10:46 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I`m guessing that this is your problem.


$sql = "select * from 'tablename' where id=". $_POST['Name'] . $_POST['Address'] . $_POST['SS#'] . $_POST['Birthday'] . $_POST['Birth_place'] . $_POST['comments'];

Try changing it to (note the use of single and double quotes):


$sql = "select * from tablename where id='". $_POST['Name'] . $_POST['Address'] . $_POST['SS#'] . $_POST['Birthday'] . $_POST['Birth_place'] . $_POST['comments']. "';

also, you should use mysql_error() to give you the specific error message.

Change:


$query = mysql_query($sql);

to:


$query = mysql_query($sql) or die(mysql_error());

Hope that helps.

rus3439

11:45 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



i tried inserting error check and got the following message:
You have an error in your SQL syntax near ''tablename' where id=fgdfddfd' at line 1
Also can you please advise again on changing the quotes, because i copied the one you changed and all the color fonts became red in Dream Weaver.
thanks,

dreamcatcher

7:31 am on Aug 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Table names generally don`t have any quotes surrounding them, but if you do have problems, then a grave accent is used in some case:

$query = "SELECT * FROM `tablename`...

Your query should always use single quotes when comparing data.

$query = "SELECT * FROM `tablename` WHERE foo = '$boo'....

Unfortunately I have never used Dreamweaver, so maybe someone else can give you insight into the colours. I`m colour blind anyway. :)

dkin

8:31 am on Aug 22, 2004 (gmt 0)

10+ Year Member



Also what is this,

id=". $_POST['Name'] . $_POST['Address'] . $_POST['SS#'] . $_POST['Birthday'] . $_POST['Birth_place'] . $_POST['comments'];

why so many periods.

should it not jus be something like this

id = `$id`