Jump to content

Php Noob here need help


Recommended Posts

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>";
}
}
Link to comment
Share on other sites

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:
[code]if (ctr=.$info['IP4'].)
{
print "The available IP is:".$info4['IP4'].;[/code]
Should be:
[code]if (ctr==$info['IP4'])
{
print "The available IP is: ".$info4['IP4'];[/code]
Link to comment
Share on other sites

Your souce is filled with syntax errors. For starters:[list][*]The comparision operator for equality is the double equal "==" not the single equal "="[*]The period is the string concatenation operator, code like [code]<?php if (ctr=.$info['IP4'].) ?>[/code] is completely meaningless. What were you trying to write?[/list]Your code written syntactally correct would look something like this: (whether it's logically correct is another question)
[code]<?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>";
}
?>[/code]

Ken
Link to comment
Share on other sites

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>";
}
}
Link to comment
Share on other sites

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:
[code]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'].;[/code]
To this (again, carefully please) and try again.
[code]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'];[/code]
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.