Jump to content

[SOLVED] INSERT INTO Statement Refuses to Work


CloudSex13

Recommended Posts

Hey everyone, thanks for reading.

 

I have this bit of code here:

 

function add() {

if (isset($_POST['add'])) {

$addtask = $_POST['task'];
$addpriority = $_POST['priority'];
$adddeadline = $_POST['deadline'];
$getnexttaskid = mysql_query("SELECT TaskID FROM Tasks");
$amountoftasks = mysql_num_rows($getnexttaskid);
$nexttaskid = $amountoftasks + 1;

$getaccountid = mysql_query("SELECT AccountID FROM Accounts WHERE Username='".$_COOKIE['usercookieLP']."' LIMIT 1");
$getinfo = mysql_fetch_array($getaccountid);
$AccountID = $getinfo['AccountID'];

mysql_query("INSERT INTO Tasks SET TaskID='$nexttaskid', AccountID='$AccountID', Task='$addtask', Priority='$addpriority', Created=NOW(), Deadline='$adddeadline', Status='1'");
$added = "<p align=center><span class=success>The task has been created.</span></p>";
}

echo "
".$added."
<div class=box>
<form method=post action=tasks.php?action=add>
<table width=100% align=center border=0>
<tr>
<td width=40% align=right>
Task:
</td>
<td width=60% align=left>
<textarea name=task cols=35 rows=5></textarea>
</td>
</tr>
<tr>
<td width=40% align=right>
Deadline:
</td>
<td width=60% align=left>
<input type=text name=deadline class=text>
</td>
</tr>
<tr>
<td width=40% align=right>
Priority:
</td>
<td width=60% align=left>
<select name=priority class=text>
<option value=3>Low</option>
<option value=2>Medium</option>
<option value=1>High</option>
</select>
</td>
</tr>
<tr>
<td align=center width=100% colspan=2>
<input type=submit class=button value='Add' name=add>
</td>
</tr>
</table>
</form>
</div>";

}

 

This code was working perfectly fine until I started messing around with the page layout.

Basically, the code is flawless - no errors.

Database connections are fine, all good.

Like I said, it was just working.

But for some reason, the INSERT INTO statement will not create a new row in the database now.

Manually putting in a row using phpMyAdmin works, though.

I've tried an alternative method using VALUES, but that had no luck.

 

Would anyone have any ideas? I'm stumped.

 

x.x

 

Thanks if so -

 

Best.

Start with echoing mysql errors:

 

mysql_query("INSERT INTO ...") or die(mysql_error());

 

same for the other query.

 

Even better would be

 

$query = "INSERT INTO ...";
mysql_query($query) or die(mysql_error().": $query");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.