Jump to content

Recommended Posts

 

I'm very new at this and all I need is to display the mysql data I have three fields to display name color and county its just a test program.

 

I can enter the information into mysql database but cant display it on a page I get the error below

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/zendurl/public_html/m/m00ch00/display.php on line 18

 

I've search for it on these forums and cant find the problem anyone point me in a direction to help me or maybe point out my mistake

 

--------------------------

Input.php

 

<?php

$db_host = "localhost";

$db_user = "USER";

$db_pwd = "PW";

$db_name = "databasename";

mysql_connect($db_host, $db_user, $db_pwd);

mysql_select_db($db_name);

?>

<html>

<head>

<title>MySQL submission form</title>

</head>

<body>

<?php

if (!isset($_POST['submit'])) {

?>

<form action="" method="post">

Name: <input type="text" name="name"><br>

Favorite Color: <input type="text" name="color"><br>

What County are you from: <input type="text" name="county"><br>

<input type="submit" name="submit" value="Submit!">

</form>

<?php

} else {

$name = $_POST['name'];

$color = $_POST['color'];

$county = $_POST['county'];

mysql_query("INSERT INTO `colours` (name, favoriteColor, county) VALUES ('$name', '$color', '$county')");

echo "Success! Your favourite colour has been added!";

}

?>

</body>

</html>

 

-----------------------

Display.php

 

<html>

<head>

<title>Displaying MySQL Data</title>

</head>

<body>

<?php

$db_host = "localhost";

$db_user = "USER";

$db_pwd = "PW";

$db_name = "databasename";

mysql_connect($db_host, $db_user, $db_pwd);

mysql_select_db($db_name);

?>

<table>

<?php

$sql = "SELECT * FROM colours";

$query = mysql_query($sql);

if($row = mysql_fetch_array($query)) {

echo "<tr>";

echo "<td>".$row['name']."</td>";

echo "<td>".$row['favoritecolor']."</td>";

echo "<td>".$row['county']."</td>";

echo "</tr>";

}

?>

</table>

</body>

</html>

???

Forgive my slow replys my host is free and the users keep maxing out

 

I got the same error swapping the if for a while

 

My table is named colours without the single quotes?

will the single quotes effect the display.php page because the input.php works fine?

 

I'll take them off and see how it goes

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/zendurl/public_html/m/m00ch00/display.php on line 18 could it be to do with my database or is that not possible basically my database is build up as

 

name            Text null

favoritecolor  Text null

count            Text null

 

same problem changing the c in favoritecolor

i cant figure out y it is not workin 4 u...

 

but ur code s workin for me well..xcept that the value in 'favoritecolor' is not being displayed as the column names do not match.

ve u chkd frm the backend...r d records being inserted properly???

Turns out it was just my database name was wrong missed off a 0, took me all day to find that out

 

Thanks for your help though as without it I would still be thinking its that line Thanks jitesh & pranav_kavi yourve both bit very helpful  ;D

I now have another problem it was working correctly then I added in the code

 

echo "<tr class=\"data\">"; just above where if outputs my data

 

echo "<tr>"; <-- added here

echo "<td>".$row['name']."</td>";

echo "<td>".$row['favoritecolor']."</td>";

echo "<td>".$row['county']."</td>";

echo "</tr>";

 

now it only prints one line of my database information I then took the line out and replaced it with only <tr> which worked before and it still insists on only displayin one line of information out of mysql database I'm puzzled?!?!?

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.