Jump to content

Recommended Posts

Hello, I've got basic knowledge in Java and almost none in PHP, but after researching for the past couple hours, I finally managed to get the following snippet together:

 

<?php

function updateDatabase($applicant, $body)

{

 

$con = mysql_connect('******','*******','***');

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

mysql_select_db("******");

 

$counter = 8;

$queryAssist;

$idProject = 3;

$idParentItem = 0;

$priorityHolder = 5;

$contextHolder = 1;

$titleHolder = "Application - $applicant";

$descriptionHolder = "&body";

$durationExpected = 0;

$calendarInShow = 0;

$privateShow = 0;

$idMember = 3;

$idAuthor = 1;

$idItem = 8;

$conditionElement = false;

while($conditionElement = false)

{

if( mysql_query( SELECT * FROM 'frk_item' where 'itemId' = $counter )

{

$counter++;

}

else

{

$idItem = $counter;

$conditionElement = true;

}

 

}

 

 

 

$query = "INSERT INTO item (itemId, projectId, itemParentId, priority, context, title, description, deadlineDate, expectedDuration, showInCalendar, showPrivate, memberId, authorId)

VALUES ('$idItem', '$idProject', '$idParentItem', '$priorityHolder', '$contextHolder', '$titleHolder', '$descriptionHolder', '$dateDeadline', '$durationExpected', '$calendarInShow', '$privateShow', '$idMember', '$idAuthor')";

 

mysql_query($query) or die('Error, insert query failed');

 

 

}

 

 

?>

 

The goal is to connect to my mySQL server, and add an entry. The function is called with two parameters and creates an entry with the two parameters, should be somewhat obvious. I don't know why it won't work or what to do, so any advice or alteration would be very helpful. I also had a question, when trying to debug or run my php files, I always just get a page with all the code (minus the whitespace). I was wondering if there were any methods for testing code I should use.

 

I appreciate it

Link to comment
https://forums.phpfreaks.com/topic/123711-entries-into-mysql/
Share on other sites

I fixed my previous issue, but now I am having another. It will only create one database entry and then fail to create anymore.

 

<?php

function updateDatabase($applicant, $body)

{

 

$con = mysql_connect('10.6.186.64','Wessex','StatelyMatter9');

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

mysql_select_db("Wessex");

 

$queryAssist;

$idProject = 3;

$idParentItem = 0;

$priorityHolder = 5;

$contextHolder = 1;

$titleHolder = "Application - $applicant";

$descriptionHolder = "&body";

$durationExpected = 0;

$calendarInShow = 0;

$privateShow = 0;

$idMember = 3;

$idAuthor = 1;

$idItem = 8;

$conditionElement = false;

while($conditionElement = false)

{

                $counter++;

if( mysql_query( "SELECT * FROM 'frk_item' where 'itemId' = $counter" ))

{

$counter++;

}

else

{

$idItem = $counter;

$conditionElement = true;

}

 

}

 

 

 

$query = "INSERT INTO frk_item (itemId, projectId, itemParentId, priority, context, title, description, deadlineDate, expectedDuration, showInCalendar, showPrivate, memberId, authorId)

VALUES ('$idItem', '$idProject', '$idParentItem', '$priorityHolder', '$contextHolder', '$titleHolder', '$descriptionHolder', '$dateDeadline', '$durationExpected', '$calendarInShow', '$privateShow', '$idMember', '$idAuthor')";

mysql_query($query) or die('Error, insert query failed');

 

 

}

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/123711-entries-into-mysql/#findComment-638899
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.