Jump to content

Recommended Posts

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 '.135.69' at line 1

 

 

hElp frnds....

 

 

 

my code.....

 

if ($check) {
 
        @fclose($check);
$status="ONLINE";
        $stat="UPDATE servers SET Status=$status WHERE IP=$b";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "Fully Updated";
    }
else {
        $status="OFFLINE";
$stat="UPDATE servers SET Status=$status WHERE IP=$b";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "Fully Updated";
    }
 
 
 
thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/283604-update-ip-in-databse-using-php-variable/
Share on other sites

hey thanks dat problem luks to be solved bt i have another problem at before this code...

i wil show u the entire code...

i m not able to conect the array to variable. i m talkin abt these lines...

 

foreach($values as $server) {

 

 
$b=$server;
 
 
Entire code down.....

 

<?PHP
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $values = mysqli_query($con,"SELECT IP FROM servers");
$result = mysqli_query($con,"SELECT * FROM servers");
 
 
 
 
 
 
if(empty($values))
{
echo"<p>There's nothing in the array.....</p>";
}
else
{
 
foreach($values as $b) {
 
 
$b=$server;
 
  $check = @fsockopen($b, 22);
    if ($check) {
 
        @fclose($check);
$status="ONLINE";
        $stat="UPDATE servers SET Status='$status'WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "Fully Updated";
    }
else {
        $status="OFFLINE";
$stat="UPDATE servers SET Status='$status'WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "Fully Updated";
    }
 
// k the manual that corresponds to your MySQL server version for the right syntax to use near '.135.69' at line 1
}
}
 
echo "<table border='1'>
<tr>
<th>IP</th>
<th>Port</th>
<th>ID</th>
<th>Client Name</th>
<th>Plan</th>
<th>Validity</th>
<th>Status</th>
</tr>";
 
 
while($row = mysqli_fetch_array($result))
  {
    
 echo "<tr>";
  
  echo "<td>" . $row['IP'] . "</td>";
  echo "<td>" . $row['Port'] . "</td>";
 echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['ClientName'] . "</td>"; 
echo "<td>" . $row['Plan'] . "</td>"; 
echo "<td>" . $row['Validity'] . "</td>";
echo "<td>" . $row['Status'] . "</td>";
 
  echo "</tr>";
   
  }
echo "</table>";
 
mysqli_close($con);
 
?>
Edited by udaystrad

mysqli_query does not return any results.

$values = mysqli_query($con,"SELECT IP FROM servers");
$result = mysqli_query($con,"SELECT * FROM servers");

To get the results from the query you use one of the mysqli_fetch_* functions, such as mysqli_fetch_assoc (see Example #2 for how to use this function)

Edited by Ch0cu3r

thank u issue resolved but havin some other problem nw....i dont kno wats goin wrong...

ON every refresh i either get 1/4, half , sometimes full page.... 

n also the servers which is online it shows ofline smetimes....

 

I m uploading the entire page hope u can help.... thanks in advace.....

 

her it goes.....

 

 

<?php session_start(); 
if(!isset($_SESSION['uname']) || !isset($_SESSION['pwd'])){
 header("Location: login.php");
 
 
if(isset($_POST['Submit'])){
$ipno1=trim($_POST["ipno1"]);
$ipno2=trim($_POST["ipno2"]);
$ipno3=trim($_POST["ipno3"]);
$ipno4=trim($_POST["ipno4"]);
$addport=trim($_POST["addport"]);
$addid=trim($_POST["addid"]);
$clientname=trim($_POST["clientname"]);
$plan=trim($_POST["plan"]);
$validity=trim($_POST["validity"]);
 
 
if($ipno1 == "" && $ipno2 == "" && $ipno3 == "" && $ipno4 == "" && $addport == "" && $addid == "" && $clientname == "" && $plan == "" && $validity == "") {
$error= "All Coloumns Blank!!!";
$code= "1" ;
}
 
elseif($ipno1 == "" ) {
$error= "Enter the IP First column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno1)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($ipno2 == "" ) {
$error= "Enter the IP Second column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno2)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($ipno3 == "" ) {
$error= "Enter the IP Third column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno3)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
elseif($ipno4 == "" ) {
$error= "Enter the IP Fourth column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno4)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($addport == "" ) {
$error= "Enter the Port Number.";
$code= "2" ;
}
 
elseif(!is_numeric($addport)) {
$error= "Port Entry should be Numeric!!!";
$code= "2" ;
}
 
elseif($addid == "" ) {
$error= "Enter ID!!!";
$code= "3" ;
}
 
 
elseif(($clientname == "")) {
$error= "Enter client name !!!";
$code= "4" ;
}
 
 
elseif(($plan == "")) {
$error= "Enter client name!!!";
$code= "5" ;
}
 
 
 
elseif(($validity == "")) {
$error= "Enter validity!!!";
$code= "6" ;
}
 
else{
 
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
$a=$ipno1.".".$ipno2.".".$ipno3.".".$ipno4;
 
$sql="INSERT INTO Servers (IP,Port,ID,ClientName,Plan,Validity)
 
VALUES
('$a','$_POST[addport]','$_POST[addid]','$_POST[clientname]','$_POST[plan]','$_POST[validity]')";
if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "1 record added.<br/><a href='server-handling.php'>Refresh</a> ";
mysqli_close($con);
 
}
}
 
 
 
 
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
 // $values = mysqli_query($con,"SELECT IP FROM servers");
$result = mysqli_query($con,"SELECT * FROM servers");
 
$query = "SELECT IP FROM servers";
if ($task = mysqli_query($con, $query)) {
 
 while ($row = mysqli_fetch_assoc($task)) {
 
//$servers = array("183.87.135.65","183.87.135.69","183.87.135.70");
 
if(empty($row))
{
echo"<p>There's nothing in the array.....</p>";
}
else
{
 
foreach($row as $server) {
//print_r($server);
//Array ( [iP] => 183.87.135.69 ) shazim
//Notice: Use of undefined constant IP - assumed 'IP' in C:\xampp\htdocs\sapp\server-handling.php on line 152
//183.87.135.69Error: 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 'SET Status='ONLINE' servers WHERE IP='183.87.135.69'' at line 1
//$sql = "UPDATE testimonials SET name='$name', content='$content' WHERE id=$id";
//    $result = mysql_query($sql);
 //   if ($result === FALSE) {
//        die(mysql_error());
//    }
//}
//echo "shazim";
 
$b=$server;
echo "<br>".$b;
//echo  $b;
  $check = @fsockopen($b, 22);
    if ($check) {
 
        @fclose($check);
$status="ONLINE";
        $stat="UPDATE servers SET Status='$status' WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
 
    }
else {
        $status="OFFLINE";
$stat="UPDATE servers SET Status='$status' WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
 
    }
 
// k the manual that corresponds to your MySQL server version for the right syntax to use near '.135.69' at line 1
}
}
}
}
echo "<table border='1'>
<tr>
<th>IP</th>
<th>Port</th>
<th>ID</th>
<th>Client Name</th>
<th>Plan</th>
<th>Validity</th>
<th>Status</th>
</tr>";
 
 
while($row = mysqli_fetch_array($result))
  {
    
 echo "<tr>";
  
  echo "<td>" . $row['IP'] . "</td>";
  echo "<td>" . $row['Port'] . "</td>";
 echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['ClientName'] . "</td>"; 
echo "<td>" . $row['Plan'] . "</td>"; 
echo "<td>" . $row['Validity'] . "</td>";
echo "<td>" . $row['Status'] . "</td>";
 
  echo "</tr>";
   
  }
echo "</table>";
 
mysqli_close($con);
 
?>
 
 
<html>
   <body>
   <div class="xyz">
<div class="abc" style="float: left">
 
Welcome Sir You have Logged in.
</div>
<div class="xml" style="float:right">
<a href="logout.php">Logout</a>
 
</div>
</div>
   
<div align="left">
   <?php if (isset($error)) { echo "<p class='message'>" .$error. "</p>" ;} ?>
 
<style type="text/css" >
.error{border:1px solid red; }
.message{color: red; font-weight:bold; }
</style>
<center>   
<form action="server-handling.php" method="post">
<table border="1">
 
<tr>
<td>IP: </td>
<td><INPUT type="text" size="1" name="ipno1" maxlength="3" 
value="<?php if(isset($ipno1)){echo $ipno1;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
<INPUT type="text" size="1" name="ipno2" maxlength="3" 
value="<?php if(isset($ipno2)){echo $ipno2;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
<INPUT type="text" size="1" name="ipno3" maxlength="3" 
value="<?php if(isset($ipno3)){echo $ipno3;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
 <INPUT type="text" size="1"name="ipno4" maxlength="3" 
 value="<?php if(isset($ipno4)){echo $ipno4;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
<br>
</td>
 </tr>
 
<tr>
<td>Port:</td> 
<td><input type="text" name="addport" placeholder="Port Number"
value="<?php if(isset($addport)){echo $addport;} ?>" <?php if(isset($code) && $code == 2){echo "class=error" ;} ?> ><br></td>
</tr>
 
<tr>
<td>ID:</td>
<td> <input type="text" name="addid" placeholder="Add id" 
value="<?php if(isset($addid)){echo $addid;} ?>" <?php if(isset($code) && $code == 3){echo "class=error" ;} ?>><br></td>
</tr>
 
 
 
<tr>
<td>Client Name </td>
<td><input type="text" name="clientname"  
value="<?php if(isset($clientname)){echo $clientname;} ?>" <?php if(isset($code) && $code == 4){echo "class=error" ;} ?>><br></td>
 
</tr>
 
<tr>
<td>Plan</td>
<td><input type="text" name="plan" placeholder="plan"
value="<?php if(isset($plan)){echo $plan;} ?>" <?php if(isset($code) && $code == 5){echo "class=error" ;} ?>><br></td>
</tr>
 
 
<tr>
<td>Validity </td>
<td><input type="text" name="validity" placeholder="13th Nov 2011" value="
<?php if(isset($validity)){echo $validity;} ?>" <?php if(isset($code) && $code == 6){echo "class=error" ;} ?>><br> </td>
</tr>
 
 
 
<th colspan="6">
<input type="submit" value="Enter" name="Submit">
</th>
</table>
</form>
</center>
</div
 
 
 
 
 
</body>
</html>

the thread you started after this one has been removed. please stick to ONE thread for a problem.

 

also, please use the forum's


bbcode tags (the edit form's <> button) when posting code. you have over 20 posts on this forum and should know how to do this. this will also increase the chance of someone reading your post and replying to your problem.
 

i m sorry for the trouble....

here's the repeat my code...

 
<?php session_start(); 
if(!isset($_SESSION['uname']) || !isset($_SESSION['pwd'])){
 header("Location: login.php");
 
} 
 
if(isset($_POST['Submit'])){
$ipno1=trim($_POST["ipno1"]);
$ipno2=trim($_POST["ipno2"]);
$ipno3=trim($_POST["ipno3"]);
$ipno4=trim($_POST["ipno4"]);
$addport=trim($_POST["addport"]);
$addid=trim($_POST["addid"]);
$clientname=trim($_POST["clientname"]);
$plan=trim($_POST["plan"]);
$validity=trim($_POST["validity"]);
 
 
if($ipno1 == "" && $ipno2 == "" && $ipno3 == "" && $ipno4 == "" && $addport == "" && $addid == "" && $clientname == "" && $plan == "" && $validity == "") {
$error= "All Coloumns Blank!!!";
$code= "1" ;
}
 
elseif($ipno1 == "" ) {
$error= "Enter the IP First column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno1)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($ipno2 == "" ) {
$error= "Enter the IP Second column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno2)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($ipno3 == "" ) {
$error= "Enter the IP Third column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno3)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
elseif($ipno4 == "" ) {
$error= "Enter the IP Fourth column.";
$code= "1" ;
}
 
elseif(!is_numeric($ipno4)) {
$error= "Entries of IP and Port should be Numeric!!!";
$code= "1" ;
}
 
 
elseif($addport == "" ) {
$error= "Enter the Port Number.";
$code= "2" ;
}
 
elseif(!is_numeric($addport)) {
$error= "Port Entry should be Numeric!!!";
$code= "2" ;
}
 
elseif($addid == "" ) {
$error= "Enter ID!!!";
$code= "3" ;
}
 
 
elseif(($clientname == "")) {
$error= "Enter client name !!!";
$code= "4" ;
}
 
 
elseif(($plan == "")) {
$error= "Enter client name!!!";
$code= "5" ;
}
 
 
 
elseif(($validity == "")) {
$error= "Enter validity!!!";
$code= "6" ;
}
 
else{
 
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
$a=$ipno1.".".$ipno2.".".$ipno3.".".$ipno4;
 
$sql="INSERT INTO Servers (IP,Port,ID,ClientName,Plan,Validity)
 
VALUES
('$a','$_POST[addport]','$_POST[addid]','$_POST[clientname]','$_POST[plan]','$_POST[validity]')";
if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
 
  }
echo "1 record added.<br/><a href='server-handling.php'>Refresh</a> ";
mysqli_close($con);
 
}
}
 
 
 
 
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
 // $values = mysqli_query($con,"SELECT IP FROM servers");
$result = mysqli_query($con,"SELECT * FROM servers");
 
$query = "SELECT IP FROM servers";
if ($task = mysqli_query($con, $query)) {
 
 while ($row = mysqli_fetch_assoc($task)) {
 
//$servers = array("183.87.135.65","183.87.135.69","183.87.135.70");
 
if(empty($row))
{
echo"<p>There's nothing in the array.....</p>";
}
else
{
 
foreach($row as $server) {
//print_r($server);
//Array ( [IP] => 183.87.135.69 ) shazim
//Notice: Use of undefined constant IP - assumed 'IP' in C:\xampp\htdocs\sapp\server-handling.php on line 152
//183.87.135.69Error: 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 'SET Status='ONLINE' servers WHERE IP='183.87.135.69'' at line 1
//$sql = "UPDATE testimonials SET name='$name', content='$content' WHERE id=$id";
//    $result = mysql_query($sql);
 //   if ($result === FALSE) {
//        die(mysql_error());
//    }
//}
//echo "shazim";
 
$b=$server;
echo "<br>".$b;
//echo  $b;
  $check = @fsockopen($b, 22);
    if ($check) {
 
        @fclose($check);
$status="ONLINE";
        $stat="UPDATE servers SET Status='$status' WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
 
    }
else {
        $status="OFFLINE";
$stat="UPDATE servers SET Status='$status' WHERE IP='$b'";
if (!mysqli_query($con,$stat))
  {
  die('Error: ' . mysqli_error($con));
 
  }
 
    }
 
// k the manual that corresponds to your MySQL server version for the right syntax to use near '.135.69' at line 1
}
}
}
}
echo "<table border='1'>
<tr>
<th>IP</th>
<th>Port</th>
<th>ID</th>
<th>Client Name</th>
<th>Plan</th>
<th>Validity</th>
<th>Status</th>
</tr>";
 
 
while($row = mysqli_fetch_array($result))
  {
    
 echo "<tr>";
  
  echo "<td>" . $row['IP'] . "</td>";
  echo "<td>" . $row['Port'] . "</td>";
 echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['ClientName'] . "</td>"; 
echo "<td>" . $row['Plan'] . "</td>"; 
echo "<td>" . $row['Validity'] . "</td>";
echo "<td>" . $row['Status'] . "</td>";
 
  echo "</tr>";
   
  }
echo "</table>";
 
mysqli_close($con);
 
?>
 
 
<html>
   <body>
   <div class="xyz">
<div class="abc" style="float: left">
 
Welcome Sir You have Logged in.
</div>
<div class="xml" style="float:right">
<a href="logout.php">Logout</a>
 
</div>
</div>
   
<div align="left">
   <?php if (isset($error)) { echo "<p class='message'>" .$error. "</p>" ;} ?>
 
<style type="text/css" >
.error{border:1px solid red; }
.message{color: red; font-weight:bold; }
</style>
<center>   
<form action="server-handling.php" method="post">
<table border="1">
 
<tr>
<td>IP: </td>
<td><INPUT type="text" size="1" name="ipno1" maxlength="3" 
value="<?php if(isset($ipno1)){echo $ipno1;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
<INPUT type="text" size="1" name="ipno2" maxlength="3" 
value="<?php if(isset($ipno2)){echo $ipno2;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
<INPUT type="text" size="1" name="ipno3" maxlength="3" 
value="<?php if(isset($ipno3)){echo $ipno3;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
 
 <INPUT type="text" size="1"name="ipno4" maxlength="3" 
 value="<?php if(isset($ipno4)){echo $ipno4;} ?>" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> >
<br>
</td>
 </tr>
 
<tr>
<td>Port:</td> 
<td><input type="text" name="addport" placeholder="Port Number"
value="<?php if(isset($addport)){echo $addport;} ?>" <?php if(isset($code) && $code == 2){echo "class=error" ;} ?> ><br></td>
</tr>
 
<tr>
<td>ID:</td>
<td> <input type="text" name="addid" placeholder="Add id" 
value="<?php if(isset($addid)){echo $addid;} ?>" <?php if(isset($code) && $code == 3){echo "class=error" ;} ?>><br></td>
</tr>
 
 
 
<tr>
<td>Client Name </td>
<td><input type="text" name="clientname"  
value="<?php if(isset($clientname)){echo $clientname;} ?>" <?php if(isset($code) && $code == 4){echo "class=error" ;} ?>><br></td>
 
</tr>
 
<tr>
<td>Plan</td>
<td><input type="text" name="plan" placeholder="plan"
value="<?php if(isset($plan)){echo $plan;} ?>" <?php if(isset($code) && $code == 5){echo "class=error" ;} ?>><br></td>
</tr>
 
 
<tr>
<td>Validity </td>
<td><input type="text" name="validity" placeholder="13th Nov 2011" value="
<?php if(isset($validity)){echo $validity;} ?>" <?php if(isset($code) && $code == 6){echo "class=error" ;} ?>><br> </td>
</tr>
 
 
 
<th colspan="6">
<input type="submit" value="Enter" name="Submit">
</th>
</table>
</form>
</center>
</div
 
 
 
 
 
</body>
</html>
 
 
Edited by udaystrad
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.