Jump to content

syntex error??


puremagnum

Recommended Posts

It would probably be best if you were to post the whole script at this point. Just remove any database passwords, etc.

i was one step ahead of u

<?php
				$subject_set = mysql_query("SELECT * FROM subjects",$connection );
				if(!$subject_set)
				{
				die("DB query failed:" . mysql_error());
				}

				while($subject = mysql_fetch_array($subject_set))
				{
				echo "<li>{$page['menu_name']}</li>";
				}
				$query="SELECT * FROM pages WHERE subject_id = $subject['id']";
					echo $query;
					$page_set=mysql_query($query) or die( "<br>Query string: $query<br>Produced error: " . mysql_error() );
				echo"<ul class=\"pages\">";
				while($page= mysql_fetch_array($page_set))
				{
				echo "<li>{$page["menu_name"]}</li>";
				}
				if(mysql_num_rows($page_set)>0){

}
				echo "</ul>";

				?>

thats what im currently working on

Link to comment
Share on other sites

It would probably be best if you were to post the whole script at this point. Just remove any database passwords, etc.

Still I think you are correct about what the exact problem is though. :P

echo "<li>{$page['menu_name']}</li>";

arrays must have brackets when used in magic quotes.

Link to comment
Share on other sites

You should have done as he said :P

 

<?php
$subject_set = mysql_query('SELECT * FROM subjects',$connection);
if(!$subject_set){
die('DB query failed:' . mysql_error());
}
while($subject = mysql_fetch_array($subject_set)){
echo '<li>'.$page['menu_name'].'</li>';
}
$query='SELECT * FROM pages WHERE subject_id = '.$subject['id'];
echo $query;
$page_set=mysql_query($query) or die( '<br>Query string: '.$query.'<br>Produced error: ' . mysql_error() );
echo '<ul class="pages">';
while($page= mysql_fetch_array($page_set)){
echo '<li>'.$page["menu_name"].'</li>';
}
echo '</ul>';
?>

Link to comment
Share on other sites

thx for the code... inserted it got this when loaded pg

 

Notice: Undefined variable: page in C:\wamp\www\widget_corp\content.php on line 24

#

Notice: Undefined variable: page in C:\wamp\www\widget_corp\content.php on line 24

#

Notice: Undefined variable: page in C:\wamp\www\widget_corp\content.php on line 24

#

SELECT * FROM pages WHERE subject_id =Query string: SELECT * FROM pages WHERE subject_id =

Produced error: 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 1

 

y is this sooo flippen hard if im such a newb!!! lol

Link to comment
Share on other sites

Added curly braces around {$subject['id']}, no more parse errors . . .

 

<?php
$subject_set = mysql_query("SELECT * FROM subjects",$connection );
if(!$subject_set) {
die("DB query failed:" . mysql_error());
}
while($subject = mysql_fetch_array($subject_set)) {
echo "<li>{$page['menu_name']}</li>";
}
$query="SELECT * FROM pages WHERE subject_id = {$subject['id']}";
echo $query;
$page_set=mysql_query($query) or die( "<br>Query string: $query<br>Produced error: " . mysql_error() );
echo"<ul class=\"pages\">";
while($page= mysql_fetch_array($page_set)) {
echo "<li>{$page["menu_name"]}</li>";
}
if(mysql_num_rows($page_set)>0) {
}
echo "</ul>";
?>

Link to comment
Share on other sites

<?php
$subject_set = mysql_query('SELECT * FROM subjects',$connection);
if(!$subject_set){
die('DB query failed:' . mysql_error());
}
while($subject = mysql_fetch_array($subject_set)){
echo '<li>'.$subject['menu_name'].'</li>';
$subjects[]=$subject;
}
$query='SELECT * FROM pages WHERE subject_id = '.$subjects[0]['id'];
echo $query;
$page_set=mysql_query($query) or die( '<br>Query string: '.$query.'<br>Produced error: ' . mysql_error() );
echo '<ul class="pages">';
while($page= mysql_fetch_array($page_set)){
echo '<li>'.$page["menu_name"].'</li>';
}
echo '</ul>';
?>

 

$page was never assigned when you first used it in the first loop!

(all I originally did was to edit your script to not use magic quotes, because they scare me.)

Link to comment
Share on other sites

ok i fixed thanks u guys soooooo much :)...

i h8 this stupid video for this....

should i stop useing the video??. considering its teaching me old syntex??.

old? =P

I think you should keep on using it, but try to mess around with it after you've seen how stuff has been done by others. You learn far more from that.

syntax*

Link to comment
Share on other sites

It isn't necessarily teaching old syntax, but it isn't teaching what most would consider best practices. Unfortunately, anyone can make a video, or write a tutorial and put it on the internet. The people who have the least knowledge of a subject are the ones who suffer the most from shoddy information because they simply don't know the information is bad.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.