Jump to content

sfia

Members
  • Posts

    21
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

sfia's Achievements

Member

Member (2/5)

0

Reputation

  1. ok with some help i got it working and doing what i want. <?php $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql2)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else if ($stream =='nursing') { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); mysqli_stmt_execute($stmt); } ?>
  2. ok, I get that part. I'm not sure why I was doing it I think i just thought I was preparing a statement. I actually removed all three mysqli_query and my query still works. But don't I bind my variables by doing this? ---> mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); I thought my sql queries just prepared statements with placeholders(?, ?, ?)
  3. <?php $username = $_POST['uid']; $email = $_POST['mail']; $password = $_POST['pwd']; $passwordRepeat = $_POST['pwd-repeat']; $date = $_POST['date2']; $stream = $_POST['relationship']; $sql1 = "INSERT INTO users (uidUsers, emailUsers, pwdUsers, relationship) VALUES (?, ?, ?, ?);"; $sql2 = "INSERT INTO Family1 (username, application_filed, relationship) VALUES (?, ?, ?);"; $sql3 = "INSERT INTO Family2 (username, application_filed, relationship) VALUES (?, ?, ?);"; mysqli_query($sql1, $conn); mysqli_query($sql2, $conn); mysqli_query($sql3, $conn); $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql2)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='nursing'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql3)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='doctoral'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { $hashedPwd = password_hash($password, PASSWORD_DEFAULT); mysqli_stmt_bind_param($stmt, "ssss", $username, $email, $hashedPwd, $stream); mysqli_stmt_execute($stmt); header("Location: ../signup.php?signup=success"); exit(); ?> sorry, i added php tags to make it better readable. My queries work with parameters that I set up. <?php mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); ?> But i dont know how to make it work with that condition before executing query. perhaps I'm not using right logic here? <?php ($username==$_SESSION['uid'] and $stream =='nursing'); mysqli_stmt_execute($stmt); ?>
  4. $username = $_POST['uid']; $email = $_POST['mail']; $password = $_POST['pwd']; $passwordRepeat = $_POST['pwd-repeat']; $date = $_POST['date2']; $stream = $_POST['relationship']; $sql1 = "INSERT INTO users (uidUsers, emailUsers, pwdUsers, relationship) VALUES (?, ?, ?, ?);"; $sql2 = "INSERT INTO Family1 (username, application_filed, relationship) VALUES (?, ?, ?);"; $sql3 = "INSERT INTO Family2 (username, application_filed, relationship) VALUES (?, ?, ?);"; mysqli_query($sql1, $conn); mysqli_query($sql2, $conn); mysqli_query($sql3, $conn); $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql2)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='nursing'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql3)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='doctoral'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { $hashedPwd = password_hash($password, PASSWORD_DEFAULT); mysqli_stmt_bind_param($stmt, "ssss", $username, $email, $hashedPwd, $stream); mysqli_stmt_execute($stmt); header("Location: ../signup.php?signup=success"); exit(); I was wondering if someone could point me in the right direction. I have this code. They idea I had behind it is to insert values into different tables depending on variables being passed. So when user fills out a form and selects $stream="nursing" I want results to go to table 'users' and 'Family1', but not 'Family2' table. and if user selects $stream='doctoral' results should go to table 'users' and 'Family2', and not go to 'Family1' But with my query I get results go to both table and also users table. And there is no restriction to what users selects, variable $stream being passed no matter what it is. Is this the wrong way to go here? Did I completely mess up the logic?
  5. ok, I added $uid1 = $_SESSION['uid']; and than $sql = "SELECT id,username, date1 FROM datetable WHERE username = '$uid1'"; and that works!! Hopefully its the right way.
  6. <?php session_start(); $servername = ""; $username = ""; $password = ""; $dbname = ""; $connect = mysqli_connect($servername, $username, $password,$dbname); $sql = "SELECT id,username, date1 FROM datetable WHERE username = '".$_SESSION['uid']['username'] ."'"; $result = mysqli_query($connect, $sql); $json_array = array(); while($row = mysqli_fetch_assoc($result)) { $json_array[] = [ $row['id'], $row['username'], $row['date1'] $TotalTime ]; } echo json_encode($json_array); ?> Yes, session_start on each page. I played around a little and edit some things, I do get this now when run the var_dump($_SESSION); code. But my json format disappears. [] array(4) { ["id"]=> int(34) ["uid"]=> string(8) "bostin21" ["email"]=> string(18) "emaill123@gmail.com" ["user"]=> NULL } If i removed var_dump($_SESSION); than my query runs again.
  7. I just used echo "<pre>"; var_dump($_SESSION); echo "</pre>"; and it returns NULL. So I'm missing my session value somehow on this page.
  8. $sql = "SELECT id,username, date1, date2, total FROM datetable WHERE username = '".$_SESSION['uid']['username'] ."'"; Hello again, I ran into problem when trying to pull information for logged in user. I'm trying to display results for current user only who is signed in. Now I do have session_start(); and my query works if I replace '".$_SESSION['uid']['username'] ."'"; with 'specificusername' but when I run my current query displayed above it returns me all records with username = empty (I have some empty usernames for testing reasons). So that tells me that query cant find unique user name that is logged in. I don't get any errors and query still goes through. My datetable structure is My uid is defined in another document like so and uses another table called "users" session_start(); $_SESSION['id'] = $row['idUsers']; $_SESSION['uid'] = $row['uidUsers']; $_SESSION['email'] = $row['emailUsers']; header("Location: ../member.php?login=success"); exit(); This query works on another page where it displays logged in username in html document. <?php echo $_SESSION['uid']; ?> I have tried many different ways yesterday to modify my request ( WHERE username = $_SESSION['uid']; WHERE username = '".$_SESSION["uid"]) many other variations, but no matter what never returns logged in user information only empty username records. Can anyone see a problem with that query? or is it due to something else I'm missing? Sorry, maybe this goes in MySQL thread not here in PHP page. If someone can, please move it. Thanks.
  9. OK, thanks, i will try to set it up
  10. Thanks, its working now.
  11. Actually I got it figured now. Query was right. my column name is different on database side. I was getting HTTP 500 error.
  12. Hi, I was just trying to post form data to MySQL and trying to also post value of logged in user? but that code below doesnt work..Do you see a typo? or is it done some other way? $uid =$_SESSION[ "uid" ]; $sql = "INSERT INTO Date (uid) VALUES (:uid)"; $query= $conn->prepare( $sql ); $query->execute( array( ':uid'=>$uid) );
  13. I followed that link and used validateDate function below and now my script works!. thank you. Appreciate the help. Just trying to learn some of PHP. function validateDate($date, $format = 'Y-m-d') { $d = DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; }
  14. if (validDate($_POST['date2'], $format = 'Y-m-d')){ $date2 = date('Y-m-d', strtotime(trim($_POST['date2']))); } else { $date2 = NULL; } Like something like this? IDK that doesnt seem to work
×
×
  • 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.