Jump to content

Entries into mySQL


mogx21

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

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.