Page 1 of 1

Php newbie pls help me debug my code tnx

Posted: Wed May 24, 2006 7:26 pm
by theoretical_dreamer
I'm having problems with the syntax Please check my code:

Code: Select all

<?
include("conf/config.php");
$link = mysql_connect($database['host'],$database['username'],$database['password']); 
mysql_select_db($database['name'],$link);

$rs4 = mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error()); 
$info4 = (mysql_fetch_array( $rs4 ));
$ctr=31;

if ($ctr != 31) {//if ctr is equal to the 1st value of IP4 field in the database
	Print "<b>The IP is available:</b> ".$info4['IP4']. " <br>";
}

else
{
	Print "<b>IP4:</b> ".$info4['IP4']. " <br>";
	
	while($info4 = mysql_fetch_array( $rs4 ))

	{ 
	$ctr++;
		
		if (ctr==.$info4['IP4'].) //Line 23
		{
			Print $ctr;
		}
		
	Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
	Print $ctr;
	}
}
?>
THe browser returned: Parse error: parse error, unexpected '.' in C:\Program Files\Apache Group\Apache2\htdocs\generate.php on line 23

Burrito: Please use

Code: Select all

and/or

Code: Select all

tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]posting code in the forum[/url].[/size]

Posted: Wed May 24, 2006 7:30 pm
by Burrito
take the dots (.) out of this line:

you'll also need to add a dollar sign because you're comparing a variable.

Code: Select all

if (ctr==.$info4['IP4'].) //Line 23

Posted: Wed May 24, 2006 7:34 pm
by theoretical_dreamer
Thanks bro :D

Posted: Wed May 24, 2006 9:09 pm
by theoretical_dreamer
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Just want to ask y there is no output in the If condition:

Code: Select all

<?
include("conf/config.php");
$link = mysql_connect($database['host'],$database['username'],$database['password']); 
mysql_select_db($database['name'],$link);

$rs4 = mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error()); 
$info4 = (mysql_fetch_array( $rs4 ));
$ctr=31;

if ($ctr != 31) {//if ctr is equal to the 1st value of IP4 field in the database
	Print "<b>The IP is available:</b> ".$info4['IP4']. " <br>";
}

else
{
	//Print "<b>IP4:</b> ".$info4['IP4']. " <br>";
	$ctr++;
	Print "The value of ctr is ";
	Print $ctr; //value of ctr is 32
	while($info4 = mysql_fetch_array( $rs4 ))

	{ 
		$ctr++;
		Print "<br> <b>IP4:</b> ".$info4['IP4']. " <br>";
		Print "The value of ctr is ";
		Print $ctr; 
		
		if ($ctr==$info4['IP4']) 
		{
			print "It is equal "; //Doesn't output at all
			print $ctr;
		}
		
		/*
		else
		{
		 	print "Finally, its not";
			$ctr;
		}
		*/
	}
}
?>
Output:

Code: Select all

The value of ctr is 32
IP4: 32 
The value of ctr is 33
IP4: 33 
The value of ctr is 34
IP4: 34 
The value of ctr is 35
IP4: 35 
The value of ctr is 36

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed May 24, 2006 9:26 pm
by feyd
seriously theoretical_dreamer, start using the syntax highlighting tags to post code.

Try using var_dump() to see what the difference is between the variables.

Posted: Wed May 24, 2006 9:35 pm
by theoretical_dreamer
sorry about the tags, anyway care to elaborate what does <?var_dump() ?> do?

Posted: Wed May 24, 2006 9:39 pm
by theoretical_dreamer
ah ic the 2 variables are of different types one is an int, one is a string how can i convert a string to an int?

Posted: Thu May 25, 2006 3:03 am
by JayBird