Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 10th, 2002, 11:11 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Wink Success with EasyPHP!

I have been very successful with EasyPHP and Win.2000 but I'm still having problems. The first problem I corrected by switching text editors. I started with Notepad but it kept sticking a .txt extension on the end and that drove me crazy for a few days. Once I switched and started writing real .php docs I was in-like-Flin. Thanks for everyones help.

Now I am having trouble connecting to mySQLdatabase, although I have no trouble using PHPmyadmin to create tables, databases, etc. I get a parse error with the following code:

first what I'm using... apache 1.3.24.+ , PHP 4.2.0 and mysql (latest)...

Here is the code:

<? PHP
$db = @mysql_connect("localhost", "root", "");
mysql_select_db("myfirstdb",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE booksbd SET booktitle ='$booktitle',author='$author',publisher='$publish er',summery ='$summery',inputby ='$inputby', WHERE id=$id";
} else {
$sql = "INSERT INTO booksbd (booktitle,author,publisher,summery,inputby) VALUES ('$booktitle','$author','$publisher','$summery', '$inputby')";
}

* I wanted to enclose the above code in red, php code, but I don't know how...


I'm so close, can anyone help?
Thanks.
__________________
bow wow!

Reply With Quote
  #2  
Old October 11th, 2002, 12:14 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
whoa! a few big problems, here.

Firstly im guessing that you used to use 4.0 and have only made the switch reciently to 4.2.

Ok firstly, if your connecting to your database server via phpmyadmin without any hassels, then everything is set up correctly.

Im asuming that you have the right connection details, so lets move on

if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE booksbd SET booktitle ='$booktitle',author='$author',publisher='$publish
er',summery ='$summery',inputby ='$inputby', WHERE id=$id";
} else {
$sql = "INSERT INTO booksbd (booktitle,author,publisher,summery,inputby) VALUES ('$booktitle','$author','$publisher','$summery', '$inputby')";
}

here lies your problem, firstly you want to insert or update data into the database, currently all your doing is setting a value of a $VARIABLE. you actually need to query the database like this

PHP Code:
if ($submit) { 
// here if no ID then adding else we're editing 
if ($id) { 
$sql "UPDATE booksbd SET booktitle ='$booktitle',author='$author',publisher='$publish  
er',summery ='$summery',inputby ='$inputby', WHERE id=$id"

} else { 
$sql "INSERT INTO booksbd (booktitle,author,publisher,summery,inputby) VALUES ('$booktitle','$author','$publisher','$summery', '$inputby')"


mysql_query($sql);



next im asuming that this page is loaded after you hit the submit button, in which case, it wont get past the

if ($submit) {

line.

4.2.x uses superarray globals, so basically this means, that you cant call a post $variable as $submit.

you will need to do it like this

PHP Code:
if (isset($_POST['submit'])) { 
// here if no ID then adding else we're editing 
if ($_POST['id']) { 
$sql "UPDATE booksbd SET booktitle ='$booktitle',author='$author',publisher='$publish  
er',summery ='$summery',inputby ='$inputby', WHERE id=$id"

} else { 
$sql "INSERT INTO booksbd (booktitle,author,publisher,summery,inputby) VALUES ('$booktitle','$author','$publisher','$summery', '$inputby')"


mysql_query($sql);



next problem

your queries are calling $var, from POST variables

you will also need to use $_POST

but you will need to place them in curly brackets {} since your setting them in a variable

an example

$sql = "SELECT * FROM books WHERE field = {$_POST['id']}";

something like that


PHP Code:
if (isset($_POST['submit'])) { 
// here if no ID then adding else we're editing 
if ($_POST['id']) { 
$sql "UPDATE booksbd SET booktitle = '{$_POST['booktitle']}',
author='{$_POST['author']}',
publisher='{$_POST['publisher']}',
summery ='{$_POST['summery']}',
inputby ='{$_POST['inputby']}',
 WHERE id='{$_POST['id']}'"


else 

$sql "INSERT INTO booksbd (booktitle,author,publisher,
summery,inputby) VALUES 
('{$_POST['booktitle']}',
'{$_POST['author']}',
'{$_POST['publisher']}',
'{$_POST['summery']}', 
'{$_POST['inputby']}')"



mysql_query($sql);


Reply With Quote
  #3  
Old October 11th, 2002, 03:40 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Wow, I've much to learn!

Thanks, I'll get to the changes. I'll post another reply once these are in place and I test it again! Thanks again.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Success with EasyPHP!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT