Jump to content

divinedesigns1

Recommended Posts

hey guys, im having a problem inserting information into my database once again -_- i dont know what im doing wrong i even check the w3s tutorial on this and its exactly what im doing

<?phpif(isset($_GET['action'])){$action = $_GET['action'];if($action == "news"){  // creating a new Blog	    echo '<h3>New Blog</h3>';   if(isset($_POST['submit'])){    [color=#ff0000]$title = $_POST['title'];    $article = $_POST['article'];[/color]       if(empty($title) && empty($article)){	 echo 'Please Fill In All Fields';    }elseif(!empty($title) && empty($article)){	 echo 'Article: ' . 'Some text is required';    }elseif(empty($title) && !empty($article)){	 echo 'Title: ' . 'A Title Is Required';    }elseif(!empty($title) && !empty($article)){	 // filter the title and article	 $title = mysqli_real_escape_string($con, $title);	 $article = mysqli_real_escape_string($con, $article);	 $title = stripslashes($title);	 $title = strip_tags($title);	 $article = stripslashes($article);	 $article = strip_tags($article); 		 [color=#00ff00]$query = "INSERT INTO  `php`.`ent` (`id` ,`title` ,`body` ,`user`)	 VALUES ('' ,  '$title',  '$article',  '" . $_SESSION['uid'] . "')" or die('Error: ' . mysqli_error());[/color]		 echo 'Your Blog Have Been Post';    }   }else{			 echo '<table align="center" border="0" width="500" bgcolor="#ccc">';			 echo '<form action="admin.php?action=new" method="post">';			 echo '<tr>';			 echo '<td>Title</td>';			 echo '<td><input type="text" [color=#ff0000]name="title"[/color] /></td>';			 echo '</tr>';			 echo '<tr>';			 echo '<td>Article</td>';			 echo '<td><textarea [color=#ff0000]name="article"[/color] row="7"></textarea></td>';			 echo '</tr>';			 echo '<tr>';			 echo '<td colspan="2"><input type="submit" name="submit" value="Save" /></td>';			 echo '</tr>';			 echo '</form>';			 echo '</table>';      }}elseif($action == "edit"){  // Editing the blog  ?>

see its correct just as it should$query = "INSERT INTO `php`.`ent` (`id` ,`title` ,`body` ,`user`) VALUES ('' , '$title', '$article', '" . $_SESSION['uid'] . "')" or die('Error: ' . mysqli_error());and i place the value in the correct order also, the $_session['uid'] come from the the session set on the login page and there is a session_start(); at the top of the page, ahhh can someone help me with this please and thanks

Link to comment
Share on other sites

Ok im still having problems with this, i fix part of the error but it still not inserting the information into the database, anyone can help?

Edited by DDs1
Link to comment
Share on other sites

What is `php`.`ent` supposed to represent or refer to?
php is the database name and ent is the table in that database
Link to comment
Share on other sites

you refer to table name in INSERT, the db is defined through mysql_select_db().
correct, but even if i just refer the table name "ent" the information still wouldnt insert into the db, this is the updated code which still giving the query problem, well i dont think its the query, because when i do a var_dump() and print_r() i get back the value, mostly when i do a var_dump(); i get back boolen true/false depending on the situation but this time it give me the value
<?phpif(isset($_SESSION['uid'])){// if log in display the below menu?><table align="center" width="800"><tr><td width="663"><?phpif(isset($_GET['action'])){$action = $_GET['action'];if($action == "news"){  // creating a new Blog		echo '<h3>New Blog</h3>';   if(isset($_POST['submit'])){	$title = $_POST['title'];	$article = $_POST['article'];  	if(empty($title) && empty($article)){	 echo 'Please Fill In All Fields';	}	if(!empty($title) && empty($article)){	 echo 'Article: ' . 'Some text is required';	}	if(empty($title) && !empty($article)){	 echo 'Title: ' . 'A Title Is Required';	}	if(!empty($title) && !empty($article)){	 // filter the title and article	 $title = mysqli_real_escape_string($con, $title);	 $article = mysqli_real_escape_string($con, $article);	 $title = stripslashes($title);	 $title = strip_tags($title);	 $article = stripslashes($article);	 $article = strip_tags($article);		 $query = "INSERT INTO article(title, body, post_user) VALUES('$title', '$article', '" . $_SESSION['uid'] . "')";	 if(!$query){	  die('Error: ' . mysqli_error());	 }		 echo 'Your Blog Have Been Post';	}   }else{	?>

note: the connection to the db is at the very top with the session_start() function

Edited by DDs1
Link to comment
Share on other sites

Also instead of '' for the value of id, try NULL.
yup i tired that also, still nothing ahhh this is giving me a headache
Link to comment
Share on other sites

without using mysql_select_db() it is also possible to get any database's table specifying db schema like "databasename.tablename"

Link to comment
Share on other sites

without using mysql_select_db() it is also possible to get any database's table specifying db schema like "databasename.tablename"
okie thanks birbal and dsonesuk i got it working thanks to birbal, i forgot the mysqli_query :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...