Jump to content

Archived

This topic is now archived and is closed to further replies.

dean012

Warning: mysql_query() expects parameter 2 to be resource, object given in F:\xampp\htdocs\taranaki2.php on line 69

Recommended Posts

Failed to connectarrow-10x10.png to MySQL:
Warning: mysql_query() expects parameter 2 to be resource, object given in F:\xampp\htdocs\taranaki2.php on linearrow-10x10.png 69

Notice: Undefined variable: resultarrow-10x10.png in F:\xampp\htdocs\taranaki2.php on line 81

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in F:\xampp\htdocs\taranaki2.php on line 81

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yakity Yak</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
  <p><!-- end #header --></p>
  <div id="header" class="container">
    <div id="logo">
      <h1><a href="#">Yakity Yak</a></h1>
    </div>
    <div id="menu">
      <ul>
        <li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li>
        <li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li>
        <li><a href="#">contact </a></li>
        <li><a href="#">Login</a></li>
		<li><a href="adminlogin.php">Leader</a></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </div>
  <blockquote>
    <blockquote>
      <p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388"  alt=""/></center>  </p>
    </blockquote>
  </blockquote>
  <div id="page">
    <div class="post">
      <h2 class="title"><a href="#">Taranaki</a></h2>
			<div class="entry">
				<table border='1'>
    
    </div>

	


 
</body>
</html>
<?php
/* This code establishes a connection with the database on the server. 
The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. 
It accepts two parameters, one is the name of the database and the other is the connection variable.*/
   
$con=mysqli_connect("localhost","root","","assesment");
// Check connection
if (mysqli_connect_errno())

$result = mysqli_query($con,"SELECT * FROM taranaki");
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
if(isset($_POST['update'])){
$UpdateQuery= "UPDATE taranaki SET ID='$_POST[ID]',Destination='$_POST[Destination]',Difficulty='$_POST[Difficulty]' ";
mysql_query($UpdateQuery, $con);
};



echo "<table border='1'>
<tr>
<th>ID</th>
<th>Destination</th>
<th>Difficulty</th>
</tr>";

while($row = mysqli_fetch_array($result)){
  echo "<form action=taranaki2.php method=post>";{
  echo "<tr>";
  echo "<td>" . '<input type="text"  name="ID" value=""/>'.         $row['ID'] .          "</td>";
  echo "<td>" . '<input type="text" name="Destination" value=""/>'. $row['Destination'] . "</td>";
  echo "<td>" . '<input type="text"  name="Difficulty" value=""/>'. $row['Difficulty'] .  "</td>";
  echo "<td>". '<input type="submit" name="update" value="update"/>'.                       "</td>";
  echo "</tr>";
  echo "</form>";}
echo "</table>";
}

mysqli_close($con);
?>

Share this post


Link to post
Share on other sites

i done that now i got

Warning: mysql_query() expects parameter 1 to be string, resource given in F:\xampp\htdocs\taranaki2.php on linearrow-10x10.png 73

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in F:\xampp\htdocs\taranaki2.php on line 83

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yakity Yak</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
  <p><!-- end #header --></p>
  <div id="header" class="container">
    <div id="logo">
      <h1><a href="#">Yakity Yak</a></h1>
    </div>
    <div id="menu">
      <ul>
        <li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li>
        <li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li>
        <li><a href="#">contact </a></li>
        <li><a href="#">Login</a></li>
		<li><a href="adminlogin.php">Leader</a></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </div>
  <blockquote>
    <blockquote>
      <p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388"  alt=""/></center>  </p>
    </blockquote>
  </blockquote>
  <div id="page">
    <div class="post">
      <h2 class="title"><a href="#">Taranaki</a></h2>
			<div class="entry">
				<table border='1'>
    
    </div>

	


 
</body>
</html>
<?php
/* This code establishes a connection with the database on the server. 
The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. 
It accepts two parameters, one is the name of the database and the other is the connection variable.*/
   
$con=mysql_connect("localhost","root","","assesment");
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE taranaki SET ID='$_POST[ID]', Destinations='$_POST[Destinations]', Difficulty='$_POST[Difficulty]' " ;
mysql_query($UpdateQuery, $con);
};
// Check connection
if (mysqli_connect_errno())


  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$result = mysql_query($con,"SELECT * FROM taranaki");


echo "<table border='1'>
<tr>
<th>ID</th>
<th>Destinations</th>
<th>Difficulty</th>
</tr>";

  while($row = mysqli_fetch_array($result));{
  echo "<form action=taranaki2.php method=post>";{
  echo "<tr>";
  echo "<td>" . '<input type="text"  name="ID" value=""/>'.         $row['ID'] .          "</td>";
  echo "<td>" . '<input type="text" name="Destinations" value=""/>'. $row['Destinations'] . "</td>";
  echo "<td>" . '<input type="text"  name="Difficulty" value=""/>'. $row['Difficulty'] .  "</td>";
  echo "<td>". '<input type="submit" name="update" value="update"/>'.                       "</td>";
  echo "</tr>";
  echo "</form>";}
echo "</table>";
}

mysql_close($con);
?>

Share this post


Link to post
Share on other sites

you are mixing mysqli and mysql functions

 

if you  use "mysql_connect" then you need to use "mysql_select_db" to connect the database

Share this post


Link to post
Share on other sites

and now i got this Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:\xampp\htdocs\taranaki2.php on linearrow-10x10.png 85

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yakity Yak</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
  <p><!-- end #header --></p>
  <div id="header" class="container">
    <div id="logo">
      <h1><a href="#">Yakity Yak</a></h1>
    </div>
    <div id="menu">
      <ul>
        <li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li>
        <li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li>
        <li><a href="#">contact </a></li>
        <li><a href="#">Login</a></li>
		<li><a href="adminlogin.php">Leader</a></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </div>
  <blockquote>
    <blockquote>
      <p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388"  alt=""/></center>  </p>
    </blockquote>
  </blockquote>
  <div id="page">
    <div class="post">
      <h2 class="title"><a href="#">Taranaki</a></h2>
			<div class="entry">
				<table border='1'>
    
    </div>

	


 
</body>
</html>
<?php
/* This code establishes a connection with the database on the server. 
The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. 
It accepts two parameters, one is the name of the database and the other is the connection variable.*/
   
$con=mysql_connect("localhost","root","","taranaki");
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE taranaki2 SET ID='$_POST[ID]', Destinations='$_POST[Destinations]', Difficulty='$_POST[Difficulty]' WHERE ID='$_POST[hidden]'"; ;
mysql_query($UpdateQuery, $con);
};


// Check connection
if (mysqli_connect_errno())


  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$sql = "SELECT * FROM taranaki2";
$myData = mysql_query($sql,$con);

echo "<table border=1>
<tr>
<th>ID</th>
<th>Destinations</th>
<th>Difficulty</th>
</tr>";

while($record = mysql_fetch_array($myData));{
echo "<form action=taranaki2.php method=post>";
echo "<tr>";
echo "<td>" . '<input type="text"  name="ID" value=""/>'.         $record['ID'] .          "</td>";
echo "<td>" . '<input type="text" name="Destinations" value=""/>'. $record['Destinations'] . "</td>";
echo "<td>" . '<input type="text"  name="Difficulty" value=""/>'. $record['Difficulty'] .  "</td>";
echo "<td>". '<input type="submit" name="update" value="update"/>'.                       "</td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['ID'] . " </td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}

mysql_close($con);
?>

Share this post


Link to post
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yakity Yak</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<p><!-- end #header --></p>
<div id="header" class="container">
<div id="logo">
<h1><a href="#">Yakity Yak</a></h1>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li>
<li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li>
<li><a href="#">contact </a></li>
<li><a href="#">Login</a></li>
<li><a href="adminlogin.php">Leader</a></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<blockquote>
<blockquote>
<p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388" alt=""/></center> </p>
</blockquote>
</blockquote>
<div id="page">
<div class="post">
<h2 class="title"><a href="#">Taranaki</a></h2>
<div class="entry">
<table border='1'>

</div>



<?php
/* This code establishes a connection with the database on the server.
The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from.
It accepts two parameters, one is the name of the database and the other is the connection variable.*/

$con = mysql_connect("localhost","root","","taranaki");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("taranaki",$con);



if(isset($_POST['update'])){
$UpdateQuery = "UPDATE taranaki2 SET ID='$_POST[ID]', Destinations='$_POST[Destinations]', Difficulty='$_POST[Difficulty]' ,WHERE ID='$_POST[hidden]'"; ;
mysql_query($UpdateQuery, $con);
};




$sql = "SELECT * FROM taranaki2";
$myData = mysql_query($sql,$con);

echo "<table border=1>
<tr>
<th>ID</th>
<th>Destinations</th>
<th>Difficulty</th>
</tr>";

while($record = mysql_fetch_array($myData));{
echo "<form action=taranaki2.php method=post>";
echo "<tr>";
echo "<td>" . '<input type="text" name="ID" value=""/>'. $record['ID'] . "</td>";
echo "<td>" . '<input type="text" name="Destinations" value=""/>'.$record['Destinations'] . "</td>";
echo "<td>" . '<input type="text" name="Difficulty" value=""/>'. $record['Difficulty'] . "</td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['ID'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}

mysql_close($con);
?>

</body>
</html>

Share this post


Link to post
Share on other sites

man this is so frustrating!! i fix it and another problem pop out.. it wont update any data

Share this post


Link to post
Share on other sites

in this line

 

$con = mysql_connect("localhost","root","","taranaki");

 

what is "taranaki", is this database password?, if yes, then it should be 3rd parameter of mysql_connect

 

also echo your SELECT query and check it in phpmyadmin

Share this post


Link to post
Share on other sites

i have change it to $con = mysql_connect("localhost","root",""); but still the same problem

Share this post


Link to post
Share on other sites

how many records are you getting for your SELECT query in phpmyadmin

 

SELECT * FROM taranaki2

Share this post


Link to post
Share on other sites

$UpdateQuery = "UPDATE taranaki2 SET ID='$_POST[id]', Destinations='$_POST[destinations]', Difficulty='$_POST[difficulty]' ,WHERE ID='$_POST[hidden]'";

Share this post


Link to post
Share on other sites

there is comma(,) before WHERE, remove it

 

echo $UpdateQuery = "UPDATE taranaki2 SET ID='$_POST[id]', Destinations='$_POST[destinations]', Difficulty='$_POST[difficulty]' WHERE ID='$_POST[hidden]' ";

Share this post


Link to post
Share on other sites

STOP NOW!

 

Use mysqli_ and you'll be headed in a great direction!  See the big fat warning?

 

Big Fat MySQL Extension Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

 

USE MySQLi INSTEAD

Share this post


Link to post
Share on other sites

×
×
  • 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.