Jump to content

Empty Query?


elite_prodigy

Recommended Posts

Why is navId comming out blank?

 

 

<?php

include 'config.php';
include 'functions.php';

mysql_select_db('exembar_site');

if( isset($_POST['title']) & isset($_POST['display']) & isset($_POST['topbar']) & isset($_POST['content'])) {
$title = $_POST['title'];
$display = $_POST['display'];
$top = $_POST['topbar'];
$content = $_POST['content'];

//sanitize everything
$title = sanitize($title);
$display = sanitize($display);
$top = sanitize($top);
$content = sanitize($content);

$sql = "INSERT INTO `navigation` VALUES('','{$display}','')";
mysql_query($sql) or die(mysql_error());

$sql = "SELECT * FROM `navigation` WHERE `display`='{$display}'";
$res = mysql_query($sql) or die(mysql_error());
$stuff = mysql_fetch_array($res) or die(mysql_error());

$navId = $stuff['id'];
echo $navID;

$sql = "INSERT INTO `pages` VALUES('','{$title}','{$navID}')";
mysql_query($sql) or die(mysql_error());

$sql = "INSERT INTO `pgContent` VALUES('','{$top}','{$content}','{$navID}')";
mysql_query($sql) or die(mysql_error());

//header("location:{$root}");

}
else {

echo "Variables Were Not Defined!";

}

?>

 

I don't know what to try, as i've tried it all....

Link to comment
Share on other sites

I am not an expert on this stuff by any means and I may be wrong here, but this don't look right to me..

 

$sql = "INSERT INTO `navigation` VALUES('','{$display}','')";

 

To the best of my knowledge, an insert statement should look like this..

 

$sql = INSERT INTO tableName (fieldName1, fieldName2, fieldName3) VALUES ('$value1', '$value2', '$value3');

 

Thats what I can see offhand... but like I said I could be wrong about the structure of your query.

 

Nate

 

Link to comment
Share on other sites

I am not an expert on this stuff by any means and I may be wrong here, but this don't look right to me..

 

$sql = "INSERT INTO `navigation` VALUES('','{$display}','')";

 

To the best of my knowledge, an insert statement should look like this..

 

$sql = INSERT INTO tableName (fieldName1, fieldName2, fieldName3) VALUES ('$value1', '$value2', '$value3');

 

Thats what I can see offhand... but like I said I could be wrong about the structure of your query.

 

Nate

 

 

You don't have to specify columns in an insert statement. It will insert the data in the order the columns are stored in the table hence the '' (blanks) in the values.

However as a best practice I would always state the columns.

 

However I've never used { } around my values. So not sure if this is correct.

Link to comment
Share on other sites

I am not an expert on this stuff by any means and I may be wrong here, but this don't look right to me..

 

$sql = "INSERT INTO `navigation` VALUES('','{$display}','')";

 

To the best of my knowledge, an insert statement should look like this..

 

$sql = INSERT INTO tableName (fieldName1, fieldName2, fieldName3) VALUES ('$value1', '$value2', '$value3');

 

Thats what I can see offhand... but like I said I could be wrong about the structure of your query.

 

Nate

 

 

You don't have to specify columns in an insert statement. It will insert the data in the order the columns are stored in the table hence the '' (blanks) in the values.

However as a best practice I would always state the columns.

 

However I've never used { } around my values. So not sure if this is correct.

 

NEVER use that kind of query structure. What if you decide to add a column later on?

Link to comment
Share on other sites

Did you try the whole $navID vs $navId thing..... that would make a big difference as has been pointed out...

 

I would say try echoing out your query and make sure that the values are filled in like your expecting.

 

When I have issues with a sql statement, I generally will echo them out and try them in phpmyadmin... found a lot of issues that way.

 

Thats the only 2 things I can suggest.

 

Nate

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.