Hello all. This code is not working. Where is the mistake? Thanks. <?php ob_start(); session_start(); $hostname="x"; $username="x"; $password=" x"; $dbname="x"; $con = mysql_pconnect ($hostname,$username,$password) or print "No database connection exists or invalid query<br>".mysql_error(); mysql_select_db ($dbname, $con) or print "Can't select databse <br>".mysql_error(); if(isset($_REQUEST['add']) && $_REQUEST['add']=="1") { $desc = str_replace("[", "\r\n", $_REQUEST['description']); $arrayOflinks = explode(";", $_REQUEST['links']); // Get Extension of first extry $extPos = strrpos($arrayOflinks[0], "."); if ($extPos !== false) { $ext = substr($arrayOflinks[0], $extPos+1); $extL = strtolower($ext); if (!strcasecmp($extL, "bmp") || !strcasecmp($extL, "jpg") || !strcasecmp($extL, "gif")) { $imageTag = "<img src='".$arrayOflinks[0]."' border='0'>"; $arrayOflinks[0]=$imageTag; } } $link = implode("<br>", $arrayOflinks); $query = "insert into articles (`id`, `type`, `title`, `description`, `links`) values('0', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')"; print $query; mysql_query($query); exit(); } $result = mysql_query("select * from articles"); if ($result != "") { $z = mysql_num_rows($result); for ($i = 0 ; $i < $z ; $i++) { $row = mysql_fetch_array($result); print $row['type'].", ".$row['title'].", ".$row['description'].", ".$row['links']."<br>"; } } ?> Code (markup): This one is working. <?php ob_start(); session_start(); $hostname="x"; $username="x"; $password=" x"; $dbname="x"; $con = mysql_pconnect ($hostname,$username,$password) or print "No database connection exists or invalid query<br>".mysql_error(); mysql_select_db ($dbname, $con) or print "Can't select databse <br>".mysql_error(); if(isset($_REQUEST['add']) && $_REQUEST['add']=="1") { $desc = str_replace("[", "\r\n", $_REQUEST['description']); $query = "insert into articles (`id`, `quality`, `type`, `title`, `description`, `links`, `owner`) values('0', '0000000000', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$_REQUEST['links']."', '".$_REQUEST['owner']."')"; print $query; mysql_query($query); exit(); } $result = mysql_query("select * from articles"); if ($result != "") { $z = mysql_num_rows($result); for ($i = 0 ; $i < $z ; $i++) { $row = mysql_fetch_array($result); print $row['type'].", ".$row['title'].", ".$row['description'].", ".$row['links']."<br>"; } } ?> Code (markup):
Put this in your script. if (!$result) { die('Invalid query: ' . mysql_error()); } PHP: You will probably get some detailed info on what is going wrong if somethign goes wrong Also, do echo $query; PHP: You will see the sql and you can check if there is anything wrong there. I'd like to see what $query echo's.
Are you posting data to this script? You should use $_POST - if data is posted. You should use $_GET - if data is in the URL. You shouldnt really use $_REQUEST. Edit as appropriate and see if it works.
I am using $_REQUEST. Because it is connected to a software. I do not have any chance to edit the software.
You dont have to. All you have to know is if it is being posted or not.... Post the form that you fill in to add data to this db.
Then you shouldnt be inserting a id Try this $query = "insert into articles (`type`, `title`, `description`, `links`) values('".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')"; print $query; mysql_query($query); exit(); Code (markup):
Also do tell us print $query; is saying. If you say that the code works but it isn't inserting that there must be something with the $query string
I meant i do not have a chance to check it. Because it is the software i am using to submit the article. so i can not check your code. if i do i will not get any answer.
You are obviously not familiar with php. Choller told you to put it into not make a page with that code in. Saying it did not work doesnt help us. Put this code AT THE TOP of your script (that means inside of the <?php) error_reporting(E_ALL); ini_set('display_errors', '1'); Code (markup): and tell us what errors you get.
You got me wrong... Ofcource i added that code in the php codes. I am saying: There is no way i will get an error message while i am trying to insert something to the database. Because i am not adding anything manually. This page is getting called by the software. The software includes this page while you are submitting. So can you tell me how i am going to check if the query working or not. There is only one way i can see. If it is added to the database, it means it worked. If it is not added, it means it did not work.
Do what I said and give us an error! We cant help without an error. If there are no errors displayed when you put in the code i mentioned ^^ there are no errors.
papa face and Choller Thanks very much for your help. But it does not work. I do not get any error messages. It is just not adding anything.