Jump to content

Adam Brave

Members
  • Posts

    25
  • Joined

  • Last visited

Posts posted by Adam Brave

  1. I have a form defined by the following code:

    <form name="input" action="insert.php" method="get"> <input type="text" name="meeting"><input type="Submit" value="Gravar"></form>

    And, in other file (insert.php), I want to insert in the database the information that the user introduced onto the form with the following code:

     <?php session_start(); ?><html><body><?php $link = mysqli_connect('localhost', 'root');if (!$link) { die('Nao foi possivel conectar: ' . mysqli_error()); }else{echo 'Conexao bem sucedida';echo "<br />";}mysqli_select_db("databasexpto", $link); $appoint = mysqli_query("INSERT INTO appointments (`what`, `owner`) VALUES('$_POST['meeting']','$_SESSION['userID']')"); if (!mysqli_query($link,$sql)) {die('Error: ' . mysqli_error());}else{ echo "1 record added";} mysqli_close($link);?></body></html>

    When I execute the code I receive the following error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\Program Files\EasyPHP-12.1\www\files\insert.php on line 21 Can someone help me?

  2. In PHP you can load data from another file using include() but if you want a redirect, you can use a location header:
    header('Location: http://example.com/');exit;

    The specifications say URLs in the location header must be absolute and prepended by the http: or https: protocol.If you send a location header, it must be sent before any HTML or printed content.

    Tkz, it worked :)
  3. location.href = "some-page.php"

    or just link to the PHP file with an <a> tag and just have the PHP file output the HTML you want.

    That works in javascript but not in php. I want a instruction that works inside of the tags <?php ... ?>
  4. Solved :)

    $result = mysql_query(SELECT * FROM userdb WHERE mail LIKE '$maill' AND pass LIKE '$passwordd');

    Btw, can someone tell me how do I load a html page with php code? In javascript I would use the instruction location.href but how do I load a page with php?

  5. I have changed the code to this:

    $maill = $_POST['fmail'];$passwordd = $_POST['fpass'];$mysqli = new mysqli("localhost",$maill,"");/* check connection */if ($mysqli->connect_errno) {    printf("Connect failed: %s\n", $mysqli->connect_error);    exit();}$mysqli->select_db("database.accdb");$result = $mysqli->query("SELECT * FROM user WHERE mail=$maill AND password=$passwordd");$row = $result->fetch_row();printf("Default database is %s.\n", $row[0]);

    And my output is: "Fatal error: Call to a member function fetch_row() on a non-object in C:\Program Files\EasyPHP-12.1\www\welcome.php on line 27" Line 27 :

    $row = $result->fetch_row();

    Now, I'm sure that I have a row in my database with the mail and password stored on the variables $maill and $password and, I'm also sure, that these variables have the corresponding information so why can't I validate that user?

  6. From what I see, the information submitted by the user (mail=asd@hotmail.com and password=asd) have something wrongon the password. For example I printed the two variables and get this:

     <form action="welcome.php" method="post">mail: <input type="text" name="fmail">password: <input type="text" name="fpass"><input type="submit"></form>...$maill = $_POST['fmail'];$passwordd = $_POST['fpass'];echo $maill;echo "<br>";echo $passwordd;

    Output:asd@hotmail.comasdbool(false) From where come the "bool(false)" ?

  7. Hi, I want to make a login and a validation in a database. In order to do it I use the following code where: user -> table with all the user information like birthday, mail, username, first name etcpassword -> column of the table "user" that contains all the passwordsmail -> column of the table "user" that contains all the mails. The two variables, $maill and $passwordd, are use to store the information required at the login moment to the user.

    $result = mysql_query("SELECT password FROM user WHERE mail=$maill");$row = mysql_fetch_array($result); if ( $row['mail'] == $maill &&  $row['password'] == $passwordd ){    echo $row['name'] . " " . $row['ultimonome'];  } else  {   echo "login not correct";  }

    Output: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-12.1\www\welcome.php on line 29login not correct Can someone help me?

  8. Just one last question a little bit offtopic. I have this two lines of code:

    month = document.calForm.selMonth.options[document.calForm.selMonth.selectedIndex].value;month += 1;

    What I expected that should happen was the variable "month" to be incremented, but what really happen is that if "month" is equal 5 on the end of the first line then in the second line it will result "51" . The instruction "month += 1" does not do a numerical calculation, instead, it joins "1" to the previous value of the variable. How can I change this?

  9. With this:

    function NewPage(day){myJSON = '{"jday":"' + day + '"}';location.href = 'new.php?xpto=' + encodeURIComponent(myJSON);}....<?php$dayphp = $_GET['xpto'];var_dump($dayphp);?> 

    My output is: " string(13) "{"jday":"24"}" ,, " But I just want the number 24. How do I get rid of the rest? Tkz for the help guys :)

  10. Well..here is what I have done. On the first file I have:

    text += "<td align=center><span id=sp" + aa + " onClick='NewPage(" + aa + ")'></span> </td>";...function NewPage(day){myJSON = { "jday" : day}; // I'm trying to pass the function argument (day) to the "jday" field.location.href = 'new.php?xpto=' + myJSON;}

    On the second file I have:

    <?php$dayphp = $_GET[xpto];echo $dayphp;?>

    My output is: "Notice: Use of undefined constant xpto - assumed 'xpto' in C:\Program Files\EasyPHP-12.1\www\new.php on line 13[object Object] ,, " Help..lol

  11. You can't. Confusion arose because your first post talks about passing data from one PHP file to another. That's not what you're doing. You're sending data from JavaScript running in the browser to a PHP script. Your option is to send data in a query string, or as POST data from a form, or to use AJAX. Your first idea was fine. What you didn't realize was that in the URL 'new.php?xpto', xpto is no longer a variable. It's just a string. What you need instead is a string that contains all the data. JSON is one technique that will work.
    Hmm ok, I wil use the JSON object but from what I see I dont understand how can I use the value of the JSON in a second file. Can you help me?
  12. no. you'll just have pass them as individual params in the query string. another option is to use $_SESSION. You can save pretty much any data type in a SESSION member, since it's just an array.
    Can you give me an example of how do it?
  13. Hi, can I pass an array from one php file to another php file like this: First file:

    function NewPage(Day, Month, Year){xpto[0] = Day;xpto[1] = Month;xpto[2] = Year;location.href='new.php?xpto';}

    Second file (new.php):

    <?php$dayphp = $_GET[xpto[0]];$monthphp = $_GET[xpto[1]];$yearphp = $_GET[xpto[2]]; ?>

    I have tried but just got an error like this "Parse error: syntax error, unexpected '[', expecting ']' in C:\Program Files\EasyPHP-12.1\www\new.php on line 13" Can I do something similar?

  14. Select elements don't have a value property, they have an array of options and a selectedIndex property. You use the selectedIndex to figure out which option they have selected, and then get the value from that option. var xpto = parseInt(document.calForm.selMonth.options[document.calForm.selMonth.selectedIndex].value);
    It didn't worked =\
  15. Hi, I have one html file where I use the following expression:

    <select name=selMonth onChange='changeCal()'>"; 

    Then, I have another file, this one is a php file, where I want to use the selected value on the dropdown list select object. I tried to use the following expression in the php file but it didn't worked:

    var xpto = parseInt(document.calForm.selMonth.value);

    It presents me nothing... Can someone help me please? Regards,

×
×
  • Create New...