Forum Moderators: coopster
The error i'm getting is: "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/panthero/public_html/gentry/submitlayout.php on line 7".
I'll post the code from the pages i'm having trouble with so that you may be able to understand what the problem is better. My site is currently skinned as well. Also, <password> is were my real password is.
submitlayout.php:
<?php$dbh=mysql_connect ("localhost", "panthero_panther", "<password>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("panthero_pantherodb");$q="insert into layouts (id,name,creator,creatorurl,date,series,category,previewimage,fileurl,previewurl,describe) VALUES ('','$filename','$creator','$creatorurl','$date','$series','$category','$previewimage','$previewurl','$describe')";
$result = mysql_query($q,$connection);
if ($result)
{
echo "thank you, Layout has been added.";
}
?>
Any ideas what the problem may be? I'd be much appreciative of any help i can get from anyone.
[edited by: jatar_k at 7:03 am (utc) on Dec. 9, 2004]
[edit reason] removed unnecessary code [/edit]
holy thats a lot of code and frankly I didnt read it.
I read the error message and went to the line it mentioned, I am not 100% sure what the actual line is but I have an educated hunch
I am guessing this line is dying
$result = mysql_query($q,$connection);
reason being that I don't see reference to a var named $connection since I see this
$dbh=mysql_connect ("localhost", "panthero_panther", "<password>") or die ('I cannot connect to the database because: ' . mysql_error());
your mysql_query should probably like so
$result = mysql_query($q,$dbh);
though since the second param is optional you could just have
$result = mysql_query($q);
<?php$dbh=mysql_connect ("localhost", "panthero_panther", "<password>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("panthero_pantherodb");$q = "INSERT INTO layouts (id, name, creator, creatorurl, date, series, category, previewimage, fileurl, previewurl, describe) VALUES ('', '$filename', '$creator', '$creatorurl', '$date', '$series', '$category', '$previewimage', '$previewurl', '$describe')";
$result = mysql_query($q);
if ($result)
{
echo "Thankyou. The layout has been added. Please press the BACK button.";
}
?>
It doesn't echo, and it isn't writing to the database. Any ideas why it isn't writing to the database?
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
Now it's telling me it can't INSERT INTO layouts "$q here". Then it says "Column count doesn't match value count at row 1". I'm very confused now. :(
<?
$q = "INSERT INTO layouts (id, name, creator, creatorurl, date, series, category, previewimage, fileurl, previewurl, describe) VALUES ('', '$filename', '$creator', '$creatorurl', '$date', '$series', '$category', '$previewimage', '$previewurl', '$describe')";
echo '<p>1:',$q;
?>
and my output was
1:INSERT INTO layouts (id, name, creator, creatorurl, date, series, category, previewimage, fileurl, previewurl, describe) VALUES ('', '', '', '', '', '', '', '', '', '')
which makes sense since I didn't have the vars
if there was no output and from the error message $q is not being evaluated for some reason. I can't see why.
You can't have a column named 'describe' it's a reserved word, I changed it to description (that's up to you)
You also missed a variable in your insert, $fileurl, you have it in the column list but not in the variables
I used this create statement, I just made it up
create table layouts(
id int(4) auto_increment primary key,
name varchar(100),
creator varchar(100),
creatorurl varchar(255),
date varchar(100),
series varchar(100),
category varchar(100),
previewimage varchar(255),
fileurl varchar(255),
previewurl varchar(255),
description varchar(100));
and I used this code in the end
<?
$filename = 'somefile.php';
$creator = 'jatar_k';
$creatorurl = 'someotherurl.com';
$date = '08/12/2004';
$series = 'someseries';
$category = 'somecategory';
$previewimage = '/somejpg.jpg';
$fileurl = 'some/other/url';
$previewurl = 'url.com';
$describe = 'this is going to work i hope';
//$dbconn = mysql_connect('localhost','myuser','mypass') or die (mysql_error());
$dbh=mysql_connect('localhost','myuser','mypass') or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("panthero_pantherodb");
$query = "INSERT INTO layouts (id, name, creator, creatorurl, date, series, category, previewimage, fileurl, previewurl, description) VALUES ('', '$filename', '$creator', '$creatorurl', '$date', '$series', '$category', '$previewimage', '$fileurl', '$previewurl', '$describe')";
$result = mysql_query($query) or die ('<p>err: ' . mysql_error());
if ($result) echo "Thankyou. The layout has been added. Please press the BACK button.";
?>
that should fix it :)
<?
$filename = 'filename';
$creator = 'creator';
$creatorurl = 'creatorurl';
$date = 'date';
$series = 'series';
$category = 'category';
$previewimage = 'previewimage';
$fileurl = 'fileurl';
$previewurl = 'previewurl';
$describe = 'description';$dbh=mysql_connect ("localhost", "panthero_panther", "<password>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("panthero_pantherodb");$query = "INSERT INTO layouts (id, filename, creator, creatorurl, date, series, category, previewimage, fileurl, previewurl, description) VALUES ('', '$filename', '$creator', '$creatorurl', '$date', '$series', '$category', '$previewimage', '$fileurl', '$previewurl', '$describe')";
$result = mysql_query($query) or die ('<p>err: ' . mysql_error());
if ($result) echo "Thankyou. The layout has been added. Please press the BACK button.";
?>
It IS writing to the database now, just not the input from the form.
$filename = 'filename';
$creator = 'creator';
$creatorurl = 'creatorurl';
$date = 'date';
$series = 'series';
$category = 'category';
$previewimage = 'previewimage';
$fileurl = 'fileurl';
$previewurl = 'previewurl';
$describe = 'description';
and you should be off to the races
and I am going to bed, back tomorrow ;)
very happy that my last post before bed sorted it all, I have tendency to say stupid things at that time. ;)