Jump to content

Help with this code


kbllau

Recommended Posts

Hi

I need help with this code to make it works. I am new at PHP.

I want to check if the file number exist at my database before i use it to open a new file. I use input form to fill in my query then send it to this code.

here is the code:

<?php

// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("main") or die(mysql_error());

$id = $_POST['fileno'];

$sql = mysql_query("SELECT fileno FROM master");
//or die('Error: ' . mysql_error());

if ($id==$sql){print " The file number already in use try onther one";
}
else{ print " you can use this file number";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/155338-help-with-this-code/
Share on other sites

Thanks for the help but i Still confused i updated the code

<?php

// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mandoma") or die(mysql_error());

$id = $_POST['fileno'];

$query = "SELECT '$id' FROM master";
$result = mysql_query($query)or die(mysql_error());

$row = mysql_fetch_array($result) or die (mysql_error());

echo $row['fileno'];

if ($id==$row){print " The file number not in use try onther one";
}
else{ print" you can not use this file number";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817290
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.