Page 1 of 1

Stuck for hours: mysql_select error

Posted: Fri Jul 22, 2005 3:28 pm
by hustler
Guys, I have been stuck working on this for hours. I read a lot of forums before coming on here and I still can't figure out what is wrong. I am a php/mysql noob. I just started learning this and I am making this software for my aunt.

First I have a simple form that is post submitted to this page called storecust.php, which handles storing the data into the mysql data. I echoed all the data and it works. I even tried the query command in mysql command prompt and it works but it doesn't work here. I described the fiels in the customers table.

here is the error i am getting:
INSERT INTO customers (last, first, address, city, state, zip, phone, email) VALUES ('Azurin', 'Miguel', '1234 Bamboo St', 'Austin', 'TX', 78749, '5127654564', 'miguelazurin@hotmail.com')
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\projects\dryclean\storecust.php on line 14
mysql> describe customers;
+-------------+-----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+-------------------+----------------+
| cust_ref | int(11) | | PRI | NULL | auto_increment |
| last | text | | | | |
| first | text | | | | |
| address | text | | | | |
| phone | text | | | | |
| city | text | | | | |
| state | text | | | | |
| zip | int(11) | | | 0 | |
| date_joined | timestamp | YES | | CURRENT_TIMESTAMP | |
| no_visits | int(11) | | | 0 | |
| email | tinytext | YES | | NULL | |
+-------------+-----------+------+-----+-------------------+----------------+
11 rows in set (0.00 sec)

Code: Select all

<?php
	include('connectdb.php');

	connect_database();

	$query = "INSERT INTO customers 
		(last, first, address, city, state, zip, phone, email) VALUES 
		('$_POST[newlast]', '$_POST[newfirst]', '$_POST[newaddress]', 
		'$_POST[newcity]', '$_POST[newstate]', $_POST[newzip], 
		'$_POST[newphone]', '$_POST[newemail]')";
	
	echo "$query";
	
	$test = mysql_query($query, $conn);
?>
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Jul 22, 2005 3:30 pm
by ol4pr0

Code: Select all

<?php
	include('connectdb.php');
 
	connect_database();
 
	$query = "INSERT INTO customers 
		(last, first, address, city, state, zip, phone, email) VALUES 
		('".$_POST['newlast']."', '".$_POST['newfirst']."', '".$_POST['newaddress']."', 
		'".$_POST['newcity']."', '".$_POST['newstate']."', '".$_POST['newzip']."', 
		'".$_POST['newphone']."', '".$_POST['newemail']."')";
	
	echo "$query";
	
	$test = mysql_query($query, $conn);
?>

Posted: Fri Jul 22, 2005 4:00 pm
by hustler
didn't work. :(

I tried using an older command and there were no errors but it didn't do anything to the database. I can't even get this simple thing to work????!?!?!?!?!? What is going on?

I am currently using:
# PHP 5.0.2
# Apache 1.3.33
# MySQL 4.1.7
# Zend Optimizer 2.5.5
# phpMyAdmin 2.6.0-pl2
# Perl 5.8.4

I try testing this (no errors BUT no added records into the database):

Code: Select all

<?php
    include('connectdb.php');
 
    connect_database();
 
    /* $query = "INSERT INTO customers 
        (last, first, address, city, state, zip, phone, email) VALUES 
        ('" . $_POST['newlast'] . "', '" . $_POST['newfirst'] . "', '" . $_POST['newaddress'] . "', 
        '" . $_POST['newcity'] . "', '" . $_POST['newstate'] . "', '" . $_POST['newzip'] . "', 
        '" . $_POST['newphone'] . "', '" . $_POST['newemail'] . "')"; */
    
    $query = "INSERT INTO customers (last, first) VALUES (Pak, John)";
    
    echo "$query";
    
    $test = mysql_db_query($query);
?>
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Jul 22, 2005 4:21 pm
by timvw
Please notice that (VAR)CHAR values need to be between ''.

Code: Select all

INSERT INTO foo (col1, col2) VALUES ('val1', 'val2')
And offcourse you can always request mysql to return error information

Code: Select all

mysql_query($query) or die(mysql_error());

Re: Stuck for hours: mysql_select error

Posted: Mon Jul 25, 2005 8:13 pm
by harrisonad
That error is caused by query error. You can check what error message there is with mysql_error() function.

Code: Select all

$test = mysql_query($query, $conn);
if(!$test) die("Cannot execute query: $query<br>Message: ".mysql_error());

Re: Stuck for hours: mysql_select error

Posted: Mon Jul 25, 2005 8:55 pm
by timvw
Actually, PHP was complaining about $conn in your call to mysql_query..

Where does it come from?