Jump to content

Warning: mysql_query() expects parameter 2 to be resource,


DuaneCawaling

Recommended Posts

i'm a newbie at PHP prodramming and i want to add data to an existing data base, but unfortunately, the " Warning: mysql_query() expects parameter 2 to be resource,   "always pops up @@ here are my codes

 

 

<?php

$con=mysql_connect("localhost","root","duane");
// Check connection
if(!$con){
echo ("Could not connect." .mysql_error());
}
echo ("Connected successfully");
$selected = mysql_select_db("dummy") or die ("No existing database".mysql_error());


mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080392',15,1,'2m2','5:46'')") or die(mysql_error());
mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080390',20,1,'2m3','9:46'')") or die(mysql_error());



$data = mysql_query($selected, "SELECT * from prepurchase") or die (mysql_error());
while ($row = mysql_fetch_array($data)) {
echo "FN: ".$row{'Firstname'}." LN: ".$row{'Lastname'}." Age: ".$row{'Age'}."<br>";//display the results
}
mysql_close($con);
?>

 

the italic and bold codes are the error..please enlighten me with your knowledge. attached is the database i'm planning to modify using ph 

post-141682-0-50593300-1362175912_thumb.gif

In a form that's actually readable,

<?php

$con=mysql_connect("localhost","root","duane");
// Check connection
if(!$con){
echo ("Could not connect." .mysql_error());
}
echo ("Connected successfully");
$selected = mysql_select_db("dummy") or die ("No existing database".mysql_error());


mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080392',15,1,'2m2','5:46'')") or die(mysql_error());
mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080390',20,1,'2m3','9:46'')") or die(mysql_error());


$data = mysql_query($selected, "SELECT * from prepurchase") or die (mysql_error());
while ($row = mysql_fetch_array($data)) {
echo "FN: ".$row{'Firstname'}." LN: ".$row{'Lastname'}." Age: ".$row{'Age'}."<br>";//display the results
}
mysql_close($con);
?>

 

Read the manual page for mysql_query() to see how the function should be used. Spoiler: you're close.

 

Also,

echo "FN: ".$row{'Firstname'}." LN: ".$row{'Lastname'}." Age: ".$row{'Age'}."<br>";//display the results

 

 

{} array syntax is deprecated. Use []s instead.

$con=mysql_connect("localhost","root","duane");
// Check connection
if(!$con){
echo ("Could not connect." .mysql_error());
}
echo ("Connected successfully");
$selected = mysql_select_db("dummy") or die ("No existing database".mysql_error());
$result = mysql_query("INSERT INTO prepurchase(ID, Sum, Reply, items, time) VALUES('080390',20,1,'2m3','9:46')") or die(mysql_error());
$data = mysql_query("SELECT * from prepurchase") or die (mysql_error());
while ($row = mysql_fetch_array($data)) {
echo "ID: ".$row['ID']." Sum: ".$row['Sum']." Items: ".$row['items']."
";//display the results
}
mysql_close($con);

 

i'm sorry about the way i posted the codes, i was in a rush :) it works!changed the mysql_query parameters.. THANK YOU for the kind reply :) hoping to hear from you more coz i know his will not be the first time i'll ask questions about php

 

 

Archived

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

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