mysql query question

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
252
Points
63
<?php
session_start();
ob_start();
function Submit(){
$server = ***;
$user = ***;
$password = ***;
$database = ***;
$mysqlconnection = mysql_connect($server, $user, $password);
$databaseconnection = mysql_select_db($database);

if (!$databaseconnection) {
header("Location:index.php?page=Result&error=".urlencode("Failed to Connect to Login Database"));
exit;
}
$querystring = "INSERT INTO `garrettr_Main`.`Comments` (`COM_ID` ,`AUTH_ID` ,`POST_ID` ,`DATE` ,`COMM_TITLE` ,`COMMENT` ,`ENABLED` ,`DELETED`) VALUES (NULL , '";
if(isset($_SESSION[username])){
$result0 = mysql_query("SELECT USERID FROM Logins WHERE USER_NAME='".$_SESSION[username]."'");
$row = mysql_fetch_array($result0);
$querystring .= $row[0]."', '";
}
else{
$querystring .= "0', '";
}
$querystring .= $_POST['post']."', '";

$querystring .= date('YmdHis',time())."', '";

if(isset($_POST['title'])){
$querystring .= $_POST['title']."', '";
}
else{
header("Location:index.php?page=Result&error=".urlencode("Comment Title Not Set"));
exit;
}

if(isset($_POST['comment'])){
$querystring .= $_POST['title']."', '";
}
else{
header("Location:index.php?page=Result&error=".urlencode("Comment Not Set"));
exit;
}

if(isset($_SESSION['authenticated'])){
$querystring .= "1', '0');";
}
else{
$querystring .= "0', '0');";
}
$result1 = mysql_query($querystring);

if(!$result1){
header("Location:index.php?page=Result&error=".urlencode("Insert Comment Failed"));
exit;
}
$result2 = mysql_query("UPDATE Posts SET NUM_COMS=NUM_COMS+1 WHERE POSTID='".$_GET['post']."'");

if(!isset($_GET['post'])){
header("Location:index.php?page=Result&error=".urlencode("Post Not Found"));
exit;
}
elseif(!$result2){
header("Location:index.php?page=Result&error=".urlencode("Post Update Failed").$result);
exit;
}
}

submit();
header("Location:index.php?page=Result");
ob_flush();
?>


The bold section above is behaving strangely. The query is not raising any errors. When copying the exact query and running it in PHP MyAdmin, it works without problem. When run in the browser "$result2" is false, so the query has failed. The previous two queries work without a hitch.

My initial thought was that there is a maximum to the number of queries active at once, but I could not find any information on it.

Thanks for the help!

Garrett
 

hopper

Member
Messages
225
Reaction score
0
Points
16
have you tried executing the query in phpmyadmin and seeing the results?
 

hopper

Member
Messages
225
Reaction score
0
Points
16
perhaps your input paramaters are not correct?
or perhaps you are not reading the output correctly?
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
252
Points
63
perhaps your input paramaters are not correct?
or perhaps you are not reading the output correctly?

The query should just increase the value of one specific field in one row by one. The only variable is the $_GET[post] which I have tested and it works correctly.
 

hopper

Member
Messages
225
Reaction score
0
Points
16
here is a query from mine
it decrements all the numbers starting from a given point
$sql = "UPDATE {$_GET['type']} SET id= id - 1 WHERE id > {$_GET['id']}";
mysqli_query($mysqli, $sql) or die('failed');
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
252
Points
63
what is the variable $mysqli ?

also, I've found in my code that mysql_query returns NULL instead of true or false. Why is this behavior possible?
Edit:
**** I am dumb.

When you add a user to MySQL and you use that user to 'UPDATE', make sure that user has 'UPDATE' privileges.
 
Last edited:

hopper

Member
Messages
225
Reaction score
0
Points
16
oh sorry $mysqli was the name i gave the connection string
 
Last edited:

phpasks

New Member
Messages
145
Reaction score
0
Points
0
$result2 = mysql_query("UPDATE Posts SET NUM_COMS=NUM_COMS+1 WHERE POSTID='".$_GET['post']."'");

if(!isset($_GET['post'])){
header("Location:index.php?page=Result&error=".url encode("Post Not Found"));
exit;
}
PHP:
if(!isset($_GET['post'])){
     header("Location:index.php?page=Result&error=".url  encode("Post Not Found"));
         exit;
     }

$result2 = mysql_query("UPDATE Posts SET NUM_COMS=NUM_COMS+1 WHERE POSTID='".$_GET['post']."'");

now try it..

Asif
http://www.phpasks.com
 
Top