Jump to content


Photo

Php Noob here need help


  • Please log in to reply
6 replies to this topic

#1 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 24 May 2006 - 02:01 AM

need help regarding syntax please check my code tnx

$rs4= mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error());
$info4 = (mysql_fetch_array( $rs4 ));
ctr=31;
if (ctr=.$info['IP4'].)
{
print "The available IP is:".$info4['IP4'].;
}
else
{
Print "<b>IP4:</b> ".$info4['IP4']. " <br>";
while($info4 = mysql_fetch_array( $rs4 ))
{

while (ctr==.$info4['IP4'].)
{
ctr++;
if (ctr!=.$info4['IP4'].)
{
print "It works";
}
}

Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
}

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 May 2006 - 02:12 AM

Don't forget to tell us what errors you get and identify the lines in your code. php provides really useful error messages that (with a little practice) lead you to the trouble spots.

Most of your problems stem from mis-use of the . concatenation operator (which is used exclusively for adding strings to make longer strings. Note also the equality check operator is ==. So, for example:
if (ctr=.$info['IP4'].)
{
print "The available IP is:".$info4['IP4'].;
Should be:
if (ctr==$info['IP4'])
{
print "The available IP is: ".$info4['IP4'];

Legend has it that reading the manual never killed anyone.
My site

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 May 2006 - 02:20 AM

Your souce is filled with syntax errors. For starters:
  • The comparision operator for equality is the double equal "==" not the single equal "="
  • The period is the string concatenation operator, code like
    <?php if (ctr=.$info['IP4'].) ?>
    is completely meaningless. What were you trying to write?
Your code written syntactally correct would look something like this: (whether it's logically correct is another question)
<?php
$rs4= mysql_query("SELECT IP4 FROM ipadd ORDER BY IP4")or die(mysql_error());
$ctr=31; // need a $ infront of the variable and since it doesn't change, move it out of the loop
while ($info4 = mysql_fetch_assoc( $rs4 )) { // make this a "while" loop
    if (ctr == $info['IP4'])
       print "The available IP is:".$info4['IP4'];
    else
       print "<b>IP4:</b> ".$info4['IP4']. " <br>";
    while ($ctr == $info4['IP4'])
    {
         $ctr++;
         if ($ctr != $info4['IP4'])
             print "It works";
    }
    Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
?>

Ken

#4 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 24 May 2006 - 02:45 AM

tnx for the rply that really help

#5 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 24 May 2006 - 03:04 AM

guys i did wat u said but it still didn't work here's my edited code

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

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

while($info4 = mysql_fetch_array( $rs4 ))

{

while ($ctr=.$info4['IP4'].)
{
$ctr++;
if ($ctr!=.$info4['IP4'].)
{
print "It works";
}
}

Print "<b>IP4:</b> ".$info4['IP4'] . " <br>";
}
}

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 May 2006 - 03:13 AM

No, No, No. You didn't do what we said. You didn't post what the errors were. You didn't identify which lines the errors occurred at.

Change this:
if ($ctr=.$info['IP4'].) //if ctr is equal to the 1st value of IP4 field in the database
{
print "The available IP is:".$info4['IP4'].;
To this (again, carefully please) and try again.
if ($ctr==$info['IP4']); //if ctr is equal to the 1st value of IP4 field in the database
{
print "The available IP is: ".$info4['IP4'];

Legend has it that reading the manual never killed anyone.
My site

#7 theoretical_dreamer

theoretical_dreamer
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 24 May 2006 - 03:17 AM

oh sorry... i forgot to turned the error report message in apache, thanks bro




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users