0

I am attempting to use XAMPP as a simulated web server so that I can write files locally from my laptop. I do school work at my job but I don't have an Internet connection there that I can use to upload my PHP files to my school's web server. The Apache sever that comes as part of XAMPP works great for debugging .php files but I can't seem to connect to the database that I created in phpMyAdmin to debug MySQL code. Below is an example of what I am trying to do:

<?php

$user = 'root';
$password = '';
$database = 'jesse';

$con = mysql_connect('localhost', $user, $password, $database) or die( "Unable to      connect." );

$sql = "insert into CLIENT (First_Name) values ('Jesse')";

mysql_query($sql) or die("Insert failed. " . mysql_error());

?>

This returns: Insert failed. No database selected

8
  • Try client instead of CLIENT Commented May 2, 2014 at 15:57
  • @Colourity how would that help with a db selection error? Commented May 2, 2014 at 15:58
  • @RUJordan Not sure.... Just a quick guess. Also avoid using mysql. Use mysqli or even better PDO Commented May 2, 2014 at 16:00
  • Your right about mysqli, I'm avoiding it for the project that I'm working on because I've already coded around 10 pages in mysql. In the future I will stick with mysqli. Thanks though! Commented May 2, 2014 at 16:02
  • The issue has something to do with XAMPP. I can connect to my schools web sever no problem. Its trying to connect to the tables I created in phpMyAdmin. Commented May 2, 2014 at 16:06

2 Answers 2

1

You missed to select the database mysql_select_db($database,$con) ,Check this PHP mysql_select_db() Function

Sign up to request clarification or add additional context in comments.

5 Comments

can you try this $con = mysql_connect('localhost', $user,$password); mysql_select_db($database,$con) ?
I've tried that before too. I've been at this issue for some time now. Like two days. Asking here is my last ditch effort. If the community can't figure it out I'm throwing in the towel. As I stated in a comment above, it has something to do with XAMPP and phpMyAdmin. I don't have any issues manipulating tables from my school's web server.
I was thinking there might be an extra step in choosing a database from XAMPP. Like $database = 'myadmin/jesse' or something to that effect. I can connect to XAMPP, just not the database.
That would be if you were using an array, thats where you would use 'myadmin/jesse'
Not quite what I meant. I was thinking there might a path to the phpMyAdmin tables or something. I did a lot of searching and I saw nothing that would indicate this though. I'm just out of ideas.
0

It looks like the db created via either the xampp gui or script is locked within xamppfiles/var/sql but your admin script can be run from a php file, e.g. testdb.php in my xampp htdocs folder

 $con = mysql_connect('www.myplace', 'root', '') or die ("unable to connect");
 mysql_query('CREATE DATABASE test1', $con); //include if test1 doesn't already exist
 mysql_select_db('test1', $con);
 $sql = "INSERT INTO names (first_name) VALUES ('mini mouse')";
 mysql_query($sql) or die("insert failed"); 

Turn on xampp mySQL and Apache beforehand (or it doesn't add to the db). Run by opening that php page in the browser at http://www.myplace/home/wk10db/testdb.php where tested.php resides.

NB - www.myplace is really localhost but this site was giving me trouble posting

2 Comments

Is this intended to answer the question? If so, it doesn't appear to do so. Please clarify or remove.
I was also trying to create and manage the xampp mySQL db from script and not from the GUI and this and another thread stackoverflow.com/questions/9068767/… work in Mac to satisfy the objective.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.