topflight Posted November 4, 2008 Share Posted November 4, 2008 Hi all, May somebody please help me, I am trying to create an update profile script it works(i think becuase I am not receiving any syntax errors) but, nothing displays or the database doesn't update. here is my code <?php if(!$_COOKIE['login']) { header("Location:login.php"); } ?> <?php if(isset($_GET['login'])){ $email = $_POST['email']; $semail = $_POST['semail']; $pwd = $_POST['pwd']; $about = $_POST['about']; if((!$email) || (!$pwd)){ echo '<font color="#FF0000"><center>The following Required Data is Missing</font></center>'; if(!$email){ echo'You have left the Email filed empty. Please enter a valid email'; } if(!$pwd){ echo 'You have left the Password Filed empty. Please enter a password'; } else { include 'db.php'; $sql = "SELECT * FROM pilots WHERE login = '{$_GET['login']}'"; $query = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $query = mysql_query($sql); if($query){ $erow = mysql_num_rows($query); if($erow >= 1){ echo'The Email Address you have chosen is already in the database'; } else { $update1 = "UPDATE pilots SET email = '$email'' WHERE login = '{$_GET['login']}'"; $result1 = mysql_query($update1) or die (mysql_error()); $update2 = "UPDATE pilots SET pwd = '$pwd' WHERE login = '{$_GET['login']}'"; $result2 = mysql_query($update2) or die (mysql_error()); $update3 = "UPDATE pilots SET about = ''$about' WHERE login = '{$_GET['login']}'"; $result3 = mysql_query($update3) or die (mysql_error()); $update4 = "UPDATE pilots SET semail = ''$semail' WHERE login = '{$_GET['login']}'"; $result4 = mysql_query($update4) or die (mysql_error());?> <script>javascript:alert("Account Updated" )</script> <script>javascript:window.location = "index.php"</script> <?php } } } } } ?> thanks in advanced. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 4, 2008 Share Posted November 4, 2008 Not sure why you are doing seperate queries for this, but you have two single quotes here SET semail = ''$semail' Quote Link to comment Share on other sites More sharing options...
topflight Posted November 4, 2008 Author Share Posted November 4, 2008 When I do double quotes I receive a T_VARIABLE error. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 4, 2008 Share Posted November 4, 2008 Why are you trying double quotes? $update4 = "UPDATE pilots SET semail = '$semail' Quote Link to comment Share on other sites More sharing options...
topflight Posted November 4, 2008 Author Share Posted November 4, 2008 I need to right? Quote Link to comment Share on other sites More sharing options...
srhino Posted November 4, 2008 Share Posted November 4, 2008 You also have two single quotes in front of ''$about'... Should be ... "UPDATE pilots SET about = '$about' WHERE login = '{$_GET['login']}'"; and "UPDATE pilots SET semail = '$semail' WHERE login = '{$_GET['login']}'"; Quote Link to comment Share on other sites More sharing options...
topflight Posted November 5, 2008 Author Share Posted November 5, 2008 Still just showing a white page. Not updating or running the javascript with using the following code: "UPDATE pilots SET about = '$about' WHERE login = '{$_GET['login']}'"; and "UPDATE pilots SET semail = '$semail' WHERE login = '{$_GET['login']}'"; Quote Link to comment Share on other sites More sharing options...
topflight Posted November 5, 2008 Author Share Posted November 5, 2008 anybody else have any input? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 5, 2008 Share Posted November 5, 2008 Time for a re-write: <?php if(!$_COOKIE['login']) { header("Location:login.php"); } if(isset($_GET['login'])){ $errors = array(); $qtmp = array(); foreach ($_POST as $fld => $val) { $val = trim(stripslashes($val)); switch ($fld) { case 'email': if (strlen($val) == 0) $errors[] = 'You have left the Email filed empty. Please enter a valid email'; else $qtmp[] = $fld . " = '" . mysql_real_escape_string($val) . "'"; break; case 'pwd': if (strlen($val) == 0) $errors[] = 'You have left the Password Filed empty. Please enter a password'; else $qtmp[] = $fld . " = '" . mysql_real_escape_string($val) . "'"; break; case 'semail': case 'about': if (strlen($val) > 0) $qtmp[] = $fld . " = '" . mysql_real_escape_string($val) . "'"; break; } } if (!empty($errors)) { echo '<p style="color:red;text-align:center">The following Required Data is Missing</p>'; echo implode("<br>\n",$errors) . "<br>\n"; } else { include 'db.php'; $sql = "SELECT * FROM pilots WHERE login = '" . mysql_real_escape_string(stripslashes($_GET['login'])) . "'"; $query = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $erow = mysql_num_rows($query); if($erow > 0){ echo 'The Email Address you have chosen is already in the database'; } else { if (!empty($qtmp)) { $uq = 'update pilots set ' . implode(', ', $qtmp) . " WHERE login = '" . mysql_real_escape_string(stripslashes($_GET['login'])) . "'"; $rs = mysql_query($uq) or die("Problem with the update query: $uq<br>" . mysql_error()); echo '<script>alert("Account Updated" ); window.location = "xindex.php"</script>'; } } } } ?> I combined the error checking with creating a temporary array to create the update query. Also, your Javascript was incorrect. You don't need "Javascript:" when inside the <script> tag. Ken Quote Link to comment Share on other sites More sharing options...
topflight Posted November 8, 2008 Author Share Posted November 8, 2008 I have now got errors to show and now I am receiving the follow error. Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\editp_phrase.php on line 10 this is my code <?php if(!$_COOKIE['login']) { header("Location:login.php"); } ?> <?php E_ALL if(isset($_GET['login'])){ $email = $_POST['email']; $semail = $_POST['semail']; $pwd = $_POST['pwd']; $about = $_POST['about']; if((!$email) || (!$pwd)){ echo '<font color="#FF0000"><center>The following Required Data is Missing</font></center>'; if(!$email){ echo'You have left the Email filed empty. Please enter a valid email'; } if(!$pwd){ echo 'You have left the Password Filed empty. Please enter a password'; } else { include 'db.php'; $sql = "SELECT * FROM pilots WHERE login = '{$_GET['login']}'"; $query = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $query = mysql_query($sql); if($query){ $erow = mysql_num_rows($query); if($erow >= 1){ echo'The Email Address you have chosen is already in the database'; } else { "UPDATE pilots SET semail = '$semail', email = '$email', $about = '$about', $pwd = '$pwd' WHERE login = '{$_GET['login']}'";?> <script>javascript:alert("Account Updated" )</script> <script>javascript:window.location = "index.php"</script> <?php } } } } } ?> this is line 10 <?php if(isset($_GET['login'])){ Please give advice thanks a lot in advanced. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 8, 2008 Share Posted November 8, 2008 E_ALL doesn't belong there. Quote Link to comment Share on other sites More sharing options...
topflight Posted November 8, 2008 Author Share Posted November 8, 2008 that is to show the errors. when I didn't have that I would just get a white page. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted November 8, 2008 Share Posted November 8, 2008 E_ALL should be place into the error_reporting argument. error_reporting(E_ALL); is what he's saying. And place it at the top of the page, below the <?php. Quote Link to comment Share on other sites More sharing options...
topflight Posted November 9, 2008 Author Share Posted November 9, 2008 I am not receiving no errors all I am receiving it just a white page any advice? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted November 9, 2008 Share Posted November 9, 2008 Is it outputting HTML code? View the source after it loads, is there anything there? Is it making it to index.php and nothing is output there anyway? Quote Link to comment Share on other sites More sharing options...
topflight Posted November 11, 2008 Author Share Posted November 11, 2008 It suppose to be a pop up box that says profile updated and then it is suppose to redirce the user to the index, also the actual database is not updating. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.