Jump to content

Error happens


snallemap

Recommended Posts

Hello Php freaks!

 

I've been reading a bit tutorials, and i keep getting errors... even when i take their already done code it shows me errors... Now im wondering if Php have changed? or is it just my program or something that cannot run the php code as it is?....

 

$query = 'INSERT INTO news (author, title, news)
VALUES('$author', '$title', '$news')";
Mysql_query($query) or die(mysql_error());

echo "Thank you for submitting!";

 

In that bit there shows up errors in the $query and in the echo...

 

 

Also in other tutorials it happens, seems it totally random when it decide to say its a error :/

Link to comment
Share on other sites

Well, for future reference, you should post the error code you are getting as well to help us help you figure out what's wrong.

 

But in this case, where you set $query, you need to change that first single quote (') to a double quote (").

 

EDIT: Can anyone confirm is mysql_query() is case sensitive? (hense would Mysql_query() be acceptable as he has it posted?)

Link to comment
Share on other sites

We can only help you with specific errors. If you want help with the code you posted above, you would need to post the error as well.

 

A lot of the php information posted on the Internet is there solely to earn the site money though advertising/link clicking... Many don't care if the code they have posted on their site works or produces errors.

 

There were a few fundamental changes in php around 8 years ago and a lot of the scripts posted around on the Internet have never been updated or removed. It is really sad when we see someone trying to get help in the forum because they found code that was so out of date.

Link to comment
Share on other sites

The errors were in that code....

 

<?php


include "config.php";


$author = $_POST['author'];
$title = $_POST['title'];
$news = $_POST['news];

// insert the data into the databse

$query = 'INSERT INTO news (author, title, news)
VALUES('$author', '$title', '$news')";
Mysql_query($query) or die(mysql_error());

echo "Thank you for submitting!";

?>

 

There is the entire code...

 

The errors lays in the "echo "Than you for submitting!" and another error lays in the query to insert stuff to the database.

Link to comment
Share on other sites

Well, for future reference, you should post the error code you are getting as well to help us help you figure out what's wrong.

 

But in this case, where you set $query, you need to change that first single quote (') to a double quote (").

 

EDIT: Can anyone confirm is mysql_query() is case sensitive? (hense would Mysql_query() be acceptable as he has it posted?)

 

PHP is case-insensitive when it comes to classes, methods, and functions. Also constants if you pass TRUE as a third parameter to define().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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