Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource


adap

Recommended Posts

$db_user = 'root';

$db_pwd = '';

 

$database = 'sk39_properties';

$table = 'properties';

 

if (!mysql_connect($db_host, $db_user, $db_pwd))

    die("Can't connect to database");

 

if (!mysql_select_db($database))

    die("Can't select database");

 

$sql = "select * from 'Properties' where id = 1";

$query = mysql_query($sql);

 

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

 

$id = $row['id'];

$Furnishing = $row['Furnishing'];

$Address = $row['Address'];

$Tenure = $row['Tenure'];

}

mysql_free_result($query);

 

 

?>

 

<html>

<head>

<title>Edit User Info</title>

</head>

 

<body>

 

<form action="updateinfo.php" method="post">

 

Id:<br/>

<input type="text" value="<?php echo $id;?>" name="id" disabled/>

 

<br/>

 

Furnishing:<br/>

<input type="text" value="<?php echo $Furnishing;?>" name="Furnishing"/>

 

<br />

 

Address:<br/>

<input type="text" value="<?php echo $Address;?>" name="Address"/>

 

<br />

 

Tenure:<br/>

<input type="text" value="<?php echo $Tenure;?>" name="Tenure"/>

 

</br>

 

<input type="submit" value="submit changes"/>

 

 

</form>

</body>

</html>

 

Above is my code.

When running it, it came out the following error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\editinfo.php on line 18

 

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\editinfo.php on line 25

Id:

 

Furnishing:

<br /> <b>Notice</b>:  Undefined variable: Furnishing in <b>C:\wamp\www\editinfo.php</b> on line <b>45</b><br />

Address:

<br /> <b>Notice</b>:  Undefined variable: Address in <b>C:\wamp\www\editinfo.php</b> on line <b>50</b><br />

Tenure:

<br /> <b>Notice</b>:  Undefined variable: Tenure in <b>C:\wamp\www\editinfo.php</b> on line <b>55</b><br />

 

Anyone can help!?  :'(

Link to comment
Share on other sites

Your last 3 errors are because of the fetch_array error..

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

it will tell you if the SQL is working correctly..

 

And after looking at the query..

$sql = "select * from 'Properties' where id = 1";

should be

$sql = "select * from `Properties` where id = 1";

Link to comment
Share on other sites

Thanks. It fixed.

By the way, would like to ask. If i wish to slightly change it.

This is how it works.

First, a php to prompt the user to change any of the data inside the table by key in the id which is the primary key.

After choosing it, it will link to another php file which serve like how the above php code that i posted.

From there, only they submit changes to it.

Any advise or enlighten? :)

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.