<html>
<body>
<?php
$username = 'root';
$password = '';
$hostname = 'localhost'; 
//connection to the database
$con = mysql_connect($hostname, $username, $password,'contactmanager') 
 or die('Unable to connect to MySQL');
echo 'Connected to MySQL<br>'.'<p>';
mysql_query($con,'INSERT INTO Personalinformation(Name, YearOfBirth, Email,Location,PhoneNumber)
VALUES(Peter,2008-03-05,peter@hotmail.com,kasland,0269015748)');
mysql_close($con);
?>
</body>
</html>

Recommended Answers

$con comes after the query, not before. See: http://php.net/mysql_query

Also check your mysql_connect

Jump to Post

You are missing mysql_select_db('dbname')
and in insert query string values should be in double inverted comma ""
$con not required in mysql_query
mysql_connect should not have dbname

Jump to Post

All 8 Replies

i keep on getting this error message.can the forum assit me pls.
Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\www\getinside.php on line 12

$con comes after the query, not before. See: http://php.net/mysql_query

Also check your mysql_connect

You are missing mysql_select_db('dbname')
and in insert query string values should be in double inverted comma ""
$con not required in mysql_query
mysql_connect should not have dbname

so where am putting $con.can elaborate further.i inserted mysql_select_db('dbname').now i dontget any error but it does not g intothe sql server thou it displays connected to mysql.

remove $con from mysql_query and add $con to mysql_select_db('your-db-name',$con).

Change this

mysql_query($con,'INSERT INTO Personalinformation(Name, YearOfBirth, Email,Location,PhoneNumber)
VALUES(Peter,2008-03-05,peter@hotmail.com,kasland,0269015748)');

to

mysql_query('INSERT INTO Personalinformation(Name, YearOfBirth, Email,Location,PhoneNumber)
VALUES("Peter","2008-03-05","peter@hotmail.com","kasland",0269015748)');

If this doesn't work then paste your updated code

<html>
<body>
<?php
$username = 'root';
$password = '';
$hostname = 'localhost';
//connection to the database
$con = mysql_connect($hostname, $username, $password)
or die('Unable to connect to MySQL');
echo 'Connected to MySQL<br>'.'<p>';
mysql_select_db("contactmanager",$con);
mysql_query('INSERT INTO Personalinformation(Name, YearOfBirth, Email,Location,PhoneNumber);
VALUES("Peter","2008-03-05","peter@hotmail.com","kasland",0269015748)');
mysql_close($con);
?>
</body>
</html>.
did not work.could it be some configuration from mysql phpadmin?

mysql_query('INSERT INTO Personalinformation(Name, YearOfBirth, Email,Location,PhoneNumber);
VALUES("Peter","2008-03-05","peter@hotmail.com","kasland",0269015748)');

above code have no space after Personalinformation(Name...) and there's ; at PhoneNumber); which shuoldn't be there.

Replace by this code

mysql_query('INSERT INTO Personalinformation (Name, YearOfBirth, Email,Location,PhoneNumber)
VALUES("Peter","2008-03-05","peter@hotmail.com","kasland",0269015748)');

thank u very much.it worked for me now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.