Jump to content

SQL INSERT


vonKristoff

Recommended Posts

Hi .. thanks .. yes corrected - but that was my TYPO! I have it correct in in my code im using.

 

I get a error 500 in my java console in firefox.

In my error log - it says PHP Fatal error:  Function name must be a string

 

I cant see where its wrong.

..> anything else sticking out? - Otherwise it could be something to do with mySQL on my server?

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275618
Share on other sites

Even if I push a non var through ie:

 

$q = "INSERT INTO videos(src) VALUE("text")";

 

it still wont work and says unexpected T_STRING ..

 

For the record - if i push the $var into my error_log it reads correct. :(

 

i use mysql not mysqli but:

 

$q = "INSERT INTO videos(src) VALUES ('text')";

 

 

should be the proper way to write that query, or in the original query:

 

$id=$_POST['id'];

$q = "INSERT INTO videos(src) VALUES ('$id')";

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275642
Share on other sites

Thanks..!

 

$id=$_POST['id'];

$q = "INSERT INTO videos(src) VALUES ('$id')";

 

was what I was after - I thought that was right - Alas with my final push with

$result=$mysqli->query($q) or die($mysqli_error($mysqli));

It doesnt work and throws up an error "undefined variable" & Function must not be a string. - That I dont understand and have a feeling my server is playing up ... ?

 

any hints to why this isnt going through. As said if I error log my $id - I get the correct var coming through in the log.

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275649
Share on other sites

ok, just for you fenway

<?php
include 'database.php';
if(!mysqli_connect_errno())
{
    error_log("Connected");
    $id=$_POST['id'];
$q="INSERT INTO videos(src) VALUE('$id')";	
$result=$mysqli->query($q) or die($mysqli_error($mysqli));
}
   else{
   error_log("not connected");
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275652
Share on other sites

My code is as follows - and throws no errors - but neither any javascript console messages - and does nada in general... So Im really stuck - is there no end!? :shrug:

 

/* modified */

OK - reset servers / cache / filled mug

It now takes action...> with the following ::::::

<?php
require_once "database.php";
if(!mysqli_connect_errno())
{
    error_log("Connected");
    $id=$_POST['id'];
$mysqli->query("INSERT INTO videos(src) VALUES('".mysql_real_escape_string($id)."')");
}
   else{
   error_log("not connected");
   }
?>

 

Great!

However - still dont get why I had to "mysql_real_escape_string" because I havent seen that in ANY tutorials - or from advice given by other helpful people ... guess u gotta be a freak to get it.. ;)

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275692
Share on other sites

in the original code that you posted... in this line:

$result = $mysqli->query($q) or die($mysqli_error($mysqli));

 

you are mixing OO style ($mysqli->query()) with something like (but no close) to Procedural Style ($mysqli_error()) ... totally wrong

 

maybe what you are trying to do is:

$result = $mysqli->query($q) or die($mysqli->error);

 

this is going to trow the error that you are getting ""undefined variable" & Function must not be a string"... if your query is wrong and die() is triggered

 

and fenway post still valid.

Link to comment
https://forums.phpfreaks.com/topic/248401-sql-insert/#findComment-1275761
Share on other sites

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.