Barand Posted August 23, 2006 Share Posted August 23, 2006 They certainly will if you haven't written them yet. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-79024 Share on other sites More sharing options...
simcoweb Posted August 23, 2006 Author Share Posted August 23, 2006 Ok, once again i'm lost. So then what do the 'resize' codes refer to? Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-79501 Share on other sites More sharing options...
Barand Posted August 23, 2006 Share Posted August 23, 2006 [quote author=Barand link=topic=104388.msg420358#msg420358 date=1156289919]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[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-79507 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 Ok, back on track with this monster.Update, have been doing some restructuring of the registration form to coordinate with the insertion of data into multiple tables as per your original example from reply #12:[code]<?php$sql = "INSERT INTO member (name, email, etc) VALUES ('$name', '$email', '$etc')";mysql_query($sql);$newid = mysql_unsert_id();$sql = "INSERT INTO members_cat (memberid, categoryid) VALUES ('$newid', '$catid')";mysql_query($sql);?>[/code] I did not use this method previously as I was taking a simpler method in using one table to insert the profiles into and then simply displaying them when summoned. However, I have since come to my senses and realize I need to update the method to something more useful such as what you laid out in this table structure:[quote]category member_cat members specialties ========== =========== ========= ============categoryid --+ id +-- memberid --+ idcategory | memberid >-+ name +-< memberid +-< categoryid title speciality company phone email details image[/quote]Here's the question. I've created this series of queries in the 'new' registration form based on your model but receive this error:[quote]Fatal error: Call to undefined function: mysql_unsert_id() in /home2/wwwxxxx/public_html/register-test.php on line 89[/quote]The code including line 89 is this:[code] // Run query$sql = "INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."'), $eg_objConn1";mysql_query($sql);$newid = mysql_unsert_id(); [b][color=red]<-- LINE 89[/color][/b]$sql2 = "INSERT INTO members_cat (memberid, categoryid) VALUES ('$newid', '$catid')";mysql_query($sql2);$sql3 = "INSERT INTO specialties (memberid, specialties) VALUES ('$newid' 'specialties')";mysql_query($sql3);[/code]I looked up 'UNSERT' and can't find anything on it. Don't know if this is a typo or what. But, it's producing an error like it's 'unknown'. Can you shed some light on this please? Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94804 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 [quote]I looked up 'UNSERT' and can't find anything on it. Don't know if this is a typo or what. But, it's producing an error like it's 'unknown'. Can you shed some light on this please?[/quote]As Thorpe pointed out in reply #39 in this thread, it should be "mysql_insert_id()". A typo on my part I'm afraid. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94808 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 I missed that in reply #39 :( Sorry. But, glad I found out it was a typo so I don't have to search Google for hours looking for 'unsert'. :)Now, as you notice i've changed the query codes a bit by addint $sql2 and $sql3 but now there's nothing being inserted. No errors occur...but nothing gets inserted. Once again i'm scratching my head.Here's the latest snippet. See if you can spot WHY i'm going insane:[code] // Run query$sql = "INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."'), $eg_objConn1";mysql_query($sql);$newid = mysql_insert_id();$sql2 = "INSERT INTO members_cat (`memberid`, `categoryid`) VALUES ('$newid', '$catid')";mysql_query($sql2);$sql3 = "INSERT INTO specialties (`memberid`, `specialties`) VALUES ('$newid' '$specialties')";mysql_query($sql3);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94840 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 add "... or die(mysql_error())" to each of the query calls. egmysql_query($sql) or die(mysql_error());See if any clues given. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94843 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 Ok, that produced this:[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 'Resource id #3' at line 1[/quote]Line 1, of course, is my opening <?php tag. Not sure what this eludes to. Here's the entire block of code:[code]<?php// Turn on magic quotes to prevent SQL injection attacksif(!get_magic_quotes_gpc()) set_magic_quotes_runtime(1); include 'dbconfig.php';// Connect to database$eg_objConn1 = mysql_connect($dbhost, $dbuser, $dbpass);mysql_select_db($dbname, $eg_objConn1);// Enable sessionssession_start();// Set Session Value$_SESSION['loggedin'] = @$_POST['username'];$username =$_POST['username'];// Validate users inputif(!empty($_POST)) // Check email is a valid email address if(isset($_POST['email'])) if(!ereg("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,}|[0-9]{1,})(\\]?)$", $_POST['email'])) $eg_error['email'] = "You must enter a valid email address!"; // Check password has a value if(empty($_POST['password'])) $eg_error['password'] = "You must enter a password!"; // Check that confirmPass is the same as (comparison) if(isset($_POST['confirmPass'])) if($_POST['confirmPass'] != @$_POST['password']) $eg_error['confirmPass'] = "Your passwords do not match!"; // Check that username is numbers and letters if(isset($_POST['username'])) if(ereg("[!\"£\$%\^&\*()\+=\{}[.].][.[.]#~';:@/\.,<>\?\\| ]", $_POST['username'])) $eg_error['username'] = "The user name contains some illegal charactures, only use alpha-numeric charactures."; // Check username has a value if(empty($_POST['username'])) $eg_error['username'] = "You must enter a user name!"; // Check if any errors were returned and run relevant code if(empty($eg_error)) { //check if username already exists $sql_user_check = "SELECT * FROM plateau_pros WHERE username='$username'"; $result_name_check = mysql_query($sql_user_check); $usersfound = mysql_num_rows($result_name_check); mysql_query($sql_user_check); // if user found, note that and endif ($usersfound > 0) { $eg_error['username'] = "Username $username is already in use. Please choose another username to continue."; } else { // Conditional statement//if(!empty($_POST)) // Upload File $eg_success_File1 = false; if(!empty($_FILES['photo']['name'])) { // Check file is not larger than specified maximum size $eg_allowUpload = $_FILES['photo']['size'] <= 100000 ? true : false; // Check file is of the specified type if($eg_allowUpload) $eg_allowUpload = preg_match('/\\.(gif|jpg|jpeg|png)$/i', $_FILES['photo']['name']) ? true : false; if($eg_allowUpload) { if(is_uploaded_file($_FILES['photo']['tmp_name'])) { $eg_uploaddir = $_SERVER['DOCUMENT_ROOT']."/images/photo/"; $eg_uploadFile1 = $eg_uploaddir.rawurlencode($_FILES['photo']['name']); // Create a unique filename for the uploaded file $eg_i = 1; while (file_exists($eg_uploadFile1)) { $eg_separated_filename = explode(".",$eg_uploadFile1); if (substr($eg_separated_filename[0],-1) == $eg_i) { $eg_separated_filename[0] = substr($eg_separated_filename[0], 0, (strlen($eg_separated_filename[0])-1)); $eg_i++; } $eg_separated_filename[0] = $eg_separated_filename[0] . "$eg_i"; $eg_uploadFile1 = implode(".",$eg_separated_filename); } $eg_success_File1 = move_uploaded_file($_FILES['photo']['tmp_name'], $eg_uploadFile1); } } } // Run query$sql = "INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."'), $eg_objConn1";mysql_query($sql) or die(mysql_error());$newid = mysql_insert_id();$sql2 = "INSERT INTO members_cat (`memberid`, `categoryid`) VALUES ('$newid', '$catid')";mysql_query($sql2) or die(mysql_error());$sql3 = "INSERT INTO specialties (`memberid`, `specialties`) VALUES ('$newid' '$specialties')";mysql_query($sql3) or die(mysql_error());// set session ID and redirect to login page upon success// Set Session Value $_SESSION['loggedin'] = @$_POST['username']; // Go to page header("Location: login.php"); exit;}}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94847 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 It is referring to line 1 of the SQL query string. As its all on one line it's not too meaningful.I suspect it prob the first of the queries. in addition to showing mysql_error() alsoecho $sql; Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94856 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 If it's a resource id, it means it' snot returning any information.check to make sure your table names match your query, as well as your fields. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94858 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 @Businessman,It means that somewhere in the SQL code being executed, the string 'Resource id #3' is appearing Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94861 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 Ok, here's the 'original' query code before I modified it to do the multiple queries. Perhaps there's an out of place " or , or ' or ) that my editor just isn't spotting. The only changes made were to the beginning of the query code to remove the ( ahead of the "INSERT and then removed the corresponding ) from the end of the query string. Then set up the variable $sql = My hunch is even though my PHP editor shows the proper color coding for the various elements that something is out of alignment.Here's the original:[code] // Run querymysql_query("INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."')", $eg_objConn1);[/code]Here's the revised:[code] // Run query$sql = "INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."'), $eg_objConn1";mysql_query($sql) or die(mysql_error());$newid = mysql_insert_id();[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94866 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 By looking at the query I would say you are going about it the wrong way, and it's severely insecure. Take each varaible, and pass them into a smaller variable, and pass those to the query like$username = mysql_real_escape_string($_POST['username']);$password = mysql_real_escape_string($_POST['password']);ex cetera on all of those, then build a simpler query to help you find the problem.Like$sql = "INSERT INTO plateau_pros (username, password, confirmpass, firstname, lastname, email, business, title, address, city, zip, phone, fax, mobile, category, comments, specialties, photo) VALUES ('$username', '$password', '$confirmpass'and so on, and so forth, if you get resource id area, create a debug script(wildteen taught me that)like$debug = "/nDEBUG INFORMATION:echo Contents of user: {$username}echo Contents of Password: {$password}";and so forth, then whenever you need to debug, call that variable, and it'll tell you all the contents, of all the variables, you can hunt down the problem that way.$sql = "INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('".@$_POST['username']."', '".@$_POST['password']."', '".@$_POST['confirmPass']."', '".@$_POST['firstname']."', '".@$_POST['lastname']."', '".@$_POST['email']."', '".@$_POST['business']."', '".@$_POST['title']."', '".@$_POST['address']."', '".@$_POST['city']."', '".@$_POST['zip']."', '".@$_POST['phone']."', '".@$_POST['fax']."', '".@$_POST['mobile']."', '".@$_POST['category']."', '".@$_POST['comments']."', '".@$_POST['specialties']."', '".substr(strrchr($eg_uploadFile1, "/"), 1)."'), $eg_objConn1";mysql_query($sql) or die(mysql_error());$newid = 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/3/#findComment-94873 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 actually what I Found on google, it returns that id resource, in order to get the information you have to run mysql_fetch_array() to it, after the query that was just something I read on google somewhere just now though Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94877 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 If you look at the end of the $sql string, you left in the "$eg_objConn1" which is giving the error.I was going to give you this lecture later, but Businessman is right, you shouldn't put anything into a query that originates from the user (GET, POST, COOKIE) without checking it first.I usually use a "clean()" function[code]<?phpfunction clean($data) { $data = strip_tags($data); $data = get_magic_quotes_gpc() ? $data : addslashes($data); return $data;}foreach ($_POST as $k => $v) { $$k = clean($v);}?>[/code]So if I have $_POST['xxx'] and $_POST['yyy'] it gives me 2 variables $xxx, $yyy which can be used in my queries. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94892 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 Ok, I cleared out all the $_POST references in the query and got it down to the nuts and bolts. Here's a new development. As an experiment I commented out the $sql2 and $sql3 queries to see if I could isolate the problem. The first query ran fine and inserted the data properly. I uncommented the $sql2 query and it ran fine. When I did the same for $sql3 it produced some weird behaviour. For example. the image upload field should be populated with the name of the image. When the $sql3 is active the temp name/location is stored in that field instead of the image name. Something is amiss with the 3rd query.Also, it was creating an error something like 'Number of columns doesn't match line 1' or similar. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94914 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 If you get the "Number of columns doesn't match error" it because you have query likeINSERT INTO tablename (a, b, c) VALUES ('$a', '$b')orINSERT INTO tablename (a, b, c) VALUES ('$a', '$b', '$c', '$d')orINSERT INTO tablename VALUES ('$a', '$b') and you don't provide a value for each column in the table Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94929 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 That's interesting considering that query number $sql3 wants to insert two items into the 'specialties' table, the $newid and $specialties info. That table has 3 items including the auto-incremented 'id' field. They areidmemberidspecialtiesI don't see where it's any different than the $sql2 query which is inserting two items into the 'members_cat' table which contains:idmemberidcategoryid Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94938 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 What do you get when you echo $sql (the first query) Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94940 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 I get this:[code]INSERT INTO `plateau_pros`(`username`, `password`, `confirmPass`, `firstname`, `lastname`, `email`, `business`, `title`, `address`, `city`, `zip`, `phone`, `fax`, `mobile`, `category`, `comments`, `specialties`, `photo`) VALUES('yosemite', 'park', 'park', 'yosemite', 'sam', '[email protected]', 'WhoopAss', 'Come Get Some', 'here', 'there', '42342', '305-223-6900', '333-333-3333', '333-333-3333', 'Professional Services', 'butt kickin', 'yeehaws', '6620.jpg')Warning: Cannot modify header information - headers already sent by (output started at /home2/wwwplat/public_html/register-test2.php:91) in /home2/wwwplat/public_html/register-test2.php on line 103[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94945 Share on other sites More sharing options...
Barand Posted September 19, 2006 Share Posted September 19, 2006 OK there, 18 columns, 18 values. sql2 and sql3 also have matching cols/valuesAre you sure the error message isn't coming from another query somewhere in the page? Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94948 Share on other sites More sharing options...
simcoweb Posted September 19, 2006 Author Share Posted September 19, 2006 I can't say 100% sure but I do know that if I comment out $sql3 and run the script that I get no errors and the data inserts perfectly. If I un-comment it I get the error message and the data inserted from the first two queries gets goofy as I mentioned previously that the image name doesn't show in the 'photo' field. Instead it displays the 'tmp/blahblah' info. Now, that's an element of the file upload process above the query. That doesn't break unless I activate $sql3. This is a real stumper. I need to insert that data into the right table to make it all join together. Quote Link to comment https://forums.phpfreaks.com/topic/17657-starting-big-project-or-how-to-learn-php-in-a-hurry/page/3/#findComment-94953 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.