[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 07-04-2005, 10:17 AM   #1 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


Php Error *NP for whoever fixes it*

Hey everyone, i am trying to fix my "edit" page and i cannot seem to get it. Whoever can help me with my error and fix it will receive some np$
Heres the error:

Parse error: parse error, unexpected T_STRING in /home/john/public_html/vicious/tutorials/edit.php on line 19

Here is line 19:

mysql_query("UPDATE tutorials SET title='".$_POST['title'].", preview=".$_POST['preview']." description=".$_POST['description'].", tutorial=".$_POST['tutorial'].", author=".$_POST['author']." WHERE tutorial=".$_REQUEST['tut'].");

all the database stuff is correct (table, variables etc) so dont even post about that. Whoever can help me with my error and fix it will receive some np$
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D

Last edited by Mike_Wiseman; 07-04-2005 at 10:20 AM. Reason: adding stuff
Mike_Wiseman is offline  
Old 07-04-2005, 10:35 AM   #2 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Keep the NP...anyway,

I see it would be much easier if you predefine the $_POST strings. because I see many quotes, and this is probably where the problem resides.

Try this code:

$title = $_POST['title'];
$preview = $_POST['preview'];
$description = $_POST['description'];
$tutorial = $_POST['tutorial'];
$author = $_POST['author'];
$tut = $_REQUEST['tut'];

// Now enter your SQL query if you wish..

$update_data = mysql_query("UPDATE tutorials SET title='$title', preview='$preview', description='$description', tutorial='$tutorial', author='$author' WHERE tutorial='$tut');
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 10:46 AM   #3 (permalink)
NamePros Member
 
ndelong's Avatar
 
Join Date: Jun 2005
Posts: 37
36.00 NP$ (Donate)

ndelong is an unknown quantity at this point


I agree with Mike, except that you forgot to add a terminal quote at the end of the SQL statement. Should be:

$update_data = mysql_query("UPDATE tutorials SET title='$title', preview='$preview', description='$description', tutorial='$tutorial', author='$author' WHERE tutorial='$tut' ");

Perl/PHP are terrible at dealing with nested quotes. An alternative to the method descibed by Mike is to put a '/' before each nested quotation mark, but I think the above way is better. Good luck!
__________________
:music:
Visit me at AdNom.com
CreditMint.com - free credit reports, card offers and resources!
ndelong is offline  
Old 07-04-2005, 10:53 AM   #4 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Ya my mistake..sorry
Thanks for the quick correction
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 10:59 AM   #5 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


Ok thanks, that fixed that problem, but now there is another one. :'(
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 11:04 AM   #6 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Please paste it so that we can help you.
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 11:06 AM   #7 (permalink)
Senior Member
 
Kodeking's Avatar
 
Join Date: Jun 2003
Location: Naperville Illinois
Posts: 1,803
658.75 NP$ (Donate)

Kodeking is just really niceKodeking is just really niceKodeking is just really niceKodeking is just really nice


Make sure that there is a semi-colon at the end of the previous line.
__________________
Quote:
Clan-Forums.com >> $30 BoardingForum.com >> $100
TalkWebHosting.com >> $200 AvoidChapter13.com >> $100
Send PM to make lesser offers on the above names.
Kodeking is offline  
Old 07-04-2005, 11:07 AM   #8 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


i dont really know the error, im a php n00b and a member on this forum made it for me, i played around with it and i guess i screwed it up.

Heres the code:

<?php

if( isset( $_REQUEST['tut'] ) ){
$tut = $_REQUEST['tut'];
// set your database infomation.
include("config.php");

// connect to the mysql database server.
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass);

// select the database
mysql_select_db($dbname, $connect);
$result = mysql_query("SELECT * FROM tutorials WHERE tutorial='$tut'");

// Retrieve all the data from the "tutorials" table
if(mysql_query("SELECT * FROM tutorials WHERE product='$tut'")){
if( isset($_POST['title']) && isset($_POST['preview']) && isset($_POST['description']) && isset($_POST['tutorial']) && isset($_POST['author'])){
$update_data = mysql_query("UPDATE tutorials SET title='$title', preview='$preview', description='$description', tutorial='$tutorial', author='$author' WHERE tutorial='$tut' ");
echo "Updated record!";
}
else{
$row = mysql_fetch_array( $result )
?>
<form method="post" action="edit.php?tut=<?php echo $_REQUEST['tut']; ?>">
Title: <input name="title" value="<?php echo $row['title']; ?>"><br>
Preview: <input name="preview" value="<?php echo $row['preview']; ?>"><br>
Description: <textarea name="description"><?php echo $row['description']; ?></textarea><br />
Tutorial: <textarea name="tutorial"><?php echo $row['tutorial']; ?></textarea><br />
Author: <input name="author" value="<?php echo $row['author']; ?>">
<input type="submit" value="Save" name="submit">
</form>
<?php
}
}
else
{
echo "Error";
}
}
else{
header("Location: tutorials.php");
}


?>


I dont know what there error is because it uses if/els and it just sais error so i dont know whats wrong
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 11:19 AM   #9 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Before checking deeply into use of if/else, you sure that you have field product, at first glance you use tutorial='$tut' then product='$tut' am I missing somethig?

mysql_query("SELECT * FROM tutorials WHERE product='$tut'")){
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 11:32 AM   #10 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


Ok, i change all the product= and tutorial= to title= and it works, but not i think there is something wrong with the $row = mysql_fetch_array( $result ) because when you click edit it is soposed to display the content that you have to edit in the input forms, but for some reason they arnt showing up.
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 11:41 AM   #11 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Are you sure that you added ' ; ' to the statement?

$result = somequeryhere;
$row = mysql_fetch_array($result);
extract($row); // this is recommended ..you'll just use $title instead of $row['title'] however if you do not wish, it shouldnt stop your code from working
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 11:48 AM   #12 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


where or how do i place the extractrow into the code?

$row = mysql_fetch_array( $result );
extract($row);
?>
<form method="post" action="edit.php?tut=<?php echo $_REQUEST['tut']; ?>">
Title: <input name="title" value="<?php echo $title; ?>"><br>
Preview: <input name="preview" value="<?php echo $preview; ?>"><br>
Description: <textarea name="description"><?php echo $description; ?></textarea><br />
Tutorial: <textarea name="tutorial"><?php echo $'tutorial; ?></textarea><br />
Author: <input name="author" value="<?php echo $author; ?>"><BR />
<input type="submit" value="Save" name="submit">
</form>

^ Would that work?
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 12:06 PM   #13 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Yea, it should. but I see a few errors in code

"><?php echo $'tutorial; ?></ $ and tutorial , remove the '
And try to remove the space here mysql_fetch_array($result); only

extract($row) is usually under the $row = mysql_fetch_array()
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 12:13 PM   #14 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


Heres another error

Warning: extract(): First argument should be an array in /home/john/public_html/vicious/tutorials/edit.php on line 23

here is line 23:

extract($row);
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 12:21 PM   #15 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Revise the $row please.. tell me what it has $row = ??
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 07-04-2005, 12:27 PM   #16 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


what do you mean? like the mysql rows? tables? like i said before, im a php n00b

$row = mysql_fetch_array($result); ?

rows:

title
preview
description
tutorial
author
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 12:32 PM   #17 (permalink)
Pro Coder & Designer
 
xlusive's Avatar
 
Join Date: Apr 2005
Location: Netherlands
Posts: 964
101.50 NP$ (Donate)

xlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nice


try this:

Code:
$tutorial = mysql_fetch_array(mysql_query("select * from posts WHERE tut='$tut'"));
if (empty ($tutorial[id])) {
	die("No info !");
}

echo $tutorial[title];
echo $tutorial[preview];
echo $tutorial[description];

etc...
__________________
Online Dragonball Game
xlusive is offline  
Old 07-04-2005, 12:41 PM   #18 (permalink)
Senior Member
 
Join Date: Jun 2004
Location: Ontario , Canada
Posts: 1,155
58.75 NP$ (Donate)

Mike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the roughMike_Wiseman is a jewel in the rough


that didnt work, just created another error :'(
__________________
"Dont argue with an idiot, he will just drag you down to his level and beat you with expeirence. Dont argue with me, ill drag you down to my level and beat you with a baseball bat"
:D
Mike_Wiseman is offline  
Old 07-04-2005, 12:51 PM   #19 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


Mike, send to me the whole file to ezzat @ safe-mail.net and mention your table field names in database, i 'll get working onto this.

Ok received.. and err..it was a bit complicated, do not worry I tested everything on localhost.

Well, basically, what you want it one file , edit.php which called the tutorial ID as i understand, and allow doing changes. It can submit info to itself, and if no form is submitted at first glance, it will just show the form.

Lets get this clear, you should have a file called
config.php contains database variables as regular;

you should also have a file called
form.html contains your html form as below exactly:

Quote:
<form method="post" action="edit.php?tut=<?php echo $tut; ?>">
Title: <input name="title" value="<?php echo $title; ?>"><br>
Preview: <input name="preview" value="<?php echo $preview; ?>"><br>
Description: <textarea name="description"><?php echo
$description; ?></textarea><br />
Tutorial: <textarea name="tutorial"><?php echo $tutorial;
?></textarea><br />
Author: <input name="author" value="<?php echo $author; ?>"><BR />
<input type="submit" value="Save" name="submit">
</form>
at last you should have this only in your edit.php file:

Quote:
<?php

if (isset($_REQUEST['tut'])) {
$tut = $_REQUEST['tut'];
}

// set your database infomation
include 'config.php';

// connect to the mysql database server
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass);

// select the database
mysql_select_db($dbname, $connect) or die(mysql_error());

// sql query
$result = mysql_query("SELECT * FROM tutorials WHERE id='$tut'");
$row = mysql_fetch_array($result);
extract($row);

// define POST
$title = $_POST['title'];
$preview = $_POST['preview'];
$description = $_POST['description'];
$tutorial = $_POST['tutorial'];
$author = $_POST['author'];

if (isset($title) && isset($preview) && isset($description) && isset($tutorial) && isset($author)) {
$update_data = mysql_query("UPDATE tutorials SET title='$title',
preview='$preview', description='$description', tutorial='$tutorial',
author='$author' WHERE id='$tut'");
echo "Updated record!";
include 'form.html';
} else {
include 'form.html';
}
?>
Set these up together in one directory and test. But wait,

I recognized a new field ID in table tutorials, it should get the id number from url and get the info according to ID not tutorial, and that was a little mistake.

Just go to your table structure make sure you have the following structure

field 1 - id int(25) PRIMARY KEY--important--
field 2 - title Whatever varchar or text you like, this is your choice
field 3 - preview
field 4 - description
field 5 - tutorial
field 6 - author

Remember id is a new field. ID is primary key, ID is integer. id is assigned $_GET['tut'] meaning If you called edit.php?tut=12 it would find that
$tut = $_REQUEST['tut'] // value in this case 12;
Then run the statement where tutorial ID is 12

Hope that cleared it up
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design

Last edited by Designporte; 07-04-2005 at 01:46 PM.
Porte is offline  
Old 07-05-2005, 07:06 AM   #20 (permalink)
NamePros Member
 
ndelong's Avatar
 
Join Date: Jun 2005
Posts: 37
36.00 NP$ (Donate)

ndelong is an unknown quantity at this point


Obviously, something os getting mexied up with the table field names...
__________________
:music:
Visit me at AdNom.com
CreditMint.com - free credit reports, card offers and resources!
ndelong is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Beware of PHP! PolurNET The Break Room 25 03-29-2005 03:04 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:21 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85