Jump to content

sted999

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sted999's Achievements

Member

Member (2/5)

0

Reputation

  1. I have used both bits of advice but I still seem to be getting an error - SQL Error: Query: My code now - <?php if ($_POST['delete'] == 'Delete this ride') { $jName=($_POST['deleteRide']); ini_set ("display_errors", "1"); error_reporting(E_ALL); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if (isset ($_COOKIE['loginName'])) { $sql = mysql_query("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName']))); $query = mysql_query() or die ('SQL Error: ' . mysql_error(). " Query: $sql"); if ($query) { $message = "Your ride has been deleted."; } else { $message = "Ride not deleted updated."; } } } echo "$message"; ?> Can anyone help?
  2. Hiya guys. Im a newbie to MySQL and PHP and im stuck on this problem. When i run this query it is just returning a mysql error? - SQL Error: Query was empty Im not sure why it is doing this as all the fields are in the database and have values i am searching for. Can anybody think what may be wrong? Thanks. <?php if ($_POST['delete'] == 'Delete this ride') { $jName=($_POST['deleteRide']); error_reporting(E_ALL); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if (isset ($_COOKIE['loginName'])) { $query = mysql_query(sprintf("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); if ($query) { $message = "Your ride has been deleted."; } else { $message = "Ride not deleted updated."; } } } echo "$message"; ?>
  3. Sorry for the confusion, I dont think I really understood it in the first place. Its all sorted now. Sorry again.
  4. For some reason changing the order by field effects the result. Is ORDER usually used to order by a field e.g. date created which has a timestamp?
  5. its a date type in the database, would you suggest changing this to another field?
  6. Hiya all. What I am trying to do is select the last entry to my mysql table. I searched the internet and found an example, but this seems to be picking out the first entry. Can anybody suggest how to easily get the last(latest) entry. I have looked on the net but cant find anything? Thanks. <?php $query = mysql_query("SELECT startTown,destinationTown FROM Journey ORDER BY date DESC LIMIT 1") or die(mysql_error()); ?>
  7. I am reusing so code elsewhere with the sprintf(), i worked fine on the other page so I thought i'd use it again in this page. The $_POST['edit'] is the button that is clicked to run the code.
  8. I have changed my code slightly so the update code is above the query, but this is only run if called. My database is updated but with blank fields only, does anybody know why? Thanks. <?php include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if ($_POST['edit'] == 'Update your account') { $query = mysql_query(sprintf("UPDATE Member SET loginName='$loginName' WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); if ($query) { $messages = "Details updated!"; } else { $messages = "Account details not updated."; } } $members = mysql_query(sprintf("SELECT * FROM Member WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); $fetch = mysql_fetch_array($members); $loginName = $fetch['loginName']; echo 'User name : <input type="text" size="20" maxlength="15" name="userName" value="'.$loginName.'" />'; ?>
  9. I've gone for the approach of having the fields already stating what is in the database, but I have now come across another problem. When i click update it just reverts back to the original data in the database becuase its calling the variable which holds the data. What variable should i put in the mysql query instead? <?php include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $members = mysql_query(sprintf("SELECT * FROM Member WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); $fetch = mysql_fetch_array($members); $loginName = $fetch['loginName']; echo 'New user name: <input type="text" size="20" maxlength="15" name="userName" value="'.$loginName.'" />'; echo "<br />"; if ($_POST['edit'] == 'Update your account') { $query = mysql_query(sprintf("UPDATE Member SET loginName='$loginName' WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); echo("Details updated. <br /><br /><br />"); } ?> Thanks.
  10. Hiya all. Being a newbie to PHP im not totally sure if this is possible, thats why I thought i'd ask you lot. So far i havent been able to find an answer and ive got a tonne of books next to me! What i want to do is to allow a user to update their account details via a form. The problem is when i update, it puts an empty field if I dont fill one of them in. Is thier an easy way round this? Or would I need a update button and code for every field. <?php include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if ($_POST['edit'] == 'Update your account') { $loginName=($_POST['loginName']); $password=($_POST['password']); $secretQuestion=($_POST['secretQuestion']); $secretAnswer=($_POST['secretAnswer']); $email=($_POST['email']); $title=($_POST['title']); $firstName=($_POST['firstName']); $surname=($_POST['surname']); $gender=($_POST['gender']); $dob_year = $_POST['dob_year']; $dob_month = $_POST['dob_month']; $dob_day = $_POST['dob_day']; $date_of_birth = "$dob_year-$dob_month-$dob_day"; $query = mysql_query(sprintf("UPDATE Member SET loginName='$loginName',title='$title' WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); echo("Details updated <br /><br /><br />"); } ?> For example i tried to update my title, but this then set the loginName field to blank? Any help would be amazing. Thanks.
  11. Thanks for your help guys. Its sorted now. Cheers.
  12. Yeh, ive only got two records so thats why its puzzling me so much. I have gone back a few steps to try and get it working, ive changed the variable name to what i need and then queried using the variable, but still i get no results. surely once i get this query working, all I will have to change is the variable declarartion to make it work. Sorry if im being really thick on this, my brain is frazzled and ive tried every possible combination i can think of. Thanks <?php $user="stephen"; echo "$user"; include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='".$user."'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Start town : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; echo "<br />"; } mysql_free_result($result); mysql_close(); ?>
  13. This one is puzzling me. When i mannually chose the value for the query e.g. - $query = "SELECT * FROM Member WHERE loginName='stephen' "; I get the results i need. But when i change it to the variable, no such luck ???. This would suggest that the variable is wrong, but i am getting the correct answer when i echo it?!? Is the query wrong? The table name and field names are correct. About the commas being used, i found an example and have used it elsewhere in my website and it works, thats why i have stuck to it. Would you reccomend against them? Im new to php so not sure about the best way to do things yet. Code so far - <?php $user=($_COOKIE['loginName']); echo "$user"; include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='$user' "; echo mysql_error(); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Email address : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; } mysql_free_result($result); mysql_close(); ?>
  14. Hiya all. I am trying to query my database and then display the results of the query (I am wanting the users registration details to be displayed). But no results are being display? Does anyone know why? Thanks very much. <?php $user=($_COOKIE['loginName']); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='$user'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Start town : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; echo "<br />"; } mysql_free_result($result); mysql_close(); ?>
×
×
  • 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.