Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a variable in PHP Global or with a function?
    text
    copied!<p>I am bulding a small ajax chat site and am adding an image upload with msg functionality built in PHP, MySQL and jquery with ajax. My code currently will let you upload a message, I can get the image ready for upload and store URL for the database. </p> <p>But I need to pass the variable to another if statement checking when the user submits a message. I cannot seem to get it across and into my database. </p> <p>Tryed global var, other stuff - think must be missing something. It is probably something obvious, excuse the code I am a graphic designer learning code!</p> <pre><code>$imageurl = ""; if (isset($_FILES["file"])) { //properties of uploaded file $name = $_FILES["file"] ["name"]; $type = $_FILES["file"] ["type"]; $size = $_FILES["file"] ["size"]; $temp = $_FILES["file"] ["tmp_name"]; $error = $_FILES["file"] ["error"]; if ($error &gt; 0) { die("Error uploaded file!"); } else { if ($type == "video/avi" || $size &gt; 2000000) { ?&gt; &lt;br&gt; &lt;p&gt;&lt;?die("format is not allowed or size too big!");?&gt;&lt;/p&gt; &lt;? } else { move_uploaded_file($temp, "msg_image/" . $name); } } //store url for insertation $imageurl = "msg_image/" . $name; echo '&lt;p&gt;You added a ' . $name . ' to your message&lt;/p&gt;'; return $imageurl; } /////need the var in here to store and update mysql database if (isset($_POST['message'])) { $tostore = $imageurl; $username = protect($_POST['username']); $message = protect($_POST['message']); $time = time(); $sql = "INSERT INTO messages (username, msgcontent, imageurl, msgtime) VALUES ('$username', '$message', '$tostore', $time)"; $result = mysql_query($sql); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload