-1

I'm having a big issue here, I'm trying to upload some data to a database, and I really don't have a clue why it isn't getting uploaded.

This one here is my HTML form to send data to the php. (This one here should have no problem at all)

<form method="post" action="uploadinfo.php">
 <div style="width:542px;height:129px;margin-left:45px;margin-top:102px">
  <textarea name="stufftoupload" placeholder="Write your stuff here" rows="8" cols="65"></textarea>
 </div>
 <div style="width:95px;height:29px;margin-left:489px;margin-top:22px">
  <input type="image" src="myimg.png">
 </div>
</form>

And this one here is my PHP to upload to the database, this is where the problem should be, but I have no clue what it is. I've tried several solutions, but nothing is working.

<?php

 session_start();

 $db = mysql_connect("host","db","pass");
 if(!$db) die("Error");
 mysql_select_db("table",$db);

 $email = $_SESSION['email'];
 $stuff = $_POST['stuff'];

 if (!$stuff)
 {
  echo "<script type='text/javascript'>window.alert('Fill all the blanks.')</script>"; 
  $url = 'upload.php';
  echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; 
 }
 else
 {
  $url = 'success.php';
  echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';    
 }

 mysql_query('SET NAMES utf8');

 $sql = "SELECT * FROM table WHERE email = '$email'";
 $result = mysqli_query($db,$sql);

 mysqli_fetch_all($result,MYSQLI_ASSOC);

 $sql = "INSERT INTO table SET stuff = '$stuff'" or die(mysql_error());

 $result = mysql_query($sql);

?>

So this is about it, I'm almost positive it's something within this code, but it could be some bad session managing, though I'm not totally sure about it.

Anyway, thanks in advance for the help. It'll be totally appreciated.

4

2 回答 2

0

这里有一些问题,所以我将从我现在看到的开始。

这一行:

$db = mysql_connect("host","db","pass");

是连接到您的数据库的内容,我假设“主机”不指向任何内容。根据运行的位置,通常使用 Localhost。您还需要确保密码正确。

按照建议,使用 mysqli。

您的插入需要类似于:

INSERT INTO table VALUES ({$stuff});

不确定您想从该表单中获得什么,但您的会话变量必须与您在表单上使用的输入名称相匹配。

$stuff = $_POST['stufftoupload'];
于 2013-07-12T00:27:57.753 回答
0

$db正在使用 mysql 方法连接到数据库,但您正在基于 mysqli 方法进行查询。您需要在这里做两件事才能了解正在发生的事情。首先,将所有mysql_调用更改为mysqli_调用,并添加一些错误报告(例如,添加or die (mysqli_error($db);到您查询的每一行的末尾)应该为您指明正确的方向。

您在这里的第一个明显问题是您使用 mysql_connect 连接到数据库,但随后尝试使用 mysqli 查询该连接。使用一个,而不是两个。

此外,您的 SQL 查询应该读取INSERT INTO table (stuff) VALUES ($stuff)而不是INSERT INTO table SET stuff = '$stuff'

于 2013-07-12T00:23:32.753 回答