Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2012, 06:24 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AfterAlot
Default have issues with my code

Code:
$dbc =  mysql_connect('localhost', 'root', '72031118311')
//if(!$dbc)
//{ unable to connect
or die('could not connect to the requested database'. mysql_error());
//
echo "connection successful"; 
mysql_close($dbc); 
echo "<br />";
	//create a query and store it as a string in a php variable
$query = "INSERT INTO contacts(first,middle,surname,email, phone,home,office) 
VALUES('$first','$middle','$surname','$phone','$email','$home','$office')";
$result = mysql_query($dbc,$query)
or die('Error querying database');
mysql_close();
The error message"Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\Nexus\contact.php on line 19" what is wrong with this code?
 
Old October 8th, 2012, 03:59 AM
Friend of Wrox
 
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

This;
Code:
$result = mysql_query($dbc,$query)
or die('Error querying database');
should be;
Code:
$result = mysql_query($query,$dbc)
or die('Error querying database');
because like the error message is telling you the command 'mysql_query' expects the 1st parameter to be a string (which contains the SQL query) and the optional 2nd parameter is the db link identifier.





Similar Threads
Thread Thread Starter Forum Replies Last Post
(Mac) Source code issues cpayne BOOK: Professional Cross-Platform Mobile Development in C# 1 July 14th, 2012 02:07 AM
Author's code for chapter 8, TableView has issues rcutshaw BOOK: Beginning iOS 4 Application Development 1 January 15th, 2011 05:45 PM
Issues trying to add code programatically Rowin_aboat Excel VBA 0 November 16th, 2010 11:35 AM
Chapter 6 code download issues tdewey BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 1 April 13th, 2009 04:48 PM
more book code issues skicrud Javascript How-To 1 June 3rd, 2004 09:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.