Author Topic: problems with post.php submitting mysql query  (Read 1347 times)

0 Members and 1 Guest are viewing this topic.

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
problems with post.php submitting mysql query
« on: September 01, 2010, 08:20:33 AM »
I have a post.php that is suposted to run a mysql query, and it used to, but it won't anymore and I don't have the old file.
Can someone just look see if there is something i'm missing?
<?php //header("Location: ./?p=UCP");
setcookie("Errors"0time()-3600);
// Connects to your Database 
 
mysql_connect("SERVER""USER""PASS") or die(mysql_error()); 
 
mysql_select_db("DB") or die(mysql_error());  


 if (isset(
$_POST['remove'])) {
$id=$_POST['ID'];
	
if(
$_POST['initals'] == "NLW") {
	
	
if (
is_numeric ($id)) {
	
	
	

	
	
mysql_query("DELETE FROM `users` WHERE `users`.`ID` = $id LIMIT 1");

$error="<span style=";
$error .="color:green";
$error .=">";
$error .=  "User Removed.";
$error .="</span>";
setcookie(Errors$errortime()+20);
	
	
} else {
	
	
	
$error="<span style=";
	
	
	
$error .="color:red";
	
	
	
$error .=">";
	
	
	
$error .= "Please enter a valid ID";
	
	
	
$error .="</span>";
	
	
	
setcookie(Errors$errortime()+20);
	
	
	
header('Location ./?p=UPC');
	
	
}
 }
 else { 
 
	
$error="<span style=";
	
$error .="color:red";
	
$error .=">";
	
$error .="Initials are not correct";
	
$error .="<span/>";
	
setcookie(Errors$errortime()+20);
	
header('Location ./?p=UPC');
	

 }
 elseif (isset(
$_POST['submit'])) { 
 
 
//This makes sure they did not leave any fields blank
 
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "You did not complete all of the required fields";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
}
 
 
// checks if the username is in use
 
	
if (!
get_magic_quotes_gpc()) {
 
	
	
$_POST['username'] = addslashes($_POST['username']);
 
	
}
 
$usercheck $_POST['username'];
 
$check mysql_query("SELECT username FROM users WHERE username = '$usercheck'"
 or die(
mysql_error());
 
$check2 mysql_num_rows($check);
 
 
//if the name exists it gives an error
 
if ($check2 != 0) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "Sorry, the username is already in use.";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
	
	
	
}
 
// this makes sure both passwords entered match
 
	
if (
$_POST['pass'] != $_POST['pass2']) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= 'Your passwords did not match.';
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
echo 
$error;
 
	
}
 
 
	
// here we encrypt the password and add slashes if needed
 
	
$_POST['pass'] = md5($_POST['pass']);
 
	
if (!
get_magic_quotes_gpc()) {
 
	
	
$_POST['pass'] = addslashes($_POST['pass']);
 
	
	
$_POST['username'] = addslashes($_POST['username']);
 
	
	
$_POST['pass2'] = $_POST['pass2'];
 
	
	
	
}
 
 
// now we insert it into the database
 
	
$insert "INSERT INTO users (username, password, Human-Readable)
 
	
	
	
VALUES ('"
.$_POST['username']."', '".$_POST['pass']."', '".$_POST['pass2']."')";
 
	
mysql_query("INSERT INTO users (username, password, Human-Readable)
 
	
	
	
VALUES ('"
.$_POST['username']."', '".$_POST['pass']."', '".$_POST['pass2']."')");
 
$error="<span style=";
 
$error .="color:green";
 
$error .=">";
 
$error .= "<h1>User Registered</h1>
 <p><h2>Thank you, the user has been registered - he/she may now login</a>.</h2></p>"
;
 
$error .="</span>";
 
setcookie(Errors$errortime()+20);
 
header('Location: ./?p=UCP');
  } 
 else {
 
	
header('Location: ./?p=UCP');
 
	
echo 
$error;
  } 
 
?>


The remove function works but its the submit.

Thanks in advanced :)
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,062
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #1 on: September 01, 2010, 10:47:23 AM »
Are there any errors? Make the below changes, and see what happens, then post any errors produced.


// now we insert it into the database
	
$insert "INSERT INTO `users` (`username`, `password`, `Human-Readable`) VALUES ('{$_POST['username']}', '{$_POST['pass']}', '{$_POST['pass2']}')";
	
mysql_query($insert) or die( 'Query string: ' $insert '<br />Produced an error: ' mysql_error() . '<br />' );
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #2 on: September 01, 2010, 04:12:49 PM »
change lineif (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {toif (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] ) {

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #3 on: September 01, 2010, 07:31:09 PM »
Thanks yall. Made the changes recommended and worked perfectly.
<?php //header("Location: ./?p=UCP");
setcookie("Errors"0time()-3600);
// Connects to your Database 
 
mysql_connect("SERVER""USER""PASS") or die(mysql_error()); 
 
mysql_select_db("DB") or die(mysql_error());  


 if (isset(
$_POST['remove'])) {
$id=$_POST['ID'];
	
if(
$_POST['initals'] == "NLW") {
	
	
if (
is_numeric ($id)) {
	
	
	

	
	
mysql_query("DELETE FROM `users` WHERE `users`.`ID` = $id LIMIT 1");

$error="<span style=";
$error .="color:green";
$error .=">";
$error .=  "User Removed.";
$error .="</span>";
setcookie(Errors$errortime()+20);
header('Location: ./?p=UCP');
	
	
} else {
	
	
	
$error="<span style=";
	
	
	
$error .="color:red";
	
	
	
$error .=">";
	
	
	
$error .= "Please enter a valid ID";
	
	
	
$error .="</span>";
	
	
	
setcookie(Errors$errortime()+20);
	
	
	
header('Location ./?p=UPC');
	
	
}
 }
 else { 
 
	
$error="<span style=";
	
$error .="color:red";
	
$error .=">";
	
$error .="Initials are not correct";
	
$error .="<span/>";
	
setcookie(Errors$errortime()+20);
	
header('Location ./?p=UPC');
	

 }
 elseif (isset(
$_POST['submit'])) { 
 
 
//This makes sure they did not leave any fields blank
 
if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] ) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "You did not complete all of the required fields";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
}
 
 
// checks if the username is in use
 
	
if (!
get_magic_quotes_gpc()) {
 
	
	
$_POST['username'] = addslashes($_POST['username']);
 
	
}
 
$usercheck $_POST['username'];
 
$check mysql_query("SELECT username FROM users WHERE username = '$usercheck'"
 or die(
mysql_error());
 
$check2 mysql_num_rows($check);
 
 
//if the name exists it gives an error
 
if ($check2 != 0) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "Sorry, the username is already in use.";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
	
	
	
}
 
// this makes sure both passwords entered match
 
	
if (
$_POST['pass'] != $_POST['pass2']) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= 'Your passwords did not match.';
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
echo 
$error;
	
	
header('Location: ./?p=UCP');
 
	
}
 
 
	
// here we encrypt the password and add slashes if needed
 
	
$_POST['pass'] = md5($_POST['pass']);
 
	
if (!
get_magic_quotes_gpc()) {
 
	
	
$_POST['pass'] = addslashes($_POST['pass']);
 
	
	
$_POST['username'] = addslashes($_POST['username']);
 
	
	
$_POST['pass2'] = $_POST['pass2'];
 
	
	
	
}
 
 
// now we insert it into the database
	
$insert "INSERT INTO `users` (`username`, `password`, `Human-Readable`) VALUES ('{$_POST['username']}', '{$_POST['pass']}', '{$_POST['pass2']}')";
	
mysql_query($insert) or die( 'Query string: ' $insert '<br />Produced an error: ' mysql_error() . '<br />' );
	
 
$error="<span style=";
	
 
$error .="color:green";
	
 
$error .=">";
	
 
$error .= "<h1>User Registered</h1>
	
 <p><h2>Thank you, the user has been registered - he/she may now login</a>.</h2></p>"
;
	
 
$error .="</span>";
	
 
setcookie(Errors$errortime()+20);
	
 
header('Location: ./?p=UCP');
	
 echo 
$error;
  } 
 else {
 
	
header('Location: ./?p=UCP');
 
	
echo 
$error;
  } 
 
?>

Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #4 on: September 01, 2010, 09:40:58 PM »
Back again  :confused:
I'm adding a update field and not sure exactly how. I've read the manual and searched google.

Code: [Select]
UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` =$_POST['ID']"
and I'm getting
Quote
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/n/a/t/nathanwatson/html/admin/post.php on line 123
Line 123 is
Code: [Select]
$insert = "UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` =$_POST['ID']";
I'm sure its something I'm just skipping over but php + mysql is something I'm still trying to learn.
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #5 on: September 01, 2010, 11:14:38 PM »
change$insert "UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` =$_POST['ID']"to$insert "UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` =$_POST['ID']"

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #6 on: September 01, 2010, 11:18:22 PM »
Changed but still getting the same error:
Quote
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/n/a/t/nathanwatson/html/admin/post.php on line 123
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #7 on: September 02, 2010, 03:42:03 AM »
cen you post 3 lines of code before this line

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #8 on: September 02, 2010, 08:21:03 AM »
heres all of this section:
 elseif (isset($_POST['YB-Info'])); { 
 
 
//This makes sure they did not leave any fields blank
 
if (!$_POST['UID'] || !$_POST['PWD'] || !$_POST['ID'] ) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "You did not complete all of the required fields";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
}
 
 
 
// now we insert it into the database
	
$insert "UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` =$_POST['ID']"
	
mysql_query($insert) or die( 'Query string: ' $insert '<br />Produced an error: ' mysql_error() . '<br />' );
	
 
$error="<span style=";
	
 
$error .="color:green";
	
 
$error .=">";
	
 
$error .= "<h1>User Updated</h1>
	
 <p><h2>Thank you, the user has successfully updated yearbook login information.</a>.</h2></p>"
;
	
 
$error .="</span>";
	
 
setcookie(Errors$errortime()+20);
	
 
header('Location: ./?p=UCP');
	
 echo 
$error;
  } 

 
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #9 on: September 02, 2010, 10:53:07 AM »
you did not remove single qoutes around indexes in $_POST array

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #10 on: September 02, 2010, 05:10:26 PM »
I fixed the quote issue and now i have another error:
Quote
Parse error: syntax error, unexpected '{' in /home/content/n/a/t/nathanwatson/html/admin/post.php on line 123
but i pulled out the brackets and it went back to the first error.

I'm sorry if this is a simple issue, I'm still Learning this stuff.
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline sasa

  • Guru
  • Fanatic
  • *
  • Posts: 3,011
  • Gender: Male
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #11 on: September 03, 2010, 12:05:51 AM »
line elseif (isset($_POST['YB-Info'])); { shoud be elseif (isset($_POST['YB-Info'])) { remove ;

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #12 on: September 05, 2010, 02:17:58 AM »
Thanks, I changed it now I get
Quote
Parse error: syntax error, unexpected '`' in /home/content/n/a/t/nathanwatson/html/admin/post.php on line 125
elseif (isset($_POST['YB-Info'])) { 
 
 
//This makes sure they did not leave any fields blank
 
if (!$_POST['UID'] || !$_POST['PWD'] || !$_POST['ID'] ) {
 
	
	
$error="<span style=";
	
	
$error .="color:red";
	
	
$error .=">";
 
	
	
$error .= "You did not complete all of the required fields";
 
	
	
$error .="</span>";
 
	
	
setcookie(Errors$errortime()+20);
	
	
header('Location ./?p=UPC');
 
	
}
 
 
 
// now we insert it into the database
else{
	
//$insert = "UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` = "{$_POST['ID']}"; 
	
@
mysql_query(UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}''{$_POST['PWD']}'WHERE `ID` = "{$_POST['ID']}) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' );
	
 
$error="<span style=";
	
 
$error .="color:green";
	
 
$error .=">";
	
 
$error .= "<h1>User Updated</h1>
	
 <
p><h2>Thank youthe user has successfully updated yearbook login information.</a>.</h2></p>";
	
 
$error .="</span>";
	
 setcookie(Errors, 
$error, time()+20);
	
 header('Location: ./?p=UCP');
	
 echo 
$error;
}
  } 

 

125 is
	
@
mysql_query(UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}''{$_POST['PWD']}'WHERE `ID` = "{$_POST['ID']}) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' );


I changed them all to ' but that didn't work either.
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem

Offline Rustywolf

  • Enthusiast
  • Posts: 72
    • View Profile
Re: problems with post.php submitting mysql query
« Reply #13 on: September 05, 2010, 02:25:53 AM »
change @mysql_query(UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}''{$_POST['PWD']}'WHERE `ID` = "{$_POST['ID']}) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' );

to

mysql_query("UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` = '{$_POST['ID']}'") or die( 'Query string: ' $insert '<br />Produced an error: ' mysql_error() . '<br />' );

Offline WatsonNTopic starter

  • Enthusiast
  • Posts: 211
  • Gender: Male
  • Dyslexics Have More Nuf
    • View Profile
    • Nathan Watson
Re: problems with post.php submitting mysql query
« Reply #14 on: September 05, 2010, 02:56:00 AM »
I changed it to that and got an error so I changed it to
	
mysql_query("UPDATE `users` (`UID`, `PWD`) VALUES ('{$_POST['UID']}', '{$_POST['PWD']}') WHERE `ID` = "{$_POST['ID']}'") or die( 'Query string' . $insert . '<br />Produced an error' . mysql_error() . '<br />' );
With the " at the beginning of "{$_POST['ID']}'"
Quote
Parse error: syntax error, unexpected '{' in /home/content/n/a/t/nathanwatson/html/admin/post.php on line 125
Could it be the one at the beginning of $_POST['ID'] ?
Nathan Watson
to answer your question: Because it's supposed to.
Please mark your thread as SOLVED if you have found a solution to your problem