Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

73 users online



php/mysql command

php/mysql command

Currently viewing this thread: 1 (0 members and 1 guests)


Tooli0

Tooli0

Status: Offline!

checking if something is already in mysql db

im sorry for the stupid title of this thread but...

how would i be do

if (sumthing in mysql table already exists) { showerr(" Data Already Exists");

sorry for the bad language, im a *little* hungover

___________________

everything we do in life echo's in eternity

Last edited by Tooli0, October 31st, 2003 08:14 PM (Edited 1 times)

Tooli0

Tooli0

Status: Offline!

any 1 ? :Cry:

___________________

everything we do in life echo's in eternity

Unini

Unini

overall Funny Guy
Status: Offline!
PHP:

<?php
$id 
'41';
$result mysql_query('select * from tabel where id = ' $id);
if(
$result)
  echo 
'already existst!';
?>

not tested, but should work.
what it does is that it select a row from the database and if something is returned it exists!

___________________

"I find it kinda funny, I find it kinda sad,
The dreams in wich I'm dying are the best i've ever had"

Tooli0

Tooli0

Status: Offline!

not workin :S

PHP:

<?php
 
if (isset($_POST['createbox'])) { $createbox $_POST['createbox']; }
$result $test_sql->query($db,'select * from $db[prefix]_departments WHERE dep_name = ' $createbox0);
if (
$result) { echo "already assigned"; } else { echo "not assigned"; }
?>

could u please correct tha for us :S probably totally wrong :S

___________________

everything we do in life echo's in eternity

damell

damell

Status: Offline!

instead of if $result, do:

PHP:

<?php

while($row mysql_fetch_array($result)) {
  
$count $count 1
}

if(
$count 0) {
//already assigned
} else {
//not assigned
}

?>

___________________

//damell

Tooli0

Tooli0

Status: Offline!

MySQL Returned this error: Unknown column 'test' in 'where clause' Error number: 1054

when i use that

this is the fulll code

PHP:

<?if (isset($_GET['id']) && $_GET['id'] == "c") {
    if (isset(
$_POST['createbox'])) { $createbox $_POST['createbox']; }
    
$result $toolios_sql->query($db,'select * from ' "$db[prefix]_departments" ' WHERE dep_name = ' $createbox0);
    while(
$row mysql_fetch_array($result)) {
      
$count $count 1;
    }
    if(
$count 0) {
    echo 
"already assigned";
    } else {
    echo 
"not assigned";
}
}

?>

___________________

everything we do in life echo's in eternity

midsummerstorm

midsummerstorm

28, Male & single, what else do you need to know?
Status: Offline!

First thing, you don't need to actually retrieve the rows to count them. Just use mysql_num_rows($result), and if it is > 0 then that means your select found the data you where asking for.

Now, for the query:

PHP:

<?php

$result 
$toolios_sql->query($db,'select * from ' $db['prefix'].'_departments WHERE dep_name = "' $createbox.'"'0);

?>


This should work. Just keep in mind you have to quote (') or double-quote (") your strings when comparing in your SQL queries. I guess $createbox = "test", right?

___________________

-~-~-~oO··Oo~-~-~-~-
I wish I was a messenger and all the news was good
I wish I was the full moon shining off your camaros hood
...

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0094 seconds.