Jump to content

Archived

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

simcoweb

Starting Big Project or How To Learn PHP In A Hurry

Recommended Posts

Ok, thanks for the clarification. I'll work with that until I get stuck. Shouldn't be more than...oh... 10 minutes ;)

Share this post


Link to post
Share on other sites
WHY is this mysql code giving me this error message?  ???

[code]<?php
include 'config.php';
// Make connect to DB first
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
// need to create the category table
mysql_query("CREATE TABLE category(
catid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(cat_id),
catname VARCHAR(100)") or die(mysql_error());

if (mysql_error()) {
echo "Problem with creating database. Try again.";
} else {
echo "Category and Member Tables Were Created Successfully!";
}
?> [/code]

[quote]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4[/quote]

I ran an identical query without a hitch to create another table. The error just refers to line 4 but i've even gone so far as to rewrite line 4 and 5 to see if there were any hidden spaces or characters. Still get the error.

Share this post


Link to post
Share on other sites
catid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(cat_id),

catid and cat_id - there's your problem

Share this post


Link to post
Share on other sites
Thanks for the quick response. Actually I already tried that and got the same error. I think what I posted was the 'unfixed' version of the code. Here's the corrected version and it's still producing the same error.

[code]<?php
include 'config.php';
// Make connect to DB first
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
// need to create the category table
mysql_query("CREATE TABLE category(
catid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(catid),
catname VARCHAR(100)") or die(mysql_error());

if (mysql_error()) {
echo "Problem with creating database. Try again.";
} else {
echo "Category and Member Tables Were Created Successfully!";
}
?>[/code]

I don't see anything that could cause the problem. I tried also without the 'if' statement. Same error.

I ran this query on the same database without a hitch. It's basically identical to the one causing the problem up to the point of the table name and fields.

[code]<?php
include 'config.php';
// Make connect to DB first
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die("Where is the dang database");

// Now we create the tables and rows
mysql_query("CREATE TABLE members(
memberid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(memberid),
name VARCHAR(50) NOT NULL,
business VARCHAR(255) NOT NULL,
title VARCHAR(50) NOT NULL,
phone VARCHAR(30) NOT NULL,
email VARCHAR(50) NOT NULL,
url VARCHAR(50) NOT NULL,
details VARCHAR(255) NOT NULL,
specialties VARCHAR(255)  NOT NULL,
image VARCHAR(255) NOT NULL,
thumb_image VARCHAR(255) NOT NULL,
category VARCHAR(30) NOT NULL)") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
For some odd reason it would only work if I ran these queries. Note that they are different but within the same file. I don't know what the syntax error was referring to but this worked:

[code]<?php
include 'config.php';
// Make connect to DB first
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die("Where is the dang database");

// Now we create the tables and rows
mysql_query("CREATE TABLE members(
memberid INT(30) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(memberid),
name VARCHAR(50) NOT NULL,
business VARCHAR(255) NOT NULL,
title VARCHAR(50) NOT NULL,
phone VARCHAR(30) NOT NULL,
email VARCHAR(50) NOT NULL,
url VARCHAR(50) NOT NULL,
details VARCHAR(255) NOT NULL,
specialties VARCHAR(255)  NOT NULL,
image VARCHAR(255) NOT NULL,
thumb_image VARCHAR(255) NOT NULL,
category VARCHAR(30) NOT NULL)") or die(mysql_error());

// need to create the category table
mysql_query ('CREATE TABLE `category` ('
        . ' `catid` INT(30) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `catname` VARCHAR(50) NOT NULL'
        . ' )')
        . ' TYPE = myisam;';

if (mysql_error()) {
echo "Problem with creating database. Try again.";
} else {
echo "Category and Member Tables Were Created Successfully!";
}

?>[/code]

Share this post


Link to post
Share on other sites
Hi Barand. In which post and where? I've stared at that until I passed out. I can't see where it's missing the ')' anywhere.

Share this post


Link to post
Share on other sites
// need to create the category table
mysql_query("CREATE TABLE category(
catid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(cat_id),
catname VARCHAR(100) [size=14pt][color=red])[/color][/size] ") or die(mysql_error());

Share this post


Link to post
Share on other sites
I'm getting this error message on this bit of code that's based on the reply #12:

[quote]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'catid = '1'' at line 4[/quote]

[code]<?php
include 'config.php';
$cat = '1';
$img_src = 'images/thumbs/';

// Make connect to DB first
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die("Where is the dang database");

$sql = "SELECT m.name, m.memberid, m.title, m.details, m.thumb_image
    FROM member m INNER JOIN member_cat mc
    ON m.memberid = mc.memberid
    WHERE mc,catid = '$cat'";
$res = mysql_query($sql) or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
Ok, that took care of that one. Next in line after fixing that is:

[quote]Unknown column 'mc.memberid' in 'on clause'[/quote]

Now, i'm not familiar with this type of inquiry where you are joining the 'm' and the 'mc' to the query parameters, but there IS a column named 'memberid' in the 'members' database.

Share this post


Link to post
Share on other sites
It's saying there isn't a memberid column in the member_cat table

Share this post


Link to post
Share on other sites
Ok, that's all figured out. But this error is happening now:

[quote]Fatal error: Call to undefined function: mysql_unsert_id() in /home2/wwwxxxx/public_html/addbiz.php on line 161[/quote]

Here's my code:

[code]$sql = "INSERT INTO member (business, name, title, phone, email, url, details, specialties, image, thumb_image) VALUES ('$business', '$name', '$title', '$phone', '$email', '$url', '$details', '$specialties', '$image', '$thumb_image')";
mysql_query($sql);
$newid = mysql_unsert_id();

$sql = "INSERT INTO members_cat (memberid, catid) VALUES ('$newid', '$catid')";
mysql_query($sql);[/code]

Share this post


Link to post
Share on other sites
Because there is no such function as mysql_unsert_id(). Its mysql_insert_id().

Share this post


Link to post
Share on other sites
Heh, thought I caught all the typos when I copied the code but didn't know that 'unsert' was supposed to be 'insert' :)

Ok, i'm running this query and nothing is getting inserted into the database(s) at this time.

[code]$sql = "INSERT INTO members (business, name, title, phone, email, url, details, specialties, image, thumb_image) VALUES ('$business', '$name', '$title', '$phone', '$email', '$url', '$details', '$specialties', '$image', '$thumb_image')";
mysql_query($sql);
$newid = mysql_insert_id();

$sql = "INSERT INTO members_cat (memberid, catid) VALUES ('$newid', '$catid')";
mysql_query($sql);[/code]

Oddly enough i'm not getting any error messages either. I'll try again with an 'or die' in there and see if something pops up. But why it's not inserting is another question.

Share this post


Link to post
Share on other sites
try
[code]<?php
$sql = "INSERT INTO members (business, name, title, phone, email, url, details, specialties, image, thumb_image) VALUES ('$business', '$name', '$title', '$phone', '$email', '$url', '$details', '$specialties', '$image', '$thumb_image')";
mysql_query($sql) or die (mysql_error());
?>[/code]

and see it you get an error message

Share this post


Link to post
Share on other sites
Did that and it did produce an error. It was my turn for a typo. I had 'member_cat' as the table name while the query was looking for 'member[color=red]s[/color]_cat'. I made the switch and the data inserted fine.

The next step is figuring how to set up the image and the thumbnail functions. The 'add' form for the member's includes an image upload. I need to have that image available at a specific size for the 'summary' page and then for a fuller size for the 'profile' page.

I've looked around the forums and see lots of issues about thumbs or images but nothing specific to how to operate this during the initial insertion of the data into the mysql database. The other topics seem to address it in more of a 'File Uploader' kind of thing and this is a profile generator whereas the image is uploaded at the same time as their personal and business data.

Ideas?

Share this post


Link to post
Share on other sites
Have your registration form with a file field for the photo.

[code]
<FORM action="otherpage.php" method="POST" enctype="multipart/form-data">
Name : <input type="text" name="name" size="20"><br>
Title: <input type="text" name="title" size="20"><br>
Photo: <input type="file" name="image"><br>
<input type="submit" name="submit" value="Submit">
</FORM>
[/code]

You are going to need a RESIZE() function which takes as aguments (input_file, output_file, size) and outputs a resized image to the output_file, which in my example code below creates a fuller image 400px wide and a thumb image 100px wide

The processing would be something like this (pseudocode)

[code]
    insert record without the filenames
    get $newid = mysql_insert_id()
    $fuller = "path/to/images/image_$newid.jpg";
    $thumb =  "path/to/images/thumb_$newid.jpg";
    resize($_FILES['image']['tmp_name'], $fuller, 400);
    resize($_FILES['image']['tmp_name'], $thumb, 100);
    UPDATE members SET image = '$fuller', thumb_image = '$thumb' WHERE memberid = $newid
[/code]

Share this post


Link to post
Share on other sites
Barand, as always you're a great help. Thank you.

Quick question on that. Is there a specific spot in the script where this code should be inserted/implemented? I'm assuming it would be ahead of the mysql_query since the details of the image(s) needs to be created in order to be inserted.

My form already has an 'image' and 'file' input field. I just haven't done anything in the code to process it. I tried another script I found but once again it's for what would be considered a 'stand alone' file upload script and not code that would be for the use in this profile creation setup i'm working on.

I have two folders set up for the images:

/images/
/images/thumbs/

set both permissions to 777 so no problems there.

This is just a guess, but i'm supposed to ignore the first line of your pseudocode i'm assuming?

An edited version would be like this:

[code]get $newid = mysql_insert_id()
    $fuller = "images/image_$newid.jpg";
    $thumb =  "images/thumbs/thumb_$newid.jpg";
    resize($_FILES['image']['tmp_name'], $fuller, 250);
    resize($_FILES['image']['tmp_name'], $thumb, 80);
    UPDATE members SET image = '$fuller', thumb_image = '$thumb' WHERE memberid = $newid[/code]

Share this post


Link to post
Share on other sites
I'd recommend including the id of the member in the file name for the images so that if they subsequently upload a new image you can overwrite the old. You are not then left with a shed-load of unattached images.

But to do this you need to insert the new record to get its id, so you can allocate names for the image files

Share this post


Link to post
Share on other sites
Ok, I agree with what you're describing.

I've inserted this code just behind the data query that inserts all the form contents so the function runs right after the data is processed. This line seems to be an issue as it produces an error no matter where I put it:

[code]UPDATE members SET image = '$fuller', thumb_image = '$thumb' WHERE memberid = $newid;[/code]

Error:

[code]Parse error: parse error, unexpected T_STRING in /home2/wwwxxxx/public_html/addbiz.php on line 40[/code]

Share this post


Link to post
Share on other sites
I did say it was "pseudocode". That code is Mysql, not PHP, so you would need

[code]<?php
mysql_query ("UPDATE members SET image = '$fuller', thumb_image = '$thumb' WHERE memberid = $newid;");
?>[/code]

Share this post


Link to post
Share on other sites
Grrrr... ok, I should've known that and it didn't dawn on me until you mentioned it. I think i'm getting brain dead.

Made that change and (of course) another error appears.

This line:
[code]resize($_FILES['image']['tmp_name'], $fuller, 250);[/code]

Gets this error:
[quote]Fatal error: Call to undefined function: resize() in /home2/wwwxxxx/public_html/addbiz.php on line 38[/quote]

There's two 'resize' functions. I'm a betting man so I'm pretty certain that either/and/or of these would produce the error.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.