Jump to content


Photo

Starting Big Project or How To Learn PHP In A Hurry


  • Please log in to reply
71 replies to this topic

#21 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 20 August 2006 - 03:58 PM

Hi AndyB. Can you give me a quick snippet as an example of what you mean? I understand it logically but i'm the visual type if you know what I  mean. You're right on with the problem. You can tell I put it together with a 'logical' approach but not proper syntax. That's what i'm looking to learn. :)

#22 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 20 August 2006 - 04:40 PM

Ok, this is an update. I went to PHP.net and reviewed the 'extract' info then added this line:

extract(mysql_fetch_array($result,EXTR_SKIP));

Now it displays the results utilizing the variables I had in place in the HTML ( $name, $title, etc.)

Only problem is it's repeating the first entry in the database instead of one display for each entry. There's two entries in the db.

I set up a simple query to display the content of the database: http://www.plateaupr...om/testdata.php

Those are the two entries. Here's the output of the full display after inserting the 'extract()' function: http://www.plateaupr...com/display.php

The 'while' loop is still in there as so:
while ($row = mysql_fetch_array($result)) {
echo <<<HTML

Not sure why it's not extracting both entries. Ideas?

#23 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 August 2006 - 04:51 PM

while ($row = mysql_fetch_array($result)) {
echo <<<HTML

to

while ($row = mysql_fetch_assoc($result)) {
echo <<<HTML

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#24 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 20 August 2006 - 05:00 PM

I gave you an example in of how to do this in reply #12 in this thread.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#25 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 20 August 2006 - 05:16 PM

Barand, I thought that code was for displaying the 'summary' page from a particular category. Maybe I misunderstood that. I've snagged that bit of code to work as a model for the summary pages.

What i'm trying to figure out right now is how to get all entries of the database to display in the HTML format i've layed out in the url I provided (display.php). Or is this the same method you implied in reply #12?

redarrow, I made that change but the display still shows the same entry twice instead of the two separate entries.

#26 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 20 August 2006 - 05:22 PM

Query is different but method remains the same
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#27 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 20 August 2006 - 06:27 PM

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

#28 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 12:06 AM

WHY is this mysql code giving me this error message?  ???

<?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!";
} 
?>

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


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.

#29 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 22 August 2006 - 12:17 AM

catid INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(cat_id),

catid and cat_id - there's your problem
follow me on twitter @PHPsycho

#30 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 12:21 AM

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.

<?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!";
} 
?>

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.

<?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());


#31 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 02:08 AM

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:

<?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!";
} 

 ?>


#32 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 August 2006 - 06:25 AM

You have missed the closing ")" after varchar(100)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#33 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 06:38 AM

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.

#34 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 August 2006 - 06:42 AM

// 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 you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#35 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 07:44 PM

I'm getting this error message on this bit of code that's based on the reply #12:

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


<?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());


#36 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 August 2006 - 07:53 PM

change

WHERE mc,catid = '$cat'";

to

WHERE mc.catid = '$cat'";
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#37 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 08:14 PM

Ok, that took care of that one. Next in line after fixing that is:

Unknown column 'mc.memberid' in 'on clause'


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.

#38 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 August 2006 - 08:17 PM

It's saying there isn't a memberid column in the member_cat table
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#39 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 22 August 2006 - 09:36 PM

Ok, that's all figured out. But this error is happening now:

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


Here's my 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);


#40 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 August 2006 - 09:58 PM

Because there is no such function as mysql_unsert_id(). Its mysql_insert_id().




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users