Jump to content

Sript not working for some reason.


Ruud Hermans

Recommended Posts

I wrote the following script witch does not want to work. For some reason the table does not get created but I don't get any errors when I run it.Icreated the database using PHPMyAdmin, running WAMPSERVER. No password is attached to the root account.

<?phpinclude("config.php");mysql_connect(localhost,$user,$password);@mysql_select_db($database) or die( "Unable to select database");$query="CREATE TABLE firearms (name varchar(255) primary key,caliber varchar(255),trigger_action varchar(255),magazine_capacity varchar(255),lock varchar(255),weight varchar(255),lenght varchar(255),height varchar(255),barrel_lenght varchar(255),triggerstop varchar(255),scope varchar(255),scope_lenght varchar(255),comments text)";mysql_query($query);mysql_close();?>

This is the config.php file.

<?php$user = "root";$password = "";$database = "ruud";?>

Link to comment
Share on other sites

For starters, each of your mysql functions returns a value, but you're ignoring it. Put each one in a variable and echo it. Till you do that, you don't even know where to look for the problem. You're also not writing in a way to look at mysql_error().Also, don't be surprised about not receiving errors when your call to @mysql_select_db deliberately suppresses errors.Look at the first example here for a better framework: http://www.php.net/manual/en/function.mysql-select-db.php

Link to comment
Share on other sites

For starters, each of your mysql functions returns a value, but you're ignoring it. Put each one in a variable and echo it. Till you do that, you don't even know where to look for the problem. You're also not writing in a way to look at mysql_error().Look at the first example here for a better framework: http://www.php.net/manual/en/function.mysql-select-db.php
Do you have any examples of it used in the way I need to I have trouble finding it with google. I understand what is ment but sinds I am still learning I would have no idea how to us it.
and add one of these to the top of your script
// Report all PHP errorserror_reporting(E_ALL);// Same as error_reporting(E_ALL);ini_set('error_reporting', E_ALL);

Done.
Link to comment
Share on other sites

This could be simplified, but I wrote it the long way so you'd really see it.

$con = mysql_connect("localhost", "mysql_user", "mysql_password");if (!$con) {   $message = mysql_error ();   die ($message);}$db = mysql_select_db("mydb", $con);if (!$db) {   $message = mysql_error ();   die ($message);}// etc.

Link to comment
Share on other sites

Have you removed the error suppression (@) from the Select statement?
Glad someone mentioned that. I was sitting here thinking that would the first thing I would check. Also, make sure your connecting to database successfully before checking anything else.I prefer to put a small echo statement in my code when debugging such as
echo "got to here"

Place that in your code to find out where it is breaking.Example:

mysql_connect(localhost,$user,$password);@mysql_select_db($database) or die( "Unable to select database");echo "got to here";

Now if "got to here" is printed in the screen when the script is executed you know your script has made it that far. Place it in different places to see where it is breaking.

Link to comment
Share on other sites

I removed the "@" and managed to get the entire script working now, but now I face a problem with the form to insert info but I will create a new topic for that one.What is wrong with the spelling of "lenght" if I may ask?ScottR, so basicly using the thing you described I can watch if each table is made by just making it "echo" it got so far, that could be usefull in the future. :) I'm trying to make a database that people can also downoad to their own computer if the want to that will be updated every week, so making a installationscript that shows how far it made it is great. :)

Link to comment
Share on other sites

http://dictionary.reference.com/browse/length
echo 'Begin Connection here <br />';$con = mysql_connect("localhost", "mysql_user", "mysql_password");if (!$con) {   $message = mysql_error ();   die ($message);} else {echo 'Connection made! <br />';echo 'Begin Select here <br />';$db = mysql_select_db("mydb", $con);if (!$db) {   $message = mysql_error ();   die ($message);} else {echo 'Select made!<br />';}// etc.

You can add a descriptive message any place in the script while debugging.Remove them as the code tests out as working fine.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...