Jump to content

Error: Query was empty HELP


lJesterl

Recommended Posts

here is the code im using

<?php
$con = mysql_connect("localhost","dnuname","dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("dbname", $con);
mysql_query("UPDATE debrackets SET
    tid='$_POST[tid]'
    WHERE tid='$tid'");
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "<center><br><br><br>";
echo "<font color=white>Brackets Where Updated<br>"
mysql_close($con)
?>

Its not going into the mysql because the table is empty. What i want to do is either

A)

INSERT INTO debrackets blah blah

but if it exist

UPDATE debrackets SET blah blah

or

B) UPDATE debrackets SET blah blah

but if it doesnt exisit

INSERT INTO debrackets blah blah



Any Ideas?
Link to comment
https://forums.phpfreaks.com/topic/27653-error-query-was-empty-help/
Share on other sites

Both your A) and B) options are the same. The logic is simple.

First, run a SELECT query to see if the record already exists, if it does, form an UPDATE statement otherwise form an INSERT.

It seems you have a basic understanding of the functions required so now that you have the logic, it shouldn't be too hard to help yourself.

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.