Barand Posted August 20, 2006 Share Posted August 20, 2006 Query is different but method remains the same Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-77651 Share on other sites More sharing options...
simcoweb Posted August 20, 2006 Author Share Posted August 20, 2006 Ok, thanks for the clarification. I'll work with that until I get stuck. Shouldn't be more than...oh... 10 minutes ;) Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-77678 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 WHY is this mysql code giving me this error message? ???[code]<?phpinclude 'config.php';// Make connect to DB firstmysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname) or die(mysql_error());// need to create the category tablemysql_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. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78355 Share on other sites More sharing options...
ToonMariner Posted August 22, 2006 Share Posted August 22, 2006 catid INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(cat_id),catid and cat_id - there's your problem Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78361 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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]<?phpinclude 'config.php';// Make connect to DB firstmysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname) or die(mysql_error());// need to create the category tablemysql_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 firstmysql_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 rowsmysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78363 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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 firstmysql_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 rowsmysql_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 tablemysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78396 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 You have missed the closing ")" after varchar(100) Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78450 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78456 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 // need to create the category tablemysql_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()); Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78458 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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]<?phpinclude 'config.php';$cat = '1';$img_src = 'images/thumbs/';// Make connect to DB firstmysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78759 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 changeWHERE mc,catid = '$cat'";toWHERE mc.catid = '$cat'"; Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78763 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78772 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 It's saying there isn't a memberid column in the member_cat table Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78775 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78818 Share on other sites More sharing options...
trq Posted August 22, 2006 Share Posted August 22, 2006 Because there is no such function as mysql_unsert_id(). Its mysql_insert_id(). Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78836 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 Sorry about the typos :( Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78848 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78880 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78887 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78900 Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 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 wideThe 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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78911 Share on other sites More sharing options...
simcoweb Posted August 22, 2006 Author Share Posted August 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78915 Share on other sites More sharing options...
Barand Posted August 23, 2006 Share Posted August 23, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78920 Share on other sites More sharing options...
simcoweb Posted August 23, 2006 Author Share Posted August 23, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78927 Share on other sites More sharing options...
Barand Posted August 23, 2006 Share Posted August 23, 2006 I did say it was "pseudocode". That code is Mysql, not PHP, so you would need[code]<?phpmysql_query ("UPDATE members SET image = '$fuller', thumb_image = '$thumb' WHERE memberid = $newid;");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78929 Share on other sites More sharing options...
simcoweb Posted August 23, 2006 Author Share Posted August 23, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/2/#findComment-78934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.