Jump to content

Blank Screen with MySQL


Capitan Jack

Recommended Posts

Hi all,

 

I am having some trouble with INSERT. Everytime I visit the page I get blank screen. I checked my database and I know it is not updating. What am I doing wrong?

 

<?php

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);



   if ($dbc = @mysql_connect 
('mysql.smith.robots.net', 'smith', '123456'))

 {
if (!@mysql_select_db ('smith')) 
{


$query = "INSERT INTO blog_posts
(id, title, posted_at, excerpt, body, categories)
VALUES (0, '{$_POST['title']}', '{$_POST['posted_at']}', '{$_POST['excerpt']}', '{$_POST['body']}', '{$_POST['categories']}'";

if (@mysql_query ($query)) {
	print "<p>The blog entry has been 
	added.</p>";
} else {
	print "<p>Could not add the entry 
	because: <b>" . mysql_error() . 
	"</b>. The query was $query.</p>";
}

   	 mysql_close();  


}}
  ?>

Link to comment
https://forums.phpfreaks.com/topic/106019-blank-screen-with-mysql/
Share on other sites

normally there is a syntax error with in your code if there is a blank page being displayed.

you are missing a ) at the end of your query.

 

<?php
VALUES (0, '{$_POST['title']}', '{$_POST['posted_at']}', '{$_POST['excerpt']}', '{$_POST['body']}', '{$_POST['categories']}'";
?>

 

shoud be

 

<?php
VALUES (0, '{$_POST['title']}', '{$_POST['posted_at']}', '{$_POST['excerpt']}', '{$_POST['body']}', '{$_POST['categories']}'");
?>

 

 


if (!@mysql_select_db ('smith'))
   {
   

$query = "INSERT INTO blog_posts
(id, title, posted_at, excerpt, body, categories)
VALUES (0, '{$_POST['title']}', '{$_POST['posted_at']}', '{$_POST['excerpt']}', '{$_POST['body']}', '{$_POST['categories']}'";
   

 

You're checking if selecting the DB failed and then doing the query if it failed, surely you want to check for success?

 


if ( mysql_select_db('smith') )

 

 

Okay, so I got INSERT to work but now I want to reroute the user to use the header function to send the user to another page. Basically, the id is auto_increment so I have to use whatever my database assigns the next id for the post. I am having trouble being able to retrieve the auto increment id. Here is my code...

 

<?php
ob_start();
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);



   if ($dbc = @mysql_connect 
(www.123.com, 'smith', '123456'))

 {
  } else {
die ('<p>Could not connect to 
mySQL because: <b>' .
mysql_error() . '</b></p>');
}
if (!@mysql_select_db ('smith')) 
{

} 



$query = "INSERT INTO blog_posts
(id, title, posted_at, excerpt, body, categories)
VALUES (0, '{$_POST['title']}', '{$_POST['posted_at']}', '{$_POST['excerpt']}', '{$_POST['body']}', '{$_POST['categories']}')";

if (@mysql_query ($query)) {
   	
echo header ('Location: www.123.com/index.php?id={$_GET['id']}');
   exit();	
} else {
	print "<p>Could not add the entry 
	because: <b>" . mysql_error() . 
	"</b>. The query was $query.</p>";
}

   	 mysql_close();  

ob_end_flush();
  ?>

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.